[FFmpeg-user] H264 VAAPI Encoder

Andy Furniss adf.lists at gmail.com
Sat Jun 18 00:33:50 CEST 2016


Mark Thompson wrote:
> On 13/05/16 20:43, Armin K. wrote:
>> I noticed that recently a VAAPI based H264 encoder was added to ffmpeg.
>> I built ffmpeg from git and now I have h264_vaapi listed in ffmpeg -encoders
>> output.
>>
>> However, when I try to use ffmpeg ... -vcodec h264_vaapi I get the following
>> error:
>>
>> Impossible to convert between the formats supported by the filter 'Parsed_null_0' and the filter 'auto-inserted scaler 0'
>>
>> The command I use is:
>>
>> ffmpeg -hwaccel vaapi -i <inputfile> -vcodec h264_vaapi <outfile>.mkv
>
> Short answer:
>
> ffmpeg -vaapi_device /dev/dri/renderD128 -i <inputfile> -vf 'format=nv12,hwupload' -c:v h264_vaapi <outfile>.mkv
>
>
> Longer answer:
>
> It's somewhat awkward to use because it only accepts input as VAAPI surfaces (AV_PIX_FMT_VAAPI), with underlying format depending on the particular hardware.
>
> "-vaapi_device" sets the hardware device to use.  It takes either a DRI device (ideally a render node, as above) or an X11 display name (only if you are actually in X).
>
> Then we use libavfilter to get the input into the right form:
>
> "format=nv12" forces software conversion to NV12, which is the underlying format required by the Intel driver.
>
> "hwupload" uploads that software image into a VAAPI surface, which can then be fed into the encoder.
>
>
> You need a bit more trickiness to do a pure hardware transcode, see <https://wiki.libav.org/Hardware/vaapi> for additional explanation.
>
> - Mark

AMD are working on vaapi encode for mesa, only a few patches about so 
far and they got rejected - though not for functionality.

They do work with gstreamer, but trying above with ffmpeg fails as below 
(render node or X) seems the surface is seen as rgb - but the h/w takes 
nv12.

Maybe mesa/the driver is giving false info?

vainfo
libva info: VA-API version 0.38.1
libva info: va_getDriverName() returns 0
libva info: User requested driver 'radeonsi'
libva info: Trying to open /usr/lib/dri/radeonsi_drv_video.so
libva info: Found init function __vaDriverInit_0_38
libva info: va_openDriver() returns 0
vainfo: VA-API version: 0.38 (libva 1.6.3.pre1)
vainfo: Driver version: mesa gallium vaapi
vainfo: Supported profile and entrypoints
       VAProfileMPEG2Simple            : VAEntrypointVLD
       VAProfileMPEG2Main              : VAEntrypointVLD
       VAProfileVC1Simple              : VAEntrypointVLD
       VAProfileVC1Main                : VAEntrypointVLD
       VAProfileVC1Advanced            : VAEntrypointVLD
       VAProfileH264Baseline           : VAEntrypointVLD
       VAProfileH264Baseline           : VAEntrypointEncSlice
       VAProfileH264Baseline           : VAEntrypointEncPicture
       VAProfileH264Main               : VAEntrypointVLD
       VAProfileH264High               : VAEntrypointVLD
       VAProfileNone                   : VAEntrypointVideoProc

ffmpeg doesn't seem to care about VAProfileH264Baseline

I tried avconv and it does care = bail, but I can use -profile 66 and 
then get the same error as ffmpeg (though it converts to rgba rather 
than rgb0)

ffmpeg -loglevel debug -vaapi_device /dev/dri/renderD128 -i 
~/Pendulum-prog.mpg -vf 'format=nv12,hwupload' -c:v h264_vaapi out.mkv
ffmpeg version N-80356-g7f1b503 Copyright (c) 2000-2016 the FFmpeg 
developers
   built with gcc 5.3.0 (GCC)
   configuration: --prefix=/usr --disable-doc --enable-gpl --enable-omx 
--enable-opencl --enable-libzimg --enable-libvpx --enable-libx265 
--enable-libmp3lame --enable-libx264 --enable-gnutls
   libavutil      55. 24.100 / 55. 24.100
   libavcodec     57. 46.100 / 57. 46.100
   libavformat    57. 38.100 / 57. 38.100
   libavdevice    57.  0.101 / 57.  0.101
   libavfilter     6. 46.101 /  6. 46.101
   libswscale      4.  1.100 /  4.  1.100
   libswresample   2.  1.100 /  2.  1.100
   libpostproc    54.  0.100 / 54.  0.100
