ffmpeg:mp4 到相机:转换

ffmpeg:mp4 到相机:转换

我发现了以下问题并尝试将 mp4 视频发送到我的相机: ffmpeg 有没有办法将视频发送到 Ubuntu 上的 /dev/video0?

我使用了以下命令:

ffmpeg -re -i fakezoom.mp4 -map 0:v -f h264 /dev/video0

根据Ubuntu,mp4的文件属性为H.264、每秒30帧、414kbps比特率。

当我运行该命令时,我得到以下输出:

ffmpeg -re -i fakezoom.mp4 -map 0:v -f h264 /dev/video0
ffmpeg version 4.2.4-1ubuntu0.1 Copyright (c) 2000-2020 the FFmpeg developers
  built with gcc 9 (Ubuntu 9.3.0-10ubuntu2)
  configuration: --prefix=/usr --extra-version=1ubuntu0.1 --toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu --incdir=/usr/include/x86_64-linux-gnu --arch=amd64 --enable-gpl --disable-stripping --enable-avresample --disable-filter=resample --enable-avisynth --enable-gnutls --enable-ladspa --enable-libaom --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libcodec2 --enable-libflite --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libjack --enable-libmp3lame --enable-libmysofa --enable-libopenjpeg --enable-libopenmpt --enable-libopus --enable-libpulse --enable-librsvg --enable-librubberband --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libssh --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx265 --enable-libxml2 --enable-libxvid --enable-libzmq --enable-libzvbi --enable-lv2 --enable-omx --enable-openal --enable-opencl --enable-opengl --enable-sdl2 --enable-libdc1394 --enable-libdrm --enable-libiec61883 --enable-nvenc --enable-chromaprint --enable-frei0r --enable-libx264 --enable-shared
  WARNING: library configuration mismatch
  avcodec     configuration: --prefix=/usr --extra-version=1ubuntu0.1 --toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu --incdir=/usr/include/x86_64-linux-gnu --arch=amd64 --enable-gpl --disable-stripping --enable-avresample --disable-filter=resample --enable-avisynth --enable-gnutls --enable-ladspa --enable-libaom --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libcodec2 --enable-libflite --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libjack --enable-libmp3lame --enable-libmysofa --enable-libopenjpeg --enable-libopenmpt --enable-libopus --enable-libpulse --enable-librsvg --enable-librubberband --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libssh --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx265 --enable-libxml2 --enable-libxvid --enable-libzmq --enable-libzvbi --enable-lv2 --enable-omx --enable-openal --enable-opencl --enable-opengl --enable-sdl2 --enable-libdc1394 --enable-libdrm --enable-libiec61883 --enable-nvenc --enable-chromaprint --enable-frei0r --enable-libx264 --enable-shared --enable-version3 --disable-doc --disable-programs --enable-libaribb24 --enable-liblensfun --enable-libopencore_amrnb --enable-libopencore_amrwb --enable-libtesseract --enable-libvo_amrwbenc
  libavutil      56. 31.100 / 56. 31.100
  libavcodec     58. 54.100 / 58. 54.100
  libavformat    58. 29.100 / 58. 29.100
  libavdevice    58.  8.100 / 58.  8.100
  libavfilter     7. 57.100 /  7. 57.100
  libavresample   4.  0.  0 /  4.  0.  0
  libswscale      5.  5.100 /  5.  5.100
  libswresample   3.  5.100 /  3.  5.100
  libpostproc    55.  5.100 / 55.  5.100
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x56370afc9700] st: 0 edit list: 1 Missing key frame while searching for timestamp: 0
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x56370afc9700] st: 0 edit list 1 Cannot find an index entry before timestamp: 0.
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'fakezoom.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 0
    compatible_brands: mp41avc1
    creation_time   : 2021-04-20T09:39:14.000000Z
    encoder         : vlc 3.0.9.2 stream output
    encoder-eng     : vlc 3.0.9.2 stream output
  Duration: 00:13:18.78, start: 0.000000, bitrate: 416 kb/s
    Stream #0:0(eng): Video: h264 (High) (avc1 / 0x31637661), yuv420p(tv, unknown/bt709/bt709), 1280x720 [SAR 1:1 DAR 16:9], 414 kb/s, 17.91 fps, 17.67 tbr, 90k tbn, 60 tbc (default)
    Metadata:
      creation_time   : 2021-04-20T09:39:14.000000Z
      handler_name    : VideoHandler
File '/dev/video0' already exists. Overwrite ? [y/N] y
Stream mapping:
  Stream #0:0 -> #0:0 (h264 (native) -> h264 (libx264))
