1

I would like to use hardware encoding to compress a raw video file using gstreamer and vaapi. I am getting Could not initialize supporting library, which does not allow encoder to open. Possibly context pad peer query failed is the root cause for this. But I am not sure. I use the following pipeline:

gst-launch-1.0 -v filesrc location=input.raw ! videoparse width=1280 height=1024 format=yuy2 framerate=20/1 ! vaapih264enc ! h264parse ! qtmux ! filesink location=compressed.mov

Pipeline fails with message:

Setting pipeline to PAUSED ...
ERROR: Pipeline doesn't want to pause.
ERROR: from element /GstPipeline:pipeline0/GstVaapiEncodeH264:vaapiencodeh264-0: Could not initialize supporting library.
Additional debug info:
gstvideoencoder.c(1534): gst_video_encoder_change_state (): /GstPipeline:pipeline0/GstVaapiEncodeH264:vaapiencodeh264-0:
Failed to open encoder
Setting pipeline to NULL ...
Freeing pipeline ...

What am I doing wrong?

Using GST_DEBUG=3 gst-launch-1.0 --gst-debug-level=4 to start the pipeline gives me this:

INFO       GST_STATES gstbin.c:2316:gst_bin_element_set_state:<vaapiencodeh264-0> current NULL pending VOID_PENDING, desired next READY
INFO      GST_CONTEXT gstvaapivideocontext.c:106:context_pad_query:<vaapiencodeh264-0:src> context pad peer query failed
INFO      GST_CONTEXT gstvaapivideocontext.c:106:context_pad_query:<vaapiencodeh264-0:sink> context pad peer query failed
INFO      GST_CONTEXT gstvaapivideocontext.c:180:_gst_context_query:<vaapiencodeh264-0> posting `need-context' message
INFO            vaapi gstvaapidisplay.c:119:libgstvaapi_init_once: gstreamer-vaapi version
WARN     videoencoder gstvideoencoder.c:1534:gst_video_encoder_change_state:<vaapiencodeh264-0> error: Failed to open encoder
INFO GST_ERROR_SYSTEM gstelement.c:1879:gst_element_message_full:<vaapiencodeh264-0> posting message: Could not initialize supporting library.
INFO GST_ERROR_SYSTEM gstelement.c:1902:gst_element_message_full:<vaapiencodeh264-0> posted error message: Could not initialize supporting library.
INFO       GST_STATES gstelement.c:2657:gst_element_change_state:<vaapiencodeh264-0> have FAILURE change_state return
INFO       GST_STATES gstelement.c:2247:gst_element_abort_state:<vaapiencodeh264-0> aborting state from NULL to READY
INFO       GST_STATES gstbin.c:2780:gst_bin_change_state_func:<pipeline0> child 'vaapiencodeh264-0' failed to go to state 2(READY)

My hardware should support this and driver seems to be installed properly:

shell:~$ vainfo
libva info: VA-API version 0.39.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_39
libva info: va_openDriver() returns 0
vainfo: VA-API version: 0.39 (libva 1.7.0)
vainfo: Driver version: Intel i965 driver for Intel(R) Skylake - 1.7.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
      VAProfileH264MultiviewHigh      :    VAEntrypointVLD
      VAProfileH264MultiviewHigh      :    VAEntrypointEncSlice
      VAProfileH264StereoHigh         :    VAEntrypointVLD
      VAProfileH264StereoHigh         :    VAEntrypointEncSlice
      VAProfileVC1Simple              :    VAEntrypointVLD
      VAProfileVC1Main                :    VAEntrypointVLD
      VAProfileVC1Advanced            :    VAEntrypointVLD
      VAProfileNone                   :    VAEntrypointVideoProc
      VAProfileJPEGBaseline           :    VAEntrypointVLD
      VAProfileJPEGBaseline           :    VAEntrypointEncPicture
      VAProfileVP8Version0_3          :    VAEntrypointVLD
      VAProfileVP8Version0_3          :    VAEntrypointEncSlice
      VAProfileHEVCMain               :    VAEntrypointVLD
      VAProfileHEVCMain               :    VAEntrypointEncSlice

vaapi plugin seems to be properly installed as well:

gst-inspect-1.0 vaapih264enc
Factory Details:
  Rank                     primary (256)
  Long-name                VA-API H.264 encoder
  Klass                    Codec/Encoder/Video
  Description              A VA-API based H.264 video encoder
  Author                   Wind Yuan <feng.yuan@intel.com>

Plugin Details:
  Name                     vaapi
  Description              VA-API based elements
  Filename                 /usr/lib/x86_64-linux-gnu/gstreamer-1.0/libgstvaapi.so
  Version                  1.8.3
  License                  LGPL
  Source module            gstreamer-vaapi
  Source release date      2016-06-09
  Binary package           gstreamer-vaapi
  Origin URL               http://bugzilla.gnome.org/enter_bug.cgi?product=GStreamer
...

Thank you for any suggestions.

sjcomp
  • 177
  • 2
  • 9
  • I don't think you need to include `h264parse`. Connect `vaapih264enc` directly to `qtmux`. – MayurK Sep 05 '19 at 09:35
  • I agree. I can use software encoder without `h264parse`: `gst-launch-1.0 -v filesrc location=input.row ! rawvideoparse use-sink-caps=false width=1280 height=1024 format=yuy2 framerate=20/1 ! videoconvert ! x264enc ! qtmux ! filesink location=compressed.mov` It does not change the outcome when I use hardware encoder. – sjcomp Sep 05 '19 at 13:31
  • Ok. I am not sure what is the issue. Try to see if the issue is for specific resolution/frame-rate/color format by testing with different files. – MayurK Sep 06 '19 at 04:28
  • Thanks for this suggestion, I stumbled onto the solution while working on your recommendation. – sjcomp Sep 06 '19 at 19:48

1 Answers1

0

I believe incorrect user configuration/permissions were the reason why the encoder library could not be initialized. It would be nice if knew how to find some log messages somewhere on my system to point me in that direction (it was a lucky stumble on my part).

I got hardware encoding working after changing two things: 1) the user under which I was running these command did not have the right permissions or configuration. I did not investigate what exactly yet. 2) Once I used proper user account I got an error message that suggested I use vaapipostproc before vaapih264enc to resolve chroma type that was not understood by the en.

The final pipeline command I used is: sudo -u proper_user gst-launch-1.0 filesrc location=input.raw ! videoparse width=1280 height=1024 format=yuy2 framerate=20/1 ! videoconvert ! vaapipostproc ! vaapih264enc ! qtmux ! filesink location=hardware.compressed.mov

sjcomp
  • 177
  • 2
  • 9