title: Why gstreamer with vaapih264enc shows "context pad peer query failed"?
body: <p>I would like to use hardware encoding to compress a raw video file using gstreamer and vaapi. I am getting <code>Could not initialize supporting library</code>, which does not allow encoder to open. Possibly <code>context pad peer query failed</code> is the root cause for this. But I am not sure. I use the following pipeline:</p>
  
  <pre><code>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
  </code></pre>
  
  <p>Pipeline fails with message:</p>
  
  <pre><code>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 ...
  </code></pre>
  
  <p>What am I doing wrong?</p>
  
  <p>Using <code>GST_DEBUG=3 gst-launch-1.0 --gst-debug-level=4</code> to start the pipeline gives me this:</p>
  
  <pre><code>INFO       GST_STATES gstbin.c:2316:gst_bin_element_set_state:&lt;vaapiencodeh264-0&gt; current NULL pending VOID_PENDING, desired next READY
  INFO      GST_CONTEXT gstvaapivideocontext.c:106:context_pad_query:&lt;vaapiencodeh264-0:src&gt; context pad peer query failed
  INFO      GST_CONTEXT gstvaapivideocontext.c:106:context_pad_query:&lt;vaapiencodeh264-0:sink&gt; context pad peer query failed
  INFO      GST_CONTEXT gstvaapivideocontext.c:180:_gst_context_query:&lt;vaapiencodeh264-0&gt; 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:&lt;vaapiencodeh264-0&gt; error: Failed to open encoder
  INFO GST_ERROR_SYSTEM gstelement.c:1879:gst_element_message_full:&lt;vaapiencodeh264-0&gt; posting message: Could not initialize supporting library.
  INFO GST_ERROR_SYSTEM gstelement.c:1902:gst_element_message_full:&lt;vaapiencodeh264-0&gt; posted error message: Could not initialize supporting library.
  INFO       GST_STATES gstelement.c:2657:gst_element_change_state:&lt;vaapiencodeh264-0&gt; have FAILURE change_state return
  INFO       GST_STATES gstelement.c:2247:gst_element_abort_state:&lt;vaapiencodeh264-0&gt; aborting state from NULL to READY
  INFO       GST_STATES gstbin.c:2780:gst_bin_change_state_func:&lt;pipeline0&gt; child 'vaapiencodeh264-0' failed to go to state 2(READY)
  </code></pre>
  
  <p>My hardware should support this and driver seems to be installed properly:</p>
  
  <pre><code>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
  </code></pre>
  
  <p>vaapi plugin seems to be properly installed as well:</p>
  
  <pre><code>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 &lt;feng.yuan@intel.com&gt;
  
  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
  ...
  </code></pre>
  
  <p>Thank you for any suggestions.</p>