Splitting the commandline.
Reading option '-loglevel' ... matched as option 'loglevel' (set logging 
level) with argument 'debug'.
Reading option '-vaapi_device' ... matched as option 'vaapi_device' (set 
VAAPI hardware device (DRM path or X11 display name)) with argument 
'/dev/dri/renderD128'.
Reading option '-i' ... matched as input file with argument 
'/home/andy/Pendulum-prog.mpg'.
Reading option '-vf' ... matched as option 'vf' (set video filters) with 
argument 'format=nv12,hwupload'.
Reading option '-c:v' ... matched as option 'c' (codec name) with 
argument 'h264_vaapi'.
Reading option 'out.mkv' ... matched as output file.
Finished splitting the commandline.
Parsing a group of options: global .
Applying option loglevel (set logging level) with argument debug.
Applying option vaapi_device (set VAAPI hardware device (DRM path or X11 
display name)) with argument /dev/dri/renderD128.
[vaapi @ 0x190e300] Cannot open X11 display /dev/dri/renderD128.
[vaapi @ 0x190e300] Opened VA display via DRM device /dev/dri/renderD128.
libva info: VA-API version 0.38.1
libva info: va_getDriverName() returns -1
libva info: User requested driver 'radeonsi'
libva info: Trying to open /usr/lib/dri/radeonsi_drv_video.so
libva info: Found init function __vaDriverInit_0_38
libva info: va_openDriver() returns 0
[vaapi @ 0x190e300] Initialised VAAPI connection: version 0.38
[AVHWDeviceContext @ 0x3ca4c40] Format 0x3231564e -> unknown.
[AVHWDeviceContext @ 0x3ca4c40] Format 0x32315659 -> unknown.
[AVHWDeviceContext @ 0x3ca4c40] Format 0x56595559 -> unknown.
[AVHWDeviceContext @ 0x3ca4c40] Format 0x59565955 -> unknown.
[AVHWDeviceContext @ 0x3ca4c40] Format 0x41524742 -> bgra.
[AVHWDeviceContext @ 0x3ca4c40] Format 0x41424752 -> rgba.
[AVHWDeviceContext @ 0x3ca4c40] Format 0x58524742 -> bgr0.
[AVHWDeviceContext @ 0x3ca4c40] Format 0x58424752 -> rgb0.
Successfully parsed a group of options.
Parsing a group of options: input file /home/andy/Pendulum-prog.mpg.
Successfully parsed a group of options.
Opening an input file: /home/andy/Pendulum-prog.mpg.
[file @ 0x3bfb680] Setting default whitelist 'file,crypto'
[mpeg @ 0x3bfb060] Format mpeg probed with size=2048 and score=26
[mpeg @ 0x3bfb060] Before avformat_find_stream_info() pos: 0 bytes 
read:32768 seeks:0 nb_streams:0
[mpeg @ 0x3bfb060] probing stream 0 pp:2500
[mpeg @ 0x3bfb060] Probe with size=2005, packets=1 detected mpegvideo 
with score=25
[mpeg @ 0x3bfb060] probed stream 0
[mpeg @ 0x3bfb060] max_analyze_duration 7000000 reached at 7000000 
microseconds st:0
[mpeg @ 0x3bfb060] After avformat_find_stream_info() pos: 0 bytes 
read:2019472 seeks:2 frames:177
Input #0, mpeg, from '/home/andy/Pendulum-prog.mpg':
   Duration: 00:00:39.84, start: 0.500000, bitrate: 1969 kb/s
     Stream #0:0[0x1e0], 177, 1/90000: Video: mpeg2video (Main), 1 
