我无法让 ffmpeg 捕获由 h264 编码的 X11 桌面视频。
我可以在不指定编码器的情况下捕获桌面,使用ffmpeg -y -f x11grab -s wuxga -r 5 -i :1 output.avi -loglevel repeat+level+debug
:
[info] ffmpeg started on 2019-09-16 at 10:59:13
Report written to "ffmpeg-20190916-105913.log"
Command line:
ffmpeg -y -f x11grab -s wuxga -r 5 -i :1 output.avi -loglevel repeat+level+debug -report
[info] ffmpeg version 4.0.2 Copyright (c) 2000-2018 the FFmpeg developers
[info] built with gcc 7 (SUSE Linux)
[info] configuration: --prefix=/usr --libdir=/usr/lib64 --shlibdir=/usr/lib64 --incdir=/usr/include/ffmpeg --docdir=/usr/share/doc/packages/ffmpeg --extra-cflags='-fmessage-length=0 -grecord-gcc-switches -O2 -Wall -D_FORTIFY_SOURCE=2 -fstack-protector-strong -funwind-tables -fasynchronous-unwind-tables -fstack-clash-protection' --optflags='-fmessage-length=0 -grecord-gcc-switches -O2 -Wall -D_FORTIFY_SOURCE=2 -fstack-protector-strong -funwind-tables -fasynchronous-unwind-tables -fstack-clash-protection' --enable-pic --disable-stripping --enable-shared --disable-static --enable-runtime-cpudetect --enable-libxcb --enable-libxcb-shm --enable-libxcb-xfixes --enable-libxcb-shape
[info] libavutil 56. 14.100 / 56. 14.100
[info] libavcodec 58. 18.100 / 58. 18.100
[info] libavformat 58. 12.100 / 58. 12.100
[info] libavdevice 58. 3.100 / 58. 3.100
[info] libavfilter 7. 16.100 / 7. 16.100
[info] libswscale 5. 1.100 / 5. 1.100
[info] libswresample 3. 1.100 / 3. 1.100
...
...
[info] Output #0, avi, to 'output.avi':
[info] Metadata:
[info] ISFT : Lavf58.12.100
[info] Stream #0:0, 0, 1/5: Video: mpeg4, 1 reference frame (FMP4 / 0x34504D46), yuv420p, 1920x1200, 0/1, q=2-31, 200 kb/s, 5 fps, 5 tbn, 5 tbc
[info] Metadata:
[info] encoder : Lavc58.18.100 mpeg4
[info] Side data:
[info] cpb: bitrate max/min/avg: 0/0/200000 buffer size: 0 vbv_delay: -1
...
...
[info] video:811kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.711410%
[verbose] Input file #0 (:1):
[verbose] Input stream #0:0 (video): 9 packets read (82944000 bytes); 9 frames decoded;
[verbose] Total: 9 packets (82944000 bytes) demuxed
[verbose] Output file #0 (output.avi):
[verbose] Output stream #0:0 (video): 9 frames encoded; 9 packets muxed (830464 bytes);
[verbose] Total: 9 packets (830464 bytes) muxed
[debug] 9 frames successfully decoded, 0 decoding errors
[AVIOContext @ 0x563d11c6aac0] [debug] Statistics: 8 seeks, 11 writeouts
添加编码器选项后-c:v h264_v4l2m2m
捕获失败:
[info] ffmpeg started on 2019-09-16 at 10:59:04
Report written to "ffmpeg-20190916-105904.log"
Command line:
ffmpeg -y -f x11grab -s wuxga -r 5 -i :1 -c:v h264_v4l2m2m output.avi -loglevel repeat+level+debug -report
[info] ffmpeg version 4.0.2 Copyright (c) 2000-2018 the FFmpeg developers
[info] built with gcc 7 (SUSE Linux)
[info] configuration: --prefix=/usr --libdir=/usr/lib64 --shlibdir=/usr/lib64 --incdir=/usr/include/ffmpeg --docdir=/usr/share/doc/packages/ffmpeg --extra-cflags='-fmessage-length=0 -grecord-gcc-switches -O2 -Wall -D_FORTIFY_SOURCE=2 -fstack-protector-strong -funwind-tables -fasynchronous-unwind-tables -fstack-clash-protection' --optflags='-fmessage-length=0 -grecord-gcc-switches -O2 -Wall -D_FORTIFY_SOURCE=2 -fstack-protector-strong -funwind-tables -fasynchronous-unwind-tables -fstack-clash-protection' --enable-pic --disable-stripping --enable-shared --disable-static --enable-runtime-cpudetect --enable-libxcb --enable-libxcb-shm --enable-libxcb-xfixes --enable-libxcb-shape
[info] libavutil 56. 14.100 / 56. 14.100
[info] libavcodec 58. 18.100 / 58. 18.100
[info] libavformat 58. 12.100 / 58. 12.100
[info] libavdevice 58. 3.100 / 58. 3.100
[info] libavfilter 7. 16.100 / 7. 16.100
[info] libswscale 5. 1.100 / 5. 1.100
[info] libswresample 3. 1.100 / 3. 1.100
...
...
[debug] Applying option c:v (codec name) with argument h264_v4l2m2m.
...
...
[info] Stream mapping:
[info] Stream #0:0 -> #0:0 (rawvideo (native) -> h264 (h264_v4l2m2m))
...
...
[h264_v4l2m2m @ 0x5605d58c0100] [error] Could not find a valid device
[h264_v4l2m2m @ 0x5605d58c0100] [error] can't configure encoder
[error] Error initializing output stream 0:0 -- Error while opening encoder for output stream #0:0 - maybe incorrect parameters such as bit_rate, rate, width or height
[AVIOContext @ 0x5605d58c1280] [debug] Statistics: 0 seeks, 0 writeouts
[info] Conversion failed!
我做错了什么?(为了完整起见,我有一个自定义的 ffmpeg 版本,但编码器似乎包含在内......)
由于 SE 政策的原因,列表有所缩短,完整版本的链接如下: