问题描述
我正在尝试使用 RaspBerry Pi(4B 型,4GB RAM)和一个普通网络摄像头(带有集成麦克风)来实现婴儿监控。 我跟着这个教程:https://github.com/DeTeam/webcam-stream/blob/master/Tutorial.md
简述:
- 我安装并配置了一个启用了 rtmp 模块的 Nginx 服务器。
- 我使用此配置安装了 ffmpeg --enable-gpl --enable-nonfree --enable-mmal --enable-omx-rpi
- 我尝试流式传输;)
Nginx 的配置似乎可以正常工作(有时流可以正常工作,服务器启动没有任何复杂性,当服务器启动并运行时,会显示网页)。 ffmpeg 的配置似乎也很好,因为流式传输有时有效...
我尝试了几个不同的 ffmpeg 命令;所有这些有时都在工作,有时会导致错误。 命令如下所示:
ffmpeg -re
-f v4l2
-i /dev/video0
-f alsa
-ac 1
-thread_queue_size 4096
-i hw:CARD=Camera,DEV=0
-profile:v high
-level:v 4.1
-vcodec h264_omx
-r 10
-b:v 512k
-s 640x360
-acodec aac
-strict
-2
-ac 2
-ab 32k
-ar 44100
-f flv
rtmp://localhost/show/stream;
注意:我重新排列了代码以使其更易于阅读。在终端中,一切都在一行中。
注意:使用 -f video4linux2
代替 -f v4l2
摄像头被系统识别:
pi@raspBerrypi:~ $ v4l2-ctl --list-devices
bcm2835-codec-decode (platform:bcm2835-codec):
/dev/video10
/dev/video11
/dev/video12
bcm2835-isp (platform:bcm2835-isp):
/dev/video13
/dev/video14
/dev/video15
/dev/video16
HD Web Camera: HD Web Camera (usb-0000:01:00.0-1.2):
/dev/video0
/dev/video1
仅使用 -i /dev/video0
时,音频传输无法正常工作。
arecord -L
的输出是:
pi@raspBerrypi:~ $ arecord -L
default
Playback/recording through the pulseAudio sound server
null
discard all samples (playback) or generate zero samples (capture)
jack
JACK Audio Connection Kit
pulse
pulseAudio Sound Server
usbstream:CARD=Headphones
bcm2835 Headphones
USB Stream Output
sysdefault:CARD=Camera
HD Web Camera,USB Audio
Default Audio Device
front:CARD=Camera,DEV=0
HD Web Camera,USB Audio
Front speakers
surround21:CARD=Camera,USB Audio
2.1 Surround output to Front and Subwoofer speakers
surround40:CARD=Camera,USB Audio
4.0 Surround output to Front and Rear speakers
surround41:CARD=Camera,USB Audio
4.1 Surround output to Front,Rear and Subwoofer speakers
surround50:CARD=Camera,USB Audio
5.0 Surround output to Front,Center and Rear speakers
surround51:CARD=Camera,USB Audio
5.1 Surround output to Front,Center,Rear and Subwoofer speakers
surround71:CARD=Camera,USB Audio
7.1 Surround output to Front,Side,Rear and Woofer speakers
iec958:CARD=Camera,USB Audio
IEC958 (S/PDIF) Digital Audio Output
dmix:CARD=Camera,USB Audio
Direct sample mixing device
dsnoop:CARD=Camera,USB Audio
Direct sample snooping device
hw:CARD=Camera,USB Audio
Direct hardware device without any conversions
plughw:CARD=Camera,USB Audio
Hardware device with all software conversions
usbstream:CARD=Camera
HD Web Camera
USB Stream Output
这就是我添加 -i hw:CARD=Camera,DEV=0
的原因。
如上所述,使用此配置和命令多次运行良好。 但很多时候,我在开始流式传输时收到以下错误消息:
pi@raspBerrypi:~ $ ffmpeg -re -f video4linux2 -i /dev/video0 -f alsa -ac 1 -thread_queue_size 4096 -i hw:CARD=Camera,DEV=0 -profile:v high -level:v 4.1 -vcodec h264_omx -r 10 -b:v 512k -s 640x360 -acodec aac -strict -2 -ac 2 -ab 32k -ar 44100 -f flv rtmp://localhost/show/stream
ffmpeg version N-100673-g553eb07737 copyright (c) 2000-2021 the FFmpeg developers
built with gcc 8 (Raspbian 8.3.0-6+rpi1)
configuration: --enable-gpl --enable-nonfree --enable-mmal --enable-omx-rpi --extra-ldflags=-latomic
libavutil 56. 63.101 / 56. 63.101
libavcodec 58.117.101 / 58.117.101
libavformat 58. 65.101 / 58. 65.101
libavdevice 58. 11.103 / 58. 11.103
libavfilter 7. 96.100 / 7. 96.100
libswscale 5. 8.100 / 5. 8.100
libswresample 3. 8.100 / 3. 8.100
libpostproc 55. 8.100 / 55. 8.100
[video4linux2,v4l2 @ 0x2ea4600] ioctl(VIdioC_STREAMON): Protocol error
/dev/video0: Protocol error
当我切换到 /dev/video1
时(因为这也是 v4l2-ctl --list-devices
的输出),我收到以下错误消息:
pi@raspBerrypi:~ $ ffmpeg -re -f v4l2 -i /dev/video1 -f alsa -ac 1 -thread_queue_size 4096 -i hw:CARD=Camera,v4l2 @ 0x1aa4610] ioctl(VIdioC_G_INPUT): Inappropriate ioctl for device
/dev/video1: Inappropriate ioctl for device
使用 video0
输入时,网络摄像头识别访问的 LED 会一直亮着。使用 video1
not.
经过数小时的谷歌搜索、眼泪和威士忌,为了我的肝脏、我的婚姻和我的身心健康,我非常真诚地请求您的帮助...... 他妈的到底发生了什么,我该怎么做才能让它发挥作用???
谢谢大家:)
更新 1:
- 使用 ffmpeg 的完整路径不会改变任何东西...
- /dev/video0 和 /dev/video1 对每个人都有访问权限
-
sudo ffmpeg ...
也不会改变任何东西 - 问题似乎还处于“早期阶段”。将命令精简为
ffmpeg -i /dev/video0
会导致相同的问题
更新 2:
当我第一次启动另一个需要访问网络摄像头的应用程序然后 ffmpeg 时,似乎一切正常...
可能是一些驱动程序问题,但是当我寻找带有 lsmod
的加载模块时,在我启动应用程序之前和之后绝对没有变化......
任何帮助仍然不胜感激...
更新 3:
我正在检查 dmesg
的输出。
当我开始第一个应用程序时,我收到了这条消息:uvcvideo: Failed to query (GET_DEF) UVC control 12 on unit 2: -32 (exp. 4).
当我开始ffmpeg
时,什么也没发生,但一切正常......
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)