reference frame, yuv420p(tv, left), 720x576 [SAR 1:1 DAR 5:4], 0/1, 25 
fps, 25 tbr, 90k tbn, 50 tbc
Successfully opened the file.
Parsing a group of options: output file out.mkv.
Applying option vf (set video filters) with argument format=nv12,hwupload.
Applying option c:v (codec name) with argument h264_vaapi.
Successfully parsed a group of options.
Opening an output file: out.mkv.
File 'out.mkv' already exists. Overwrite ? [y/N] y
[file @ 0x3ce8680] Setting default whitelist 'file,crypto'
Successfully opened the file.
detected 4 logical cores
[Parsed_format_0 @ 0x3cf4840] compat: called with args=[nv12]
[Parsed_format_0 @ 0x3cf4840] Setting 'pix_fmts' to value 'nv12'
[graph 0 input from stream 0:0 @ 0x3cd5fc0] Setting 'video_size' to 
value '720x576'
[graph 0 input from stream 0:0 @ 0x3cd5fc0] Setting 'pix_fmt' to value '0'
[graph 0 input from stream 0:0 @ 0x3cd5fc0] Setting 'time_base' to value 
'1/90000'
[graph 0 input from stream 0:0 @ 0x3cd5fc0] Setting 'pixel_aspect' to 
value '1/1'
[graph 0 input from stream 0:0 @ 0x3cd5fc0] Setting 'sws_param' to value 
'flags=2'
[graph 0 input from stream 0:0 @ 0x3cd5fc0] Setting 'frame_rate' to 
value '25/1'
[graph 0 input from stream 0:0 @ 0x3cd5fc0] w:720 h:576 pixfmt:yuv420p 
tb:1/90000 fr:25/1 sar:1/1 sws_param:flags=2
[format @ 0x3cf1660] compat: called with args=[vaapi_vld]
[format @ 0x3cf1660] Setting 'pix_fmts' to value 'vaapi_vld'
[auto-inserted scaler 0 @ 0x3cf2a60] Setting 'flags' to value 'bicubic'
[auto-inserted scaler 0 @ 0x3cf2a60] w:iw h:ih flags:'bicubic' interl:0
[Parsed_format_0 @ 0x3cf4840] auto-inserting filter 'auto-inserted 
scaler 0' between the filter 'graph 0 input from stream 0:0' and the 
filter 'Parsed_format_0'
[auto-inserted scaler 1 @ 0x3cf4ec0] Setting 'flags' to value 'bicubic'
[auto-inserted scaler 1 @ 0x3cf4ec0] w:iw h:ih flags:'bicubic' interl:0
[Parsed_hwupload_1 @ 0x3cd6100] auto-inserting filter 'auto-inserted 
scaler 1' between the filter 'Parsed_format_0' and the filter 
'Parsed_hwupload_1'
[AVFilterGraph @ 0x3cf9ce0] query_formats: 5 queried, 2 merged, 2 
already done, 0 delayed
[auto-inserted scaler 1 @ 0x3cf4ec0] picking rgb0 out of 4 ref:nv12 alpha:0
[auto-inserted scaler 0 @ 0x3cf2a60] w:720 h:576 fmt:yuv420p sar:1/1 -> 
w:720 h:576 fmt:nv12 sar:1/1 flags:0x4
[auto-inserted scaler 1 @ 0x3cf4ec0] w:720 h:576 fmt:nv12 sar:1/1 -> 
w:720 h:576 fmt:rgb0 sar:1/1 flags:0x4
[hwupload @ 0x3cd61c0] Surface format is rgb0.
[AVHWFramesContext @ 0x3cf1700] Created surface 0x1.
[AVHWFramesContext @ 0x3cf1700] Direct mapping possible.
[h264_vaapi @ 0x3ce7dc0] Using fixed QP = 20 / 20 / 24 for IDR / P / B 
frames.
[h264_vaapi @ 0x3ce7dc0] Using (null) as format of reconstructed frames.
[AVHWFramesContext @ 0x3d37fa0] Unsupported format: (null).
[h264_vaapi @ 0x3ce7dc0] Failed to initialise reconstructed frame 
context: -22.
Output #0, matroska, to 'out.mkv':
     Stream #0:0, 0, 0/0: Unknown: none, SAR 1:1 DAR 0:0
     Metadata:
       encoder         : Lavc57.46.100 h264_vaapi
Stream mapping:
   Stream #0:0 -> #0:0 (mpeg2video (native) -> h264 (h264_vaapi))
Error while opening encoder for output stream #0:0 - maybe incorrect 
parameters such as bit_rate, rate, width or height
[AVIOContext @ 0x3ce8760] Statistics: 0 seeks, 0 writeouts
[AVIOContext @ 0x3bfa540] Statistics: 2019472 bytes read, 2 seeks






More information about the ffmpeg-user mailing list