Press [q] to stop, [?] for help
[libx264 @ 0x56370afce880] using SAR=1/1B time=-577014:32:22.77 bitrate=  -0.0kbits/s speed=N/A    
[libx264 @ 0x56370afce880] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX FMA3 BMI2 AVX2
[libx264 @ 0x56370afce880] profile High, level 3.1
Output #0, h264, to '/dev/video0':
  Metadata:
    major_brand     : isom
    minor_version   : 0
    compatible_brands: mp41avc1
    encoder         : Lavf58.29.100
    Stream #0:0(eng): Video: h264 (libx264), yuv420p, 1280x720 [SAR 1:1 DAR 16:9], q=-1--1, 17.67 fps, 17.67 tbn, 17.67 tbc (default)
    Metadata:
      creation_time   : 2021-04-20T09:39:14.000000Z
      handler_name    : VideoHandler
      encoder         : Lavc58.54.100 libx264
    Side data:
      cpb: bitrate max/min/avg: 0/0/0 buffer size: 0 vbv_delay: -1
av_interleaved_write_frame(): Invalid argumente=00:00:02.88 bitrate= 665.2kbits/s dup=0 drop=1 speed=0.408x     
Error writing trailer of /dev/video0: Invalid argument
frame=  121 fps= 16 q=27.0 Lsize=     258kB time=00:00:03.22 bitrate= 654.2kbits/s dup=0 drop=1 speed=0.432x    
video:258kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.000000%
[libx264 @ 0x56370afce880] frame I:1     Avg QP:17.14  size: 45994
[libx264 @ 0x56370afce880] frame P:31    Avg QP:20.92  size:  9074
[libx264 @ 0x56370afce880] frame B:89    Avg QP:22.87  size:   853
[libx264 @ 0x56370afce880] consecutive B-frames:  0.8%  3.3%  0.0% 95.9%
[libx264 @ 0x56370afce880] mb I  I16..4:  7.1% 77.3% 15.7%
[libx264 @ 0x56370afce880] mb P  I16..4:  0.2%  2.1%  0.5%  P16..4: 18.5%  7.1%  3.1%  0.0%  0.0%    skip:68.4%
[libx264 @ 0x56370afce880] mb B  I16..4:  0.0%  0.0%  0.0%  B16..8: 10.1%  0.4%  0.1%  direct: 0.3%  skip:89.1%  L0:48.1% L1:48.4% BI: 3.6%
[libx264 @ 0x56370afce880] 8x8 transform intra:76.2% inter:67.0%
[libx264 @ 0x56370afce880] coded y,uvDC,uvAC intra: 57.3% 80.2% 42.2% inter: 3.4% 5.5% 0.1%
[libx264 @ 0x56370afce880] i16 v,h,dc,p: 20% 15% 10% 55%
[libx264 @ 0x56370afce880] i8 v,h,dc,ddl,ddr,vr,hd,vl,hu: 28% 13% 12%  7%  9% 11%  7%  7%  6%
[libx264 @ 0x56370afce880] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 25% 18% 10%  6% 11% 11%  9%  6%  6%
[libx264 @ 0x56370afce880] i8c dc,h,v,p: 46% 20% 21% 13%
[libx264 @ 0x56370afce880] Weighted P-Frames: Y:0.0% UV:0.0%
[libx264 @ 0x56370afce880] ref P L0: 56.5% 16.3% 20.0%  7.2%
[libx264 @ 0x56370afce880] ref B L0: 75.3% 20.1%  4.6%
[libx264 @ 0x56370afce880] ref B L1: 98.8%  1.2%
[libx264 @ 0x56370afce880] kb/s:470.92
Conversion failed!

它以对话失败结束,但也包含一些其他奇怪的消息,例如

av_interleaved_write_frame(): Invalid argumente=00:00:02.88 bitrate= 665.2kbits/s dup=0 drop=1 speed=0.408x     
Error writing trailer of /dev/video0: Invalid argument

我做错什么了吗?

v4l2-ctl --list-devices

输出:

OBS Video Source (platform:v4l2loopback-000):
    /dev/video10

UVC Camera (046d:081b) (usb-0000:02:00.0-5):
    /dev/video0
    /dev/video1

可能是因为我在那里使用了环回?当我想以正确的方式使用相机时,我有时会使用将 /dev/video0 映射到 video10 的程序来模拟绿屏并添加虚拟背景。

有人知道如何解决这个问题吗?

答案1

您链接的答案显示了如何制作“假摄像头”。这样,您选择的视频就可以定向到/dev/video*尚未被实际设备使用的摄像头。

应该不需要将视频输入到现有设备。这些设备只输出视频,所以我怀疑您是否可以将任意视频输入到相机。

运行时,sudo modprobe v4l2loopback它应该/dev/video使用当前未使用的 ID 号(例如/dev/video2)创建一个新的。然后运行:

ffmpeg -re -i fakezoom.mp4 -map 0:v -f v4l2 /dev/video2

-f h264请注意将问题中的 as改为-f v4l2

相关内容