Using hardware acceleration with libavcodec

I downloaded the software ( info-beamer ) and I would like to use GPU acceleration to decode H.264 video. I know my platform is capable of decoding H.264 video using the GPU. I ran some tests with gstreamer using the following command and the video plays smoothly without excessive CPU usage:

gst-launch-1.0 filesrc location=./Sintel.mp4 ! qtdemux ! vaapidecode ! vaapisink

      

But when I play the same info beam video, 100% CPU is used. I thought libavcodec would automatically use VAAPI if available ... Should I use another library? What am I doing wrong?

My platform is running Atom E3826 with Intel HD and Ubuntu 14.04 installed.

EDIT:

I think I have installed all the required libraries:

nap@nap:~$ dpkg -l | grep libva
ii  libva-dev:amd64                             1.3.0-2                                             amd64        Video Acceleration (VA) API for Linux -- development files
ii  libva-drm1:amd64                            1.3.0-2                                             amd64        Video Acceleration (VA) API for Linux -- DRM runtime
ii  libva-egl1:amd64                            1.3.0-2                                             amd64        Video Acceleration (VA) API for Linux -- EGL runtime
ii  libva-glx1:amd64                            1.3.0-2                                             amd64        Video Acceleration (VA) API for Linux -- GLX runtime
ii  libva-intel-vaapi-driver                    1.3.0-1ubuntu1                                      all          VAAPI driver for Intel G45 & HD Graphics family (transitional package)
ii  libva-tpi1:amd64                            1.3.0-2                                             amd64        Video Acceleration (VA) API for Linux -- TPI runtime
ii  libva-wayland1:amd64                        1.3.0-2                                             amd64        Video Acceleration (VA) API for Linux -- Wayland runtime
ii  libva-x11-1:amd64                           1.3.0-2                                             amd64        Video Acceleration (VA) API for Linux -- X11 runtime
ii  libva1:amd64                                1.3.0-2                                             amd64        Video Acceleration (VA) API for Linux -- runtime
nap@nap:~$ dpkg -l | grep vaapi
ii  gstreamer1.0-vaapi:amd64                    0.5.7-0ubuntu4                                      amd64        VA-API plugins for GStreamer
ii  libgstreamer-vaapi1.0-0:amd64               0.5.7-0ubuntu4                                      amd64        GStreamer libraries from the "vaapi" set
ii  libva-intel-vaapi-driver                    1.3.0-1ubuntu1                                      all          VAAPI driver for Intel G45 & HD Graphics family (transitional package)

      

Here is the vainfo result:

nap@nap:~$ sudo vainfo 
error: XDG_RUNTIME_DIR not set in the environment.
libva info: VA-API version 0.35.0
libva info: va_getDriverName() returns 0
libva info: Trying to open /usr/lib/x86_64-linux-gnu/dri/i965_drv_video.so
libva info: Found init function __vaDriverInit_0_35
libva info: va_openDriver() returns 0
vainfo: VA-API version: 0.35 (libva 1.3.0)
vainfo: Driver version: Intel i965 driver - 1.3.0
vainfo: Supported profile and entrypoints
      VAProfileMPEG2Simple            : VAEntrypointVLD
      VAProfileMPEG2Simple            : VAEntrypointEncSlice
      VAProfileMPEG2Main              : VAEntrypointVLD
      VAProfileMPEG2Main              : VAEntrypointEncSlice
      VAProfileH264ConstrainedBaseline: VAEntrypointVLD
      VAProfileH264ConstrainedBaseline: VAEntrypointEncSlice
      VAProfileH264Main               : VAEntrypointVLD
      VAProfileH264Main               : VAEntrypointEncSlice
      VAProfileH264High               : VAEntrypointVLD
      VAProfileH264High               : VAEntrypointEncSlice
      VAProfileVC1Simple              : VAEntrypointVLD
      VAProfileVC1Main                : VAEntrypointVLD
      VAProfileVC1Advanced            : VAEntrypointVLD
      VAProfileNone                   : VAEntrypointVideoProc
      VAProfileJPEGBaseline           : VAEntrypointVLD

      

+3


source to share


1 answer


While continuing to work, I mistakenly assumed that the hardware codec was AVCodec => this is not the case. AVHWAccel is context bound, it is not a direct codec ... so avcodec_find_decoder_by_name ("h264_vaapi") will return nothing.

info-beamer does not support hardware decoding codec (which is h264_vaapi):

video.c code:

video-> codec = avcodec_find_decoder (video-> codec_context-> codec_id);

I added



    if (video->codec_context->hwaccel != NULL)
      {
        fprintf(stderr, "HW accel IN USE : %s\n", video->codec_context->hwaccel->name);
      }
    else
      {
        fprintf(stderr, "NO HW accel IN USE\n");
      }

and "NO HW accel IN USE\n" is displayed, while i checked previously that it is registered :

   fprintf(stderr,"\n hw Decoders\n");
    AVHWAccel *first_hwaccel   = av_hwaccel_next(NULL);
    fprintf(stderr,"%p", first_hwaccel);
    AVHWAccel *hwaccel = first_hwaccel; 
    AVHWAccel *h264 = NULL; 
    const char * h264_name = "h264_vaapi";
    while (hwaccel != NULL) 
      {
    if ( hwaccel != NULL)
      {
        fprintf(stderr,"%s ", hwaccel->name);
        if (strcmp(hwaccel->name, h264_name)== 0)
          {
        h264=hwaccel;
          }
      }
    hwaccel=av_hwaccel_next(hwaccel);

    if (hwaccel == first_hwaccel)
      {
        break;
      }
      }
    fprintf(stderr,"\n");

      

It is displayed: hw Decoders 0x7f19af53fa80h263_vaapi h263_vdpau h264_vaapi h264_vdpau mpeg1_vdpau mpeg2_vaapi mpeg2_vdpau mpeg4_vaapi mpeg4_vdpau vc1_vapi vaud_vdpau vc1_vapi wapi vaud wc1_vapd3

so libavcodec knows about them, but stream-beamer doesn't use them.

Requirements for the video.c codec in the header to fork from avcodec_sample.0.5.0.c ... so it was not fully written by the info-beamer command.

+1


source







All Articles