Result video plays jerky (very small FPS) if source stream is 4K and used VAAPI encoder (ffmpeg)
Result video plays jerky (very small FPS) if source stream is 4K and used VAAPI encoder. If the same stream will encoded with CPU (libx264) encoder then video played as expected.
$ ffmpeg -f x11grab -framerate 60 -video_size 3840x2160 -i :0.0 -vf 'format=nv12,hwupload' -vaapi_device /dev/dri/renderD128 -vcodec h264_vaapi output-vaapi.mp4
ffmpeg version 4.4 Copyright (c) 2000-2021 the FFmpeg developers
built with gcc 11 (GCC)
configuration: --prefix=/usr --bindir=/usr/bin --datadir=/usr/share/ffmpeg --docdir=/usr/share/doc/ffmpeg --incdir=/usr/include/ffmpeg --libdir=/usr/lib64 --mandir=/usr/share/man --arch=x86_64 --optflags='-O2 -flto=auto -ffat-lto-objects -fexceptions -g -grecord-gcc-switches -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -fstack-protector-strong -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1 -m64 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection' --extra-ldflags='-Wl,-z,relro -Wl,--as-needed -Wl,-z,now -specs=/usr/lib/rpm/redhat/redhat-hardened-ld ' --extra-cflags=' -I/usr/include/rav1e' --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libvo-amrwbenc --enable-version3 --enable-bzlib --disable-crystalhd --enable-fontconfig --enable-frei0r --enable-gcrypt --enable-gnutls --enable-ladspa --enable-libaom --enable-libdav1d --enable-libass --enable-libbluray --enable-libcdio --enable-libdrm --enable-libjack --enable-libfreetype --enable-libfribidi --enable-libgsm --enable-libmp3lame --enable-libmysofa --enable-nvenc --enable-openal --enable-opencl --enable-opengl --enable-libopenjpeg --enable-libopenmpt --enable-libopus --enable-libpulse --enable-librsvg --enable-librav1e --enable-libsmbclient --enable-version3 --enable-libsoxr --enable-libspeex --enable-libsrt --enable-libssh --enable-libsvtav1 --enable-libtheora --enable-libvorbis --enable-libv4l2 --enable-libvidstab --enable-libvmaf --enable-version3 --enable-vapoursynth --enable-libvpx --enable-vulkan --enable-libglslang --enable-libx264 --enable-libx265 --enable-libxvid --enable-libxml2 --enable-libzimg --enable-libzvbi --enable-lv2 --enable-avfilter --enable-avresample --enable-libmodplug --enable-postproc --enable-pthreads --disable-static --enable-shared --enable-gpl --disable-debug --disable-stripping --shlibdir=/usr/lib64 --enable-lto --enable-libmfx --enable-runtime-cpudetect
libavutil 56. 70.100 / 56. 70.100
libavcodec 58.134.100 / 58.134.100
libavformat 58. 76.100 / 58. 76.100
libavdevice 58. 13.100 / 58. 13.100
libavfilter 7.110.100 / 7.110.100
libavresample 4. 0. 0 / 4. 0. 0
libswscale 5. 9.100 / 5. 9.100
libswresample 3. 9.100 / 3. 9.100
libpostproc 55. 9.100 / 55. 9.100
[x11grab @ 0x555970538fc0] Stream #0: not enough frames to estimate rate; consider increasing probesize
Input #0, x11grab, from ':0.0':
Duration: N/A, start: 1618439331.415805, bitrate: 15925248 kb/s
Stream #0:0: Video: rawvideo (BGR[0] / 0x524742), bgr0, 3840x2160, 15925248 kb/s, 60 fps, 1000k tbr, 1000k tbn, 1000k tbc
File 'output-vaapi.mp4' already exists. Overwrite? [y/N] y
Stream mapping:
Stream #0:0 -> #0:0 (rawvideo (native) -> h264 (h264_vaapi))
Press [q] to stop, [?] for help
[h264_vaapi @ 0x555970512c40] No quality level set; using default (20).
[h264_vaapi @ 0x555970512c40] Driver does not support some wanted packed headers (wanted 0xd, found 0x1).
Output #0, mp4, to 'output-vaapi.mp4':
Metadata:
encoder : Lavf58.76.100
Stream #0:0: Video: h264 (High) (avc1 / 0x31637661), vaapi_vld(tv, progressive), 3840x2160, q=2-31, 60 fps, 15360 tbn
Metadata:
encoder : Lavc58.134.100 h264_vaapi
More than 1000 frames duplicated 4096kB time=00:00:16.38 bitrate=2048.1kbits/s dup=980 drop=0 speed=1.17x
frame= 2065 fps= 31 q=-0.0 Lsize= 8403kB time=00:00:34.40 bitrate=2001.0kbits/s dup=2060 drop=0 speed=0.513x
video:8394kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.107213%
Exiting normally, received signal 2.
$ ffmpeg -f x11grab -framerate 60 -video_size 3840x2160 -i :0.0 -vcodec libx264 output-cpu.mp4
ffmpeg version 4.4 Copyright (c) 2000-2021 the FFmpeg developers
built with gcc 11 (GCC)
configuration: --prefix=/usr --bindir=/usr/bin --datadir=/usr/share/ffmpeg --docdir=/usr/share/doc/ffmpeg --incdir=/usr/include/ffmpeg --libdir=/usr/lib64 --mandir=/usr/share/man --arch=x86_64 --optflags='-O2 -flto=auto -ffat-lto-objects -fexceptions -g -grecord-gcc-switches -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -fstack-protector-strong -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1 -m64 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection' --extra-ldflags='-Wl,-z,relro -Wl,--as-needed -Wl,-z,now -specs=/usr/lib/rpm/redhat/redhat-hardened-ld ' --extra-cflags=' -I/usr/include/rav1e' --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libvo-amrwbenc --enable-version3 --enable-bzlib --disable-crystalhd --enable-fontconfig --enable-frei0r --enable-gcrypt --enable-gnutls --enable-ladspa --enable-libaom --enable-libdav1d --enable-libass --enable-libbluray --enable-libcdio --enable-libdrm --enable-libjack --enable-libfreetype --enable-libfribidi --enable-libgsm --enable-libmp3lame --enable-libmysofa --enable-nvenc --enable-openal --enable-opencl --enable-opengl --enable-libopenjpeg --enable-libopenmpt --enable-libopus --enable-libpulse --enable-librsvg --enable-librav1e --enable-libsmbclient --enable-version3 --enable-libsoxr --enable-libspeex --enable-libsrt --enable-libssh --enable-libsvtav1 --enable-libtheora --enable-libvorbis --enable-libv4l2 --enable-libvidstab --enable-libvmaf --enable-version3 --enable-vapoursynth --enable-libvpx --enable-vulkan --enable-libglslang --enable-libx264 --enable-libx265 --enable-libxvid --enable-libxml2 --enable-libzimg --enable-libzvbi --enable-lv2 --enable-avfilter --enable-avresample --enable-libmodplug --enable-postproc --enable-pthreads --disable-static --enable-shared --enable-gpl --disable-debug --disable-stripping --shlibdir=/usr/lib64 --enable-lto --enable-libmfx --enable-runtime-cpudetect
libavutil 56. 70.100 / 56. 70.100
libavcodec 58.134.100 / 58.134.100
libavformat 58. 76.100 / 58. 76.100
libavdevice 58. 13.100 / 58. 13.100
libavfilter 7.110.100 / 7.110.100
libavresample 4. 0. 0 / 4. 0. 0
libswscale 5. 9.100 / 5. 9.100
libswresample 3. 9.100 / 3. 9.100
libpostproc 55. 9.100 / 55. 9.100
[x11grab @ 0x555dd0fd88c0] Stream #0: not enough frames to estimate rate; consider increasing probesize
Input #0, x11grab, from ':0.0':
Duration: N/A, start: 1618438743.719124, bitrate: 15925248 kb/s
Stream #0:0: Video: rawvideo (BGR[0] / 0x524742), bgr0, 3840x2160, 15925248 kb/s, 60 fps, 1000k tbr, 1000k tbn, 1000k tbc
File 'output-cpu.mp4' already exists. Overwrite? [y/N] y
Stream mapping:
Stream #0:0 -> #0:0 (rawvideo (native) -> h264 (libx264))
Press [q] to stop, [?] for help
[libx264 @ 0x555dd0fe6c00] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX FMA3 BMI2 AVX2
[libx264 @ 0x555dd0fe6c00] profile High 4:4:4 Predictive, level 5.2, 4:4:4, 8-bit
[libx264 @ 0x555dd0fe6c00] 264 - core 161 r3039 544c61f - H.264/MPEG-4 AVC codec - Copyleft 2003-2021 - http://www.videolan.org/x264.html - options: cabac=1 ref=3 deblock=1:0:0 analyse=0x3:0x113 me=hex subme=7 psy=1 psy_rd=1.00:0.00 mixed_ref=1 me_range=16 chroma_me=1 trellis=1 8x8dct=1 cqm=0 deadzone=21,11 fast_pskip=1 chroma_qp_offset=4 threads=48 lookahead_threads=8 sliced_threads=0 nr=0 decimate=1 interlaced=0 bluray_compat=0 constrained_intra=0 bframes=3 b_pyramid=2 b_adapt=1 b_bias=0 direct=1 weightb=1 open_gop=0 weightp=2 keyint=250 keyint_min=25 scenecut=40 intra_refresh=0 rc_lookahead=40 rc=crf mbtree=1 crf=23.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 ip_ratio=1.40 aq=1:1.00
Output #0, mp4, to 'output-cpu.mp4':
Metadata:
encoder : Lavf58.76.100
Stream #0:0: Video: h264 (avc1 / 0x31637661), yuv444p(tv, progressive), 3840x2160, q=2-31, 60 fps, 15360 tbn
Metadata:
encoder : Lavc58.134.100 libx264
Side data:
cpb: bitrate max/min/avg: 0/0/0 buffer size: 0 vbv_delay: N/A
More than 1000 frames duplicated 3328kB time=00:00:22.16 bitrate=1229.9kbits/s dup=982 drop=0 speed=1.03x
frame= 1470 fps= 65 q=-1.0 Lsize= 4052kB time=00:00:24.45 bitrate=1357.6kbits/s dup=1008 drop=0 speed=1.08x
video:4034kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.446444%
[libx264 @ 0x555dd0fe6c00] frame I:7 Avg QP:17.48 size:333161
[libx264 @ 0x555dd0fe6c00] frame P:380 Avg QP:15.96 size: 3109
[libx264 @ 0x555dd0fe6c00] frame B:1083 Avg QP:19.12 size: 569
[libx264 @ 0x555dd0fe6c00] consecutive B-frames: 0.7% 2.3% 2.9% 94.1%
[libx264 @ 0x555dd0fe6c00] mb I I16..4: 34.2% 44.9% 20.9%
[libx264 @ 0x555dd0fe6c00] mb P I16..4: 0.2% 0.2% 0.1% P16..4: 0.2% 0.1% 0.1% 0.0% 0.0% skip:99.2%
[libx264 @ 0x555dd0fe6c00] mb B I16..4: 0.0% 0.0% 0.0% B16..8: 0.8% 0.0% 0.0% direct: 0.0% skip:99.1% L0:56.4% L1:42.7% BI: 0.9%
[libx264 @ 0x555dd0fe6c00] 8x8 transform intra:44.3% inter:22.3%
[libx264 @ 0x555dd0fe6c00] coded y,u,v intra: 13.3% 1.4% 1.3% inter: 0.0% 0.0% 0.0%
[libx264 @ 0x555dd0fe6c00] i16 v,h,dc,p: 70% 28% 1% 0%
[libx264 @ 0x555dd0fe6c00] i8 v,h,dc,ddl,ddr,vr,hd,vl,hu: 74% 7% 19% 0% 0% 0% 0% 0% 0%
[libx264 @ 0x555dd0fe6c00] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 49% 20% 13% 2% 3% 3% 3% 3% 3%
[libx264 @ 0x555dd0fe6c00] Weighted P-Frames: Y:0.0% UV:0.0%
[libx264 @ 0x555dd0fe6c00] ref P L0: 65.4% 11.8% 14.2% 8.6%
[libx264 @ 0x555dd0fe6c00] ref B L0: 58.0% 40.6% 1.4%
[libx264 @ 0x555dd0fe6c00] ref B L1: 98.1% 1.9%
[libx264 @ 0x555dd0fe6c00] kb/s:1348.55
Exiting normally, received signal 2.