linux ffmpeg 获取 rtmp 流并转换为实时网络摄像头 v4l2

linux ffmpeg get rtmp stream and convert into a live webcam v4l2

所以我只是尝试获取流并将其转换为原始视频并使用 v4l2 创建一个新的网络摄像头。

ffmpeg -i "rtmp://XX.XX.XXX.XXX/XXXXXXXXXXXX/test" -vcodec rawvideo -y -f v4l2 /dev/video2

它工作了很长时间然后我得到了这个:

ffmpeg version 2.7.1 Copyright (c) 2000-2015 the FFmpeg developers
  built with gcc 5.1.0 (GCC)
  configuration: --prefix=/usr --disable-debug --disable-static --disable-stripping --enable-avisynth --enable-avresample --enable-fontconfig --enable-gnutls --enable-gpl --enable-libass --enable-libbluray --enable-libfreetype --enable-libfribidi --enable-libgsm --enable-libmodplug --enable-libmp3lame --enable-libopencore_amrnb --enable-libopencore_amrwb --enable-libopenjpeg --enable-libopus --enable-libpulse --enable-libschroedinger --enable-libspeex --enable-libssh --enable-libtheora --enable-libv4l2 --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libx265 --enable-libxvid --enable-shared --enable-version3 --enable-x11grab
  libavutil      54. 27.100 / 54. 27.100
  libavcodec     56. 41.100 / 56. 41.100
  libavformat    56. 36.100 / 56. 36.100
  libavdevice    56.  4.100 / 56.  4.100
  libavfilter     5. 16.101 /  5. 16.101
  libavresample   2.  1.  0 /  2.  1.  0
  libswscale      3.  1.101 /  3.  1.101
  libswresample   1.  2.100 /  1.  2.100
  libpostproc    53.  3.100 / 53.  3.100
Input #0, flv, from 'rtmp://XX.XX.XXX.XXX/XXXXXXXXXXXX/test':
  Metadata:
    fileSize        : 0
    audiochannels   : 2
    encoder         : obs-output module (libobs version 0.10.1-67-g94edb7f)
  Duration: 00:00:00.00, start: 1774.608000, bitrate: N/A
    Stream #0:0: Video: h264 (High), yuv420p(tv, bt709), 1920x1080, 2560 kb/s, 30.30 fps, 30 tbr, 1k tbn, 60 tbc
    Stream #0:1: Audio: aac (LC), 44100 Hz, stereo, fltp, 196 kb/s
[v4l2 @ 0x7f7326cb4480] Unable to open V4L2 device '/dev/video2'
Output #0, v4l2, to '/dev/video2':
  Metadata:
    fileSize        : 0
    audiochannels   : 2
    encoder         : Lavf56.36.100
    Stream #0:0: Video: rawvideo (I420 / 0x30323449), yuv420p, 1920x1080, q=2-31, 200 kb/s, 30 fps, 30 tbn, 30 tbc
    Metadata:
      encoder         : Lavc56.41.100 rawvideo
Stream mapping:
  Stream #0:0 -> #0:0 (h264 (native) -> rawvideo (native))
Could not write header for output file #0 (incorrect codec parameters ?): No such file or directory

要创建虚拟视频设备,您需要安装并启用 v4l2loopback。 "No such file or directory" 消息表示您没有启用该设备。

sudo modprobe v4l2loopback video_nr=2

这将创建 /dev/video2 设备。

更新:作为对 umläute 评论的回应,请确保 v4l2loopback 模块是持久的,以防您的服务器重新启动。正常运行时间可能会很长。

CentOS 示例:Persistent Module Loading