[英]RaspberryPi HLS streaming with nginx and ffmpeg; v4l2 error: ioctl(VIDIOC_STREAMON): Protocol error
我正在嘗試使用 Raspberry Pi(型號 4B,4GB RAM)和普通網絡攝像頭(帶集成麥克風)來實現嬰兒監控。 我跟着這個教程:https://github.com/DeTeam/webcam-stream/blob/master/Tutorial.md
簡要說明:
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
的 output 是:
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,DEV=0
HD Web Camera, USB Audio
2.1 Surround output to Front and Subwoofer speakers
surround40:CARD=Camera,DEV=0
HD Web Camera, USB Audio
4.0 Surround output to Front and Rear speakers
surround41:CARD=Camera,DEV=0
HD Web Camera, USB Audio
4.1 Surround output to Front, Rear and Subwoofer speakers
surround50:CARD=Camera,DEV=0
HD Web Camera, USB Audio
5.0 Surround output to Front, Center and Rear speakers
surround51:CARD=Camera,DEV=0
HD Web Camera, USB Audio
5.1 Surround output to Front, Center, Rear and Subwoofer speakers
surround71:CARD=Camera,DEV=0
HD Web Camera, USB Audio
7.1 Surround output to Front, Center, Side, Rear and Woofer speakers
iec958:CARD=Camera,DEV=0
HD Web Camera, USB Audio
IEC958 (S/PDIF) Digital Audio Output
dmix:CARD=Camera,DEV=0
HD Web Camera, USB Audio
Direct sample mixing device
dsnoop:CARD=Camera,DEV=0
HD Web Camera, USB Audio
Direct sample snooping device
hw:CARD=Camera,DEV=0
HD Web Camera, USB Audio
Direct hardware device without any conversions
plughw:CARD=Camera,DEV=0
HD Web Camera, USB Audio
Hardware device with all software conversions
usbstream:CARD=Camera
HD Web Camera
USB Stream Output
這就是我添加-i hw:CARD=Camera,DEV=0
的原因。
如上所述,使用此配置和命令多次運行良好。 但很多時候,我在開始 stream 時收到以下錯誤消息:
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
的 output ),我收到以下錯誤消息:
pi@raspberrypi:~ $ ffmpeg -re -f v4l2 -i /dev/video1 -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 @ 0x1aa4610] ioctl(VIDIOC_G_INPUT): Inappropriate ioctl for device
/dev/video1: Inappropriate ioctl for device
使用video0
輸入時,識別訪問的網絡攝像頭 LED 常亮。 使用video1
時沒有。
經過數小時和數天的谷歌搜索、淚水和威士忌,為了我的肝臟、我的婚姻和我的身心健康,我非常真誠地請求你的幫助......我這樣做是為了讓它工作???
謝謝大家:)
更新 1:
sudo ffmpeg...
也沒有任何改變ffmpeg -i /dev/video0
會導致同樣的問題更新 2:
當我第一次啟動另一個需要訪問網絡攝像頭的應用程序,然后是lsmod
...我啟動了應用程序...任何幫助仍然很感激...
更新 3:
我正在檢查dmesg
的 output 。
當我啟動第一個應用程序時,我收到了這條消息:
uvcvideo: Failed to query (GET_DEF) UVC control 12 on unit 2: -32 (exp. 4).
當我開始ffmpeg
時,什么也沒發生,但一切正常......
我遇到了同樣的問題,注意到您的 UPDATE 2 並執行了以下操作(python):
for i in range(3):
cam1 = cv2.VideoCapture(0)
ret, frame = cam1.read()
cam1.release()
cam1 = cv2.VideoCapture(0)
現在我仍然收到錯誤消息(僅一次),但相機工作正常。
不知道為什么或如何,但是......這就是方式(顯然)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.