我想接受 RTMP 流(来自 OBS)并将视频源发送到 v4l2 环回设备,类似于https://stackoverflow.com/questions/31484616/linux-ffmpeg-get-rtmp-stream-and-convert-into-a-live-webcam-v4l2
但是,我一开始就被阻止了,因为 ffmpeg 不会监听 RTMP 流的连接,它会尝试自行连接并立即失败……这是在 Fedora Silverblue 35 的工具箱中,使用 ffmpeg 的 RPM fusion 版本。如何让 ffmpeg 在提供的 URL 上监听,而不是尝试连接到现有服务器?
(是的,OBS 内置了虚拟摄像头,其想法是将流中的音频发送到虚拟音频设备 ala pipewire,以便 Zoom/Teams/等获得处理过的视频和音频,而不是未处理的“音频监视器”。)
⬢[bnordgren@toolbox v4l2loopback]$ ffmpeg -listen 1 -timeout 10000 -f flv -loglevel debug -i rtmp://127.0.0.1:5000/mystream/test -vcodec rawvideo -y -f v4l2 /dev/video4
ffmpeg version 4.4.1 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 -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1 ' --extra-cflags=' -I/usr/include/rav1e' --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libvo-amrwbenc --enable-version3 --enable-bzlib --enable-chromaprint --disable-crystalhd --enable-fontconfig --enable-frei0r --enable-gcrypt --enable-gnutls --enable-ladspa --enable-libaom --enable-libdav1d --enable-libass --enable-libbluray --enable-libbs2b --enable-libcdio --enable-libdrm --enable-libjack --enable-libfreetype --enable-libfribidi --enable-libgsm --enable-libilbc --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-librtmp --enable-librubberband --enable-libsmbclient --enable-version3 --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libsrt --enable-libssh --enable-libsvtav1 --enable-libtesseract --enable-libtheora --enable-libtwolame --enable-libvorbis --enable-libv4l2 --enable-libvidstab --enable-libvmaf --enable-version3 --enable-vapoursynth --enable-libvpx --enable-vulkan --enable-libglslang --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxvid --enable-libxml2 --enable-libzimg --enable-libzmq --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
Splitting the commandline.
Reading option '-listen' ... matched as AVOption 'listen' with argument '1'.
Reading option '-timeout' ... matched as AVOption 'timeout' with argument '10000'.
Reading option '-f' ... matched as option 'f' (force format) with argument 'flv'.
Reading option '-loglevel' ... matched as option 'loglevel' (set logging level) with argument 'debug'.
Reading option '-i' ... matched as input url with argument 'rtmp://127.0.0.1:5000/mystream/test'.
Reading option '-vcodec' ... matched as option 'vcodec' (force video codec ('copy' to copy stream)) with argument 'rawvideo'.
Reading option '-y' ... matched as option 'y' (overwrite output files) with argument '1'.
Reading option '-f' ... matched as option 'f' (force format) with argument 'v4l2'.
Reading option '/dev/video4' ... 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 y (overwrite output files) with argument 1.
Successfully parsed a group of options.
Parsing a group of options: input url rtmp://127.0.0.1:5000/mystream/test.
Applying option f (force format) with argument flv.
Successfully parsed a group of options.
Opening an input file: rtmp://127.0.0.1:5000/mystream/test.
[flv @ 0x560f5f84b4c0] Opening 'rtmp://127.0.0.1:5000/mystream/test' for reading
[rtmp @ 0x560f5f84c180] No default whitelist set
Parsing...
Parsed protocol: 0
Parsed host : 127.0.0.1
Parsed app : mystream
RTMP_Connect0, failed to connect socket. 111 (Connection refused)
rtmp://127.0.0.1:5000/mystream/test: Unknown error occurred
答案1
至于RTMP连接,应该可以了。
我无法使用 RPM fusion 在工具箱中的 Fedora Silverblue 35 上进行测试(我运行的是 Windows 10)。
我也没有内置虚拟摄像头。
我的答案仅适用于 RTMP 连接...
为了使事情可重现,以下示例将合成视频流式传输到 RTMP。
侦听器进程将视频写入 MP4 文件。
执行顺序很重要——首先启动监听器进程。
打开两个控制台。
在第一个控制台中执行监听FFmpeg进程:
ffmpeg -listen 1 -timeout 10000 -f flv -loglevel debug -i rtmp://127.0.0.1:5000/mystream/test -vcodec libx264 -y test.mp4
在第二个控制台执行 RTMP 推流过程:
ffmpeg -re -f lavfi -i testsrc=size=192x128:rate=1:duration=60 -pix_fmt yuv420p -vcodec libx264 -bufsize 64M -maxrate 4M -f flv rtmp://127.0.0.1:5000/mystream/test
一分钟后,test.mp4
文件创建完毕。
我认为无法确定确切的问题 - 您的帖子中有太多变量。
问题可能只是执行顺序问题,可能性很小。
我希望它有帮助...