对于机器人任务,我们需要将视频(网络摄像头)实时分享给同一房间的 6 到 7 位用户。客户端将使用 OpenCV 来读取情况并向机器人发送新任务。延迟不应超过一秒,越低越好。您会推荐哪些命令来实现这一点?
我们在 Linux 主机上有一个摄像头,它想要将视频分享给几米外的其他 6 个单元。
我已经尝试了不同的设置。虽然原始视频看起来完全没有延迟(本地环回,问题在于数据量),但任何压缩都会突然增加大约一秒钟的延迟。我们应该如何在网络中共享它。广播是正确的方法吗?怎么会这么难,它们彼此相邻。
在本地工作,在网络上发出问题。
#server
ffmpeg -f video4linux2 -r 10 -s 1280x720 -i /dev/video0 -c:v libx264 -preset veryfast -tune zerolatency -pix_fmt yuv420p -f mpegts - | socat - udp-sendto:192.168.0.255:12345,broadcast
#client
socat -u udp-recv:12345,reuseaddr - | vlc --live-caching=0 --network-caching=0 --file-caching=0 -
原始视频 - 像这样的视频非常好,但如果通过网络发送,视频会有很多瑕疵
ffmpeg -f video4linux2 -r 10 -s 1280x720 -i /dev/video0 -c:v rawvideo -f rawvideo -pix_fmt yuv420p - | vlc --demux rawvideo --rawvid-fps 10 --rawvid-width 1280 --rawvid-height 720 --rawvid-chroma I420 -
使用的技术并不重要,我们也不关心网络负载。只想使用实时数据在不同的客户端上使用 opencv。
答案1
操作系统:Debian Stretch
cat /etc/*release
PRETTY_NAME="Debian GNU/Linux 9 (stretch)"
NAME="Debian GNU/Linux"
VERSION_ID="9"
VERSION="9 (stretch)"
ID=debian
HOME_URL="https://www.debian.org/"
SUPPORT_URL="https://www.debian.org/support"
BUG_REPORT_URL="https://bugs.debian.org/"
uname -v
#1 SMP Debian 4.9.25-1 (2017-05-02)
cvlc --version
VLC media player 2.2.6 Umbrella (revision 2.2.6-0-g1aae78981c)
VLC-Version 2.2.6 Umbrella (2.2.6-0-g1aae78981c)
Kompiliert von buildd auf binet.debian.org (May 24 2017 16:00:59)
Kompiler: gcc version 6.3.0 20170516 (Debian 6.3.0-18)
Dieses Programm kommt OHNE GEWÄHRLEISTUNG.
Sie dürfen das Programm unter den Bedingungen der GNU General Public License weitergegeben;
Für Details bitte die Datei COPYING ansehen.
Geschrieben von der VideoLAN-Gruppe; zu sehen in der AUTHORS-Datei.
ffplay -version
ffplay version 3.2.5-1 Copyright (c) 2003-2017 the FFmpeg developers
built with gcc 6.3.0 (Debian 6.3.0-18) 20170516
configuration: --prefix=/usr --extra-version=1 --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-libebur128 --enable-libflite --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libmp3lame --enable-libopenjpeg --enable-libopenmpt --enable-libopus --enable-libpulse --enable-librubberband --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-libxvid --enable-libzmq --enable-libzvbi --enable-omx --enable-openal --enable-opengl --enable-sdl2 --enable-libdc1394 --enable-libiec61883 --enable-chromaprint --enable-frei0r --enable-libopencv --enable-libx264 --enable-shared
libavutil 55. 34.101 / 55. 34.101
libavcodec 57. 64.101 / 57. 64.101
libavformat 57. 56.101 / 57. 56.101
libavdevice 57. 1.100 / 57. 1.100
libavfilter 6. 65.100 / 6. 65.100
libavresample 3. 1. 0 / 3. 1. 0
libswscale 4. 2.100 / 4. 2.100
libswresample 2. 3.100 / 2. 3.100
libpostproc 54. 1.100 / 54. 1.100
ffmpeg -version
ffmpeg version 3.2.5-1 Copyright (c) 2000-2017 the FFmpeg developers
built with gcc 6.3.0 (Debian 6.3.0-18) 20170516
configuration: --prefix=/usr --extra-version=1 --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-libebur128 --enable-libflite --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libmp3lame --enable-libopenjpeg --enable-libopenmpt --enable-libopus --enable-libpulse --enable-librubberband --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-libxvid --enable-libzmq --enable-libzvbi --enable-omx --enable-openal --enable-opengl --enable-sdl2 --enable-libdc1394 --enable-libiec61883 --enable-chromaprint --enable-frei0r --enable-libopencv --enable-libx264 --enable-shared
libavutil 55. 34.101 / 55. 34.101
libavcodec 57. 64.101 / 57. 64.101
libavformat 57. 56.101 / 57. 56.101
libavdevice 57. 1.100 / 57. 1.100
libavfilter 6. 65.100 / 6. 65.100
libavresample 3. 1. 0 / 3. 1. 0
libswscale 4. 2.100 / 4. 2.100
libswresample 2. 3.100 / 2. 3.100
libpostproc 54. 1.100 / 54. 1.100
ffplay /dev/video0
Input #0, video4linux2,v4l2, from '/dev/video0':B sq= 0B f=0/0
Duration: N/A, start: 45810.627382, bitrate: 122880 kb/s
Stream #0:0: Video: rawvideo (YUY2 / 0x32595559), yuyv422, 640x480, 122880 kb/s, 25 fps, 25 tbr, 1000k tbn, 1000k tbc
--> yuyv422
完美搭配(原始视频):
服务器:
cvlc -vvv v4l2:// :v4l2-dev=/dev/video0 :v4l2-width=640 :v4l2-height=480 :v4l2-fps 25 --sout '#standard{access=http,mux=raw,dst=:8081}'
客户:
ffplay -f rawvideo -pixel_format yuyv422 -video_size 640x480 -framerate 25 http://localhost:8081
(ffplay -f rawvideo -pixel_format yuyv422 -video_size 640x480 http://localhost:8081)
(ffplay -f rawvideo -pixel_format yuyv422 -video_size 640x480 http://server-ip:8081)
抱歉,没有 gbit 网络也没有 1080p 摄像头 :(
对于 Raspberry Pi(3) 用户:
sudo modprobe bcm2835-v4l2
(pi3 上无显示/X11)
ffprobe /dev/video0
ffprobe version N-85344-gb438a78 Copyright (c) 2007-2017 the FFmpeg developers
built with gcc 4.9.2 (Raspbian 4.9.2-10)
configuration:
libavutil 55. 60.100 / 55. 60.100
libavcodec 57. 92.100 / 57. 92.100
libavformat 57. 72.100 / 57. 72.100
libavdevice 57. 7.100 / 57. 7.100
libavfilter 6. 84.100 / 6. 84.100
libswscale 4. 7.100 / 4. 7.100
libswresample 2. 8.100 / 2. 8.100
Input #0, video4linux2,v4l2, from '/dev/video0':
Duration: N/A, start: 153.062714, bitrate: 283115 kb/s
Stream #0:0: Video: rawvideo (I420 / 0x30323449), yuv420p, 1024x768, 283115 kb/s, 30 fps, 30 tbr, 1000k tbn, 1000k tbc
--> yuv420p
但,
cvlc -vvv v4l2:// :v4l2-dev=/dev/video0 :v4l2-width=1024 :v4l2-height=768 :v4l2-fps=30 --sout '#standard{access=http,mux=raw,dst=:3333}'
结果
ffplay -f rawvideo -pixel_format yuv420p -video_size 1024x768 http://server-ip:3333
客户端上的情况不太好。
cvlc -vvv v4l2:// :v4l2-dev=/dev/video0 :v4l2-width=800 :v4l2-height=600 :v4l2-fps=16 --sout '#standard{access=http,mux=raw,dst=:3333}'
(~12MBiT/s-->100Mbit)
在服务器上,结果为
ffplay -f rawvideo -pixel_format yuv420p -video_size 800x600 http://server-ip:3333
在客户端上好的!