我知道如何对视频流的背景进行色度键/绿屏过滤,并使用 v4l2loopback 将其替换为图像。运行后
$ sudo modprobe v4l2loopback
我的代码如下:
$ ffmpeg -i background.jpg -f v4l2 -pix_fmt mjpeg \
-framerate 30 -video_size 1280x720 -i /dev/video0 \
-filter_complex \
"[0:v]scale=1280x720[bg]; \
[1:v]colorkey=0x00b140:0.5:0.0[ckout];
[bg][ckout]overlay" \
-pix_fmt yuv420p -f v4l2 /dev/video1
然后我可以简单地在我喜欢的任何视频播放应用程序中选择新的伪网络摄像头作为输入。
我想要一个短视频,而不是静止图像,在后台连续循环。我很确定这是可能的,但不知道如何,非常感谢任何提示!
更新 1:根据要求,这是响应中建议的命令的完整日志
$ ffmpeg -stream_loop 5 -re -i some_gif.gif \
-f v4l2 -pix_fmt mjpeg -framerate 30 \
-video_size 1280x720 -i /dev/video0 \
-filter_complex \
"[0:v]scale=1280x720[bg]; \
[1:v]colorkey=0x61A051:0.3:0.0[ckout]; \
[bg][ckout]overlay" \
-pix_fmt yuv420p -f v4l2 /dev/video1
ffmpeg version 3.4.8-0ubuntu0.2 Copyright (c) 2000-2020 the FFmpeg developers
built with gcc 7 (Ubuntu 7.5.0-3ubuntu1~18.04)
configuration: --prefix=/usr --extra-version=0ubuntu0.2 --toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu --incdir=/usr/include/x86_64-linux-gnu --enable-gpl --disable-stripping --enable-avresample --enable-avisynth --enable-gnutls --enable-ladspa --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libflite --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libmp3lame --enable-libmysofa --enable-libopenjpeg --enable-libopenmpt --enable-libopus --enable-libpulse --enable-librubberband --enable-librsvg --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libssh --enable-libtheora --enable-libtwolame --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx265 --enable-libxml2 --enable-libxvid --enable-libzmq --enable-libzvbi --enable-omx --enable-openal --enable-opengl --enable-sdl2 --enable-libdc1394 --enable-libdrm --enable-libiec61883 --enable-chromaprint --enable-frei0r --enable-libopencv --enable-libx264 --enable-shared
libavutil 55. 78.100 / 55. 78.100
libavcodec 57.107.100 / 57.107.100
libavformat 57. 83.100 / 57. 83.100
libavdevice 57. 10.100 / 57. 10.100
libavfilter 6.107.100 / 6.107.100
libavresample 3. 7. 0 / 3. 7. 0
libswscale 4. 8.100 / 4. 8.100
libswresample 2. 9.100 / 2. 9.100
libpostproc 54. 7.100 / 54. 7.100
Input #0, gif, from 'some_gif.gif':
Duration: N/A, bitrate: N/A
Stream #0:0: Video: gif, bgra, 640x640, 10 fps, 10 tbr, 100 tbn, 100 tbc
Input #1, video4linux2,v4l2, from '/dev/video0':
Duration: N/A, start: 433330.420280, bitrate: N/A
Stream #1:0: Video: mjpeg, yuvj422p(pc, bt470bg/unknown/unknown), 1280x720, 30 fps, 30 tbr, 1000k tbn, 1000k tbc
Stream mapping:
Stream #0:0 (gif) -> scale
Stream #1:0 (mjpeg) -> colorkey
overlay -> Stream #0:0 (rawvideo)
Press [q] to stop, [?] for help
[swscaler @ 0x563d17c69e80] deprecated pixel format used, make sure you did set range correctly
[swscaler @ 0x563d17c69e80] No accelerated colorspace conversion found from yuv422p to argb.
Output #0, v4l2, to '/dev/video1':
Metadata:
encoder : Lavf57.83.100
Stream #0:0: Video: rawvideo (I420 / 0x30323449), yuv420p, 1280x720, q=2-31, 110592 kb/s, 10 fps, 10 tbn, 10 tbc (default)
Metadata:
encoder : Lavc57.107.100 rawvideo
Past duration 0.899986 too largeN/A time=00:00:05.10 bitrate=N/A speed= 1x
frame= 98 fps= 10 q=-0.0 Lsize=N/A time=00:00:09.80 bitrate=N/A dup=0 drop=20 speed=1.03x
video:132300kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: unknown
更新 2:通过应用更新后
$ sudo add-apt-repository ppa:jonathonf/ffmpeg-4
$ sudo apt-get update
$ sudo apt-get install ffmpeg
我现在安装了以下版本
ffmpeg version 4.3.1-0york0~18.04 Copyright (c) 2000-2020 the FFmpeg developers
现在答案有效:)