我正在尝试将 Raspberry Pi 板设置为管道设备,它可以从摄像头或任何其他来源接收视频并将其传输到主机 PC。我正在遵循此处提到的教程
https://gist.github.com/justinschuldt/36469e2a89d95ef158a8c4df091e9cb4
我能够成功地将网络摄像头视频流传输到主机 PC。我想要做的是使用视频文件而不是网络摄像头的流。为了做到这一点,我做了以下事情
- 创建了一个虚拟的 v4l2loopback 设备
- 按照上述教程创建 uvc_gadget
我的设置如下
pi@raspberrypi:~ $ v4l2-ctl --list-devices fe980000.usb (gadget):
/dev/video1
bcm2835-codec-decode (platform:bcm2835-codec):
/dev/video10
/dev/video11
/dev/video12
mmal service 16.1 (platform:bcm2835-v4l2):
/dev/video0
Dummy video device (0x0000) (platform:v4l2loopback-000):
/dev/video2
之后我可以按如下方式启动 uvc_gadget
pi@raspberrypi:~ $ ~/uvc-gadget/uvc-gadget -d /dev/video2 -u /dev/video1 -r 1 -f 1
uvc device is fe980000.usb on bus gadget
uvc open succeeded, file descriptor = 3
control request (req 86 cs 02)
control request (req 86 cs 02)
streaming request (req 87 cs 01)
streaming request (req 01 cs 01)
setting probe control, length = 26
streaming request (req 81 cs 01)
现在,当我尝试将视频文件传输到 /dev/video2 时,主机上只出现了彩色条纹,并显示错误“未找到 jpeg 数据”
pi@raspberrypi:~ $ ffmpeg -re -i file_example_MP4_480_1_5MG.mp4 -map 0:v -f v4l2 /dev/video2
ffmpeg version 4.1.4-1+rpt7~deb10u1 Copyright (c) 2000-2019 the FFmpeg developers
在主机上我检查了哪些视频设备可供我使用
zain@zain-Creator-17M-A10SD:~$ v4l2-ctl --list-devices
Dummy video device (0x0000) (platform:v4l2loopback-000):
/dev/video2
PI4 USB Device: UVC Camera (usb-0000:00:14.0-4):
/dev/video0
/dev/video1
RPI4 显示为 UVC 相机。
我尝试使用 ffplay 读取视频设备,但没有流,只有错误。
zain@zain-Creator-17M-A10SD:~$ ffplay /dev/video0
ffplay version 3.4.8-0ubuntu0.2 Copyright (c) 2003-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
[mjpeg @ 0x7fecf40020e0] No JPEG data found in image= 0B f=0/0
[mjpeg @ 0x7fecf40020e0] No JPEG data found in image= 0B f=0/0
[video4linux2,v4l2 @ 0x7fecf4000b80] decoding for stream 0 failed
[video4linux2,v4l2 @ 0x7fecf4000b80] Could not find codec parameters for stream 0 (Video: mjpeg, none(bt470bg/unknown/unknown), 1280x720): unspecified pixel format
Consider increasing the value for the 'analyzeduration' and 'probesize' options
Input #0, video4linux2,v4l2, from '/dev/video0':
Duration: N/A, start: 331989.158354, bitrate: N/A
Stream #0:0: Video: mjpeg, none(bt470bg/unknown/unknown), 1280x720, 0.20 fps, 0.20 tbr, 1000k tbn, 1000k tbc
[mjpeg @ 0x7fecf40044c0] No JPEG data found in image
Last message repeated 2 times
[mjpeg @ 0x7fecf40044c0] No JPEG data found in image= 0B f=0/0
[mjpeg @ 0x7fecf40044c0] No JPEG data found in image= 0B f=0/0
[mjpeg @ 0x7fecf40044c0] No JPEG data found in image= 0B f=0/0
[mjpeg @ 0x7fecf40044c0] No JPEG data found in image= 0B f=0/0
[mjpeg @ 0x7fecf40044c0] No JPEG data found in image= 0B f=0/0
[mjpeg @ 0x7fecf40044c0] No JPEG data found in image= 0B f=0/0
[mjpeg @ 0x7fecf40044c0] No JPEG data found in image= 0B f=0/0
如果我使用 g_webcam 而不是 configFS 创建小工具,我会得到几乎类似的行为,不同之处在于我得到的是条纹彩线而不是此错误。
非常感谢您的帮助。我猜想编码存在一些问题。
答案1
因为uvc-gadget
不支持你的mp4大小。
ffmpeg -re -i /home/pi/test.mp4 -vf scale=640:480 -map 0:v -f v4l2 /dev/video0