[FFmpeg-user] Bad performance when using h264_vaapi to encode stream from camera.

Xiang, Haihao haihao.xiang at intel.com
Thu May 18 09:16:25 EEST 2023


Hi,

Does your camera support 1920x1080 at 30fps ? Moreover, the output format from your
camera is yuyv422, converting yuyv422 to nv12 impacts the performance too.

Thanks
Haihao


> Hello guys,
> 
>  
> 
> I am using quite old Intel e3845 processor to do hardware encoding/decoding
> via vaapi. It works very well when I test it on transcoding a h264 1920x1080
> 30 fps file:
> 
>  
> 
> ffmpeg -vaapi_device /dev/dri/renderD128 -i test_02.mp4 -vf
> 'format=nv12,hwupload' -c:v h264_vaapi -profile: high -qp: 42
> test_02_01_h264_vaapi.mp4
> 
>  
> 
> [out#0/mp4 @ 0x55c058071e40] video:3194kB audio:0kB subtitle:0kB other
> streams:0kB global headers:0kB muxing overhead: 0.287536%
> 
> frame=  901 fps= 42 q=-0.0 Lsize=    3203kB time=00:00:29.96 bitrate=
> 875.5kbits/s speed=1.41x
> 
>  
> 
> I would think that it will work as good when encoding camera stream (or even
> better because there is no decoding involved). To my surprise, performance
> is lousy, it is a fraction of speed in comparison to transcoding from a
> file:
> 
>  
> 
> ffmpeg -loglevel debug -vaapi_device /dev/dri/renderD128 -f v4l2 -framerate
> 30 -video_size 1920x1080 -i /dev/video2 -vf 'format=nv12,hwupload' -c:v
> h264_vaapi -profile: high -qp: 42 output_2_vaapi.mp4
> 
> ffmpeg version N-110363-g2aad9765ef Copyright (c) 2000-2023 the FFmpeg
> developers
> 
>   built with gcc 12 (Ubuntu 12.2.0-3ubuntu1)
> 
>   configuration: --pkg-config-flags=--static --enable-static
> --disable-shared --prefix=/home/sicore/ffmpeg_build --bindir=/home/test/bin
> --extra-cflags=-I/home/test/bin/include
> --extra-ldflags=-L/home/sicore/bin/lib --extra-cflags=-I/usr/local/include
> --extra-ldflags=-L/usr/local/lib --enable-vaapi --disable-debug
> --enable-libdrm --enable-gpl --enable-runtime-cpudetect --enable-libx264
> --enable-openssl --enable-pic --extra-libs='-lpthread -lm -lz -ldl'
> --enable-nonfree
> 
>   libavutil      58.  6.100 / 58.  6.100
> 
>   libavcodec     60. 10.100 / 60. 10.100
> 
>   libavformat    60.  5.100 / 60.  5.100
> 
>   libavdevice    60.  2.100 / 60.  2.100
> 
>   libavfilter     9.  5.100 /  9.  5.100
> 
>   libswscale      7.  2.100 /  7.  2.100
> 
>   libswresample   4. 11.100 /  4. 11.100
> 
>   libpostproc    57.  2.100 / 57.  2.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 (DirectX adapter index, DRM path or X11 display name))
> with argument '/dev/dri/renderD128'.
> 
> Reading option '-f' ... matched as option 'f' (force format) with argument
> 'v4l2'.
> 
> Reading option '-framerate' ... matched as AVOption 'framerate' with
> argument '30'.
> 
> Reading option '-video_size' ... matched as AVOption 'video_size' with
> argument '1920x1080'.
> 
> Reading option '-i' ... matched as input url with argument '/dev/video2'.
> 
> 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 '-profile:' ... matched as option 'profile' (set profile)
> with argument 'high'.
> 
> Reading option '-qp:' ... matched as AVOption 'qp:' with argument '42'.
> 
> Reading option 'output_2_vaapi.mp4' ... matched as output url.
> 
> 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 (DirectX adapter
> index, DRM path or X11 display name)) with argument /dev/dri/renderD128.
> 
> [AVHWDeviceContext @ 0x55c91096d7c0] libva: VA-API version 1.16.0
> 
> [AVHWDeviceContext @ 0x55c91096d7c0] libva: User environment variable
> requested driver 'i965'
> 
> [AVHWDeviceContext @ 0x55c91096d7c0] libva: Trying to open
> /usr/lib/x86_64-linux-gnu/dri/i965_drv_video.so
> 
> [AVHWDeviceContext @ 0x55c91096d7c0] libva: Found init function
> __vaDriverInit_1_16
> 
> [AVHWDeviceContext @ 0x55c91096d7c0] libva: va_openDriver() returns 0
> 
> [AVHWDeviceContext @ 0x55c91096d7c0] Initialised VAAPI connection: version
> 1.16
> 
> [AVHWDeviceContext @ 0x55c91096d7c0] Format 0x32315659 -> yuv420p.
> 
> [AVHWDeviceContext @ 0x55c91096d7c0] Format 0x30323449 -> yuv420p.
> 
> [AVHWDeviceContext @ 0x55c91096d7c0] Format 0x3231564e -> nv12.
> 
> [AVHWDeviceContext @ 0x55c91096d7c0] Format 0x32595559 -> yuyv422.
> 
> [AVHWDeviceContext @ 0x55c91096d7c0] Format 0x59565955 -> uyvy422.
> 
> [AVHWDeviceContext @ 0x55c91096d7c0] Format 0x48323234 -> yuv422p.
> 
> [AVHWDeviceContext @ 0x55c91096d7c0] Format 0x58424752 -> rgb0.
> 
> [AVHWDeviceContext @ 0x55c91096d7c0] Format 0x58524742 -> bgr0.
> 
> [AVHWDeviceContext @ 0x55c91096d7c0] Format 0x30313050 -> p010le.
> 
> [AVHWDeviceContext @ 0x55c91096d7c0] VAAPI driver: Intel i965 driver for
> Intel(R) Bay Trail - 2.4.0.pre1 (2.3.0-35-gab755cb).
> 
> [AVHWDeviceContext @ 0x55c91096d7c0] Driver not found in known nonstandard
> list, using standard behaviour.
> 
> Successfully parsed a group of options.
> 
> Parsing a group of options: input url /dev/video2.
> 
> Applying option f (force format) with argument v4l2.
> 
> Successfully parsed a group of options.
> 
> Opening an input file: /dev/video2.
> 
> [video4linux2,v4l2 @ 0x55c91097f300] fd:4 capabilities:84a00001
> 
> [video4linux2,v4l2 @ 0x55c91097f300] Current input_channel: 0, input_name:
> Camera, input_std: 0
> 
> [video4linux2,v4l2 @ 0x55c91097f300] The V4L2 driver changed the pixel
> format from 0x32315559 to 0x56595559
> 
> [video4linux2,v4l2 @ 0x55c91097f300] Trying to set codec:rawvideo
> pix_fmt:yuv420p
> 
> [video4linux2,v4l2 @ 0x55c91097f300] The V4L2 driver changed the pixel
> format from 0x32315559 to 0x56595559
> 
> [video4linux2,v4l2 @ 0x55c91097f300] Trying to set codec:rawvideo
> pix_fmt:yuv420p
> 
> [video4linux2,v4l2 @ 0x55c91097f300] The V4L2 driver changed the pixel
> format from 0x32315659 to 0x56595559
> 
> [video4linux2,v4l2 @ 0x55c91097f300] Trying to set codec:rawvideo
> pix_fmt:yuv422p
> 
> [video4linux2,v4l2 @ 0x55c91097f300] The V4L2 driver changed the pixel
> format from 0x50323234 to 0x56595559
> 
> [video4linux2,v4l2 @ 0x55c91097f300] Trying to set codec:rawvideo
> pix_fmt:yuyv422
> 
> [video4linux2,v4l2 @ 0x55c91097f300] Setting time per frame to 1/30
> 
> [video4linux2,v4l2 @ 0x55c91097f300] All info found
> 
> Input #0, video4linux2,v4l2, from '/dev/video2':
> 
>   Duration: N/A, start: 172336.109110, bitrate: 995328 kb/s
> 
>   Stream #0:0, 1, 1/1000000: Video: rawvideo, 1 reference frame (YUY2 /
> 0x32595559), yuyv422, 1920x1080, 0/1, 995328 kb/s, 30 fps, 30 tbr, 1000k tbn
> 
> Successfully opened the file.
> 
> Parsing a group of options: output url output_2_vaapi.mp4.
> 
> Applying option vf (set video filters) with argument format=nv12,hwupload.
> 
> Applying option c:v (codec name) with argument h264_vaapi.
> 
> Applying option profile: (set profile) with argument high.
> 
> Successfully parsed a group of options.
> 
> Opening an output file: output_2_vaapi.mp4.
> 
> [file @ 0x55c9109890c0] Setting default whitelist 'file,crypto,data'
> 
> Successfully opened the file.
> 
> Stream mapping:
> 
>   Stream #0:0 -> #0:0 (rawvideo (native) -> h264 (h264_vaapi))
> 
> Press [q] to stop, [?] for help
> 
> [vost#0:0/h264_vaapi @ 0x55c910983900] cur_dts is invalid [init:0 i_done:0
> finish:0] (this is harmless if it occurs once at the start per stream)
> 
> [rawvideo @ 0x55c910982240] PACKET SIZE: 4147200, STRIDE: 3840
> 
> [AVFilterGraph @ 0x55c910988340] Setting 'pix_fmts' to value 'nv12'
> 
> detected 4 logical cores
> 
> [graph 0 input from stream 0:0 @ 0x55c91098a480] Setting 'video_size' to
> value '1920x1080'
> 
> [graph 0 input from stream 0:0 @ 0x55c91098a480] Setting 'pix_fmt' to value
> '1'
> 
> [graph 0 input from stream 0:0 @ 0x55c91098a480] Setting 'time_base' to
> value '1/1000000'
> 
> [graph 0 input from stream 0:0 @ 0x55c91098a480] Setting 'pixel_aspect' to
> value '0/1'
> 
> [graph 0 input from stream 0:0 @ 0x55c91098a480] Setting 'frame_rate' to
> value '30/1'
> 
> [graph 0 input from stream 0:0 @ 0x55c91098a480] w:1920 h:1080
> pixfmt:yuyv422 tb:1/1000000 fr:30/1 sar:0/1
> 
> [format @ 0x55c91098b500] Setting 'pix_fmts' to value 'vaapi'
> 
> [auto_scale_0 @ 0x55c91098c980] w:iw h:ih flags:'' interl:0
> 
> [Parsed_format_0 @ 0x55c910989680] auto-inserting filter 'auto_scale_0'
> between the filter 'graph 0 input from stream 0:0' and the filter
> 'Parsed_format_0'
> 
> [AVFilterGraph @ 0x55c910988340] query_formats: 5 queried, 4 merged, 1
> already done, 0 delayed
> 
> [auto_scale_0 @ 0x55c91098c980] w:1920 h:1080 fmt:yuyv422 sar:0/1 -> w:1920
> h:1080 fmt:nv12 sar:0/1 flags:0x00000004
> 
> [hwupload @ 0x55c910989c00] Surface format is nv12.
> 
> [AVHWFramesContext @ 0x55c910bc3a00] Created surface 0x4000000.
> 
> [AVHWFramesContext @ 0x55c910bc3a00] Direct mapping possible.
> 
> [AVHWFramesContext @ 0x55c910bc3a00] Map surface 0x4000000.
> 
> [AVHWFramesContext @ 0x55c910bc3a00] Unmap surface 0x4000000.
> 
> [h264_vaapi @ 0x55c910983d00] Using input frames context (format vaapi) with
> h264_vaapi encoder.
> 
> [h264_vaapi @ 0x55c910983d00] Input surface format is nv12.
> 
> [h264_vaapi @ 0x55c910983d00] Using VAAPI profile VAProfileH264High (7).
> 
> [h264_vaapi @ 0x55c910983d00] Using VAAPI entrypoint VAEntrypointEncSlice
> (6).
> 
> [h264_vaapi @ 0x55c910983d00] Using VAAPI render target format YUV420 (0x1).
> 
> [h264_vaapi @ 0x55c910983d00] Driver supports RC modes CQP, CBR, VBR.
> 
> [h264_vaapi @ 0x55c910983d00] RC mode: CQP.
> 
> [h264_vaapi @ 0x55c910983d00] RC quality: 42.
> 
> [h264_vaapi @ 0x55c910983d00] RC framerate: 30/1 (30.00 fps).
> 
> [h264_vaapi @ 0x55c910983d00] Driver does not report any additional
> prediction constraints.
> 
> [h264_vaapi @ 0x55c910983d00] Using intra, P- and B-frames (supported
> references: 1 / 1).
> 
> [h264_vaapi @ 0x55c910983d00] All wanted packed headers available (wanted
> 0xd, found 0x1f).
> 
> [h264_vaapi @ 0x55c910983d00] Using nv12 as format of reconstructed frames.
> 
> [AVHWFramesContext @ 0x55c910c1b380] Created surface 0x4000001.
> 
> [AVHWFramesContext @ 0x55c910c1b380] Direct mapping possible.
> 
> [h264_vaapi @ 0x55c910983d00] Using fixed QP = 42 / 42 / 50 for IDR- / P- /
> B-frames.
> 
> [h264_vaapi @ 0x55c910983d00] Using level 4.
> 
> Output #0, mp4, to 'output_2_vaapi.mp4':
> 
>   Metadata:
> 
>     encoder         : Lavf60.5.100
> 
>   Stream #0:0, 0, 1/15360: Video: h264 (High), 1 reference frame (avc1 /
> 0x31637661), vaapi(tv, progressive), 1920x1080 (0x0), 0/1, q=2-31, 30 fps,
> 15360 tbn
> 
>     Metadata:
> 
>       encoder         : Lavc60.10.100 h264_vaapi
> 
>  
> 
> <some time later>
> 
>  
> 
> [out#0/mp4 @ 0x55c91097f800] video:74kB audio:0kB subtitle:0kB other
> streams:0kB global headers:0kB muxing overhead: 1.961509%
> 
> frame=   67 fps= 13 q=-0.0 Lsize=      75kB time=00:00:02.16 bitrate=
> 285.4kbits/s dup=7 drop=0 speed=0.413x
> 
> 60 frames successfully decoded, 0 decoding errors
> 
> [h264_vaapi @ 0x55c910983d00] Freed output buffer 0x8000000
> 
> [in#0/video4linux2,v4l2 @ 0x55c91097f180] Terminating demuxer thread
> 
> [in#0/video4linux2,v4l2 @ 0x55c91097f180] Input file #0 (/dev/video2):
> 
> [in#0/video4linux2,v4l2 @ 0x55c91097f180]   Input stream #0:0 (video): 60
> packets read (248832000 bytes); 60 frames decoded;
> 
> [in#0/video4linux2,v4l2 @ 0x55c91097f180]   Total: 60 packets (248832000
> bytes) demuxed
> 
>  
> 
> As you can see, speed is 0.413, it is almost 4 times slower when
> transcoding. Is there something I am doing wrong?
> 
>  
> 
> Thanks for any help.
> 
> _______________________________________________
> ffmpeg-user mailing list
> ffmpeg-user at ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-user
> 
> To unsubscribe, visit link above, or email
> ffmpeg-user-request at ffmpeg.org with subject "unsubscribe".



More information about the ffmpeg-user mailing list