树莓派摄像头视频直播技术汇总

本文介绍了使用树莓派进行视频流传输的不同方法,包括VLC、gstreamer及netcat等工具的具体配置过程和优缺点对比。文章还提供了详细的步骤说明如何设置RTSP、HTTP及HLS流。

开发板推荐:天空星STM32F407VET6开发板

超高性价比 STM32主控 | 超高主频 | 一板兼容百芯 | 比赛神器 | 沉金彩色丝印


使用VLC, 延迟比较厉害,大概延迟2s,好处是支持RTSP协议,移动端方便实现


Here I'm documenting how to stream from the Raspberry Pi Camera board using VLC. Most of this is covered in the Raspberry Pi forums in this thread.

The camera needs to be setup using the various instructions on the Raspberry Pi website and the only additional software package that needs to be installed is VLC which can be installed by doing sudo apt-get install vlc with further details about it on the VideoLan website.

The most reliable streaming method seems to be via RTSP and the command line to launch it is.

raspivid -o - -t 0 |cvlc -v stream:///dev/stdin --sout '#rtp{sdp=rtsp://:8554/}' :demux=h264

This causes the video from the camera to be streamed from port 8554 of your Raspberry Pi. This can then be viewed by launching VLC on your PC and open a 'Network Stream' with the address rtsp://<IPofRaspberryPi>:8554/

RTSP works well on a local network, but can be hard to expose through a router to allowing streaming over the internet. To over come this VLC can be configured to stream via HTTP, this seems to use a bit more CPU on the Raspberry Pi and can suffer from dropped frames however it only uses one port and can be easily port forwarded through most standard routers. The command for this configuration is

raspivid -o - -t 0 |cvlc -v stream:///dev/stdin --sout '#standard{access=http,mux=ts,dst=:8554}' :demux=h264

Once more this can be viewed on your PC by using VLC and opening a 'Network Stream' with the address http://<IPofRaspberryPi>:8554/

One final way of streaming the video is over HLS (HTTP Live Streaming). This, apparently, allows the video to be easily streamed to iOS devices. For this to work a web server needs to be installed on the Raspberry Pi. A popular choice is apache that can be installed using sudo apt-get install apache which will then serve the files stored in /var/www. To setup VLC to generate the HLS stream you can run

raspivid -o - -t 0 | cvlc -v -I "dummy" stream:///dev/stdin  :sout="#std{access=livehttp{seglen=10,delsegs=true,numsegs=5, index=/var/www/streaming/stream.m3u8, index-url=http://<IPofRaspberryPi>/streaming/stream-########.ts}, mux=ts{use-key-frames}, dst=/var/www/streaming/stream-########.ts}" :demux=h264

(Remembering to correctly set the IP address of your Raspberry Pi). Again this can be played back using VLC by opening a Network Stream ofhttp://<IPofRaspberryPi>/streaming/stream.m3u8 however HLS can consume all the CPU on the Raspberry Pi


使用gstreamer,延时200ms左右,坏处了

http://www.haodaima.net/art/2711642

1.获取树莓派的摄像头的视频源并且输出到 gstreamer中,并将数据传输到tcpserversink中,设定端口为5000

raspivid -t 0 -w 800 -h 600 -fps 25 -g 5 -b 4000000 -vf -n -o - | gst-launch-1.0 fdsrc ! h264parse ! gdppay ! tcpserversink host=127.0.0.1 port=5000

 

2.在gst-rtsp-server的example中test-launch,从本机的5000端口获取数据流作为服务器的源数据,建立rtsp的服务器。

  ./test-launch "( tcpclientsrc host=127.0.0.1 port=5000 ! gdpdepay ! rtph264pay name=pay0 pt=96 )" 

 

3.在ubuntu14.2 中安装gstreamer ,执行以下代码来获取摄像头的图像

 gst-launch-1.0 -v rtspsrc location=rtsp://192.168.11.22:8554/test ! gdpdepay ! rtph264depay ! avdec_h264 ! videoconvert ! autovideosink 



http://www.raspberry-projects.com/pi/pi-hardware/raspberry-pi-camera/streaming-video-using-gstreamer


gstreamer allows you to stream video with very low latency – a problem with VLC currently.  The catch is that you need need gstreamer on the client used to view the stream.  gstreamer is a development framework not a media player and there isn't a way to stream so that common players such as VLC can display the stream (without users having to install complex plugins).  So, gstreamer can provide an excellent low latency video link, which is great if you are techy enough to set it up at both ends, but its no good if you want to directly stream so that Joe public can see the video on a web site for instance.

Setting Up The Raspberry Pi To Use gstreamer

You need to edit the sources.list file so enter:


sudo nano /etc/apt/sources.list

and add the following to the end of the file:


deb http://vontaene.de/raspbian-updates/ . main

Press CTRL+X to save and exit

Now run an update (which will make use of the line just added):


sudo apt-get update 

Now install gstreamer


sudo apt-get install gstreamer1.0
To Stream The Video From the Raspberry Pi

Enter this on the command lne:


raspivid -t 0 -h 720 -w 1080 -fps 25 -hf -b 2000000 -o - | gst-launch-1.0 -v fdsrc ! h264parse !  rtph264pay config-interval=1 pt=96 ! gdppay ! tcpserversink host=YOUR_RPI_IP_ADDRESS port=5000

Change YOUR_RPI_IP_ADDRESS to be the IP address of your  RPI.

To View The Stream

There's a lot of resources around for this.  Seems to be pretty easy on Linux, OK on a MAC and harder on Windows. Apparently streaming from RPi to PRi works really well.


http://raspberrypi.stackexchange.com/questions/27082/how-to-stream-raspivid-to-linux-and-osx-using-gstreamer-vlc-or-netcat


  • Netcat (nc) seems to be the one with the smallest delay.
  • In my experience, VLC has the biggest delay. On the other hand, there is a VLC client for Android, which is convenient.

  • <IP-OF-THE-CLIENT> is the IP of the computer that should receive the video stream.

  • <IP-OF-THE-RPI> is the IP of the Raspberry Pi.

Using Netcat:

On the client

(Run the command on the client first, and then on the server (RPi)).

Linux

nc -l 2222 | mplayer -fps 200 -demuxer h264es -

OS X

nc -l 2222 | mplayer -fps 200 -demuxer h264es -

On the RPi

/opt/vc/bin/raspivid -t 0 -w 300 -h 300 -hf -fps 20 -o - | nc <IP-OF-THE-CLIENT> 2222

Using GStreamer:

On the client

Linux

gst-launch-1.0 -v tcpclientsrc host=<IP-OF-THE-RPI> port=5000  ! gdpdepay !  rtph264depay ! avdec_h264 ! videoconvert ! autovideosink sync=false

OS X

gst-launch-1.0 -v tcpclientsrc host=<IP-OF-THE-RPI> port=5000  ! gdpdepay !  rtph264depay ! avdec_h264 ! videoconvert ! osxvideosink sync=false

On the RPi

/opt/vc/bin/raspivid -t 0 -hf -fps 20 -w 300 -h 300 -o - | gst-launch-1.0 fdsrc ! h264parse ! rtph264pay config-interval=1 pt=96 ! gdppay ! tcpserversink host=<IP-OF-THE-RPI> port=5000

Using VLC

On the client

The client might even be on a mobile phone (I tried on Android).

Simply open from the network in the VLC client:

http://<IP-OF-THE-RPI>:8090

On the RPi

/opt/vc/bin/raspivid -o - -t 0 -hf -w 640 -h 360 -fps 25|cvlc -vvv stream:///dev/stdin --sout '#standard{access=http,mux=ts,dst=:8090}' :demux=h264


  最后解决了
https://www.raspberrypi.org/forums/viewtopic.php?t=49278&p=664616
My solution to stream camera vid on RTSP:

Install GStreamer:
sudo apt-get install gstreamer-tools gstreamer0.10-plugins-base gstreamer0.10-plugins-good gstreamer0.10-plugins-bad gstreamer0.10-plugins-ugly

Make gst-rtsp:
wget  http://gstreamer.freedesktop.org/src/gs ... .8.tar.bz2
bzip2 -d gst-rtsp-0.10.8.tar.bz2
tar xvf gst-rtsp-0.10.8.tar
cd gst-rtsp-0.10.8/
./configure
make

Run gst-launch with raspivid input:
raspivid -t 0 -w 800 -h 600 -fps 25 -g 5 -b 4000000 -vf -n -o - | gst-launch -v fdsrc ! h264parse ! gdppay ! tcpserversink host=127.0.0.1 port=5000

In gst-rtsp-0.10.8/exemples run the RTSP server:
./test-launch "( tcpclientsrc host=127.0.0.1 port=5000 ! gdpdepay ! rtph264pay name=pay0 pt=96 )"

On RTSP player or on Android with RTSP Player:
rtsp://192.168.0.10:8554/test

Improvment for fixed latency and permit to lose frame on bad connection are wellcome.

开发板推荐:天空星STM32F407VET6开发板

超高性价比 STM32主控 | 超高主频 | 一板兼容百芯 | 比赛神器 | 沉金彩色丝印

从今天开始,您唯一需要的手机模型 展示设计是成功的一半。不要仅仅因为人们容易分心而浪费自己的辛苦工作。 即使您不了解3D的第一件事,也可以在一分钟内为iPhone,Android,笔记本电脑和iPad生成模型。新增:生成所有App Store图像。 随附的手机,笔记本电脑和手表模型,在任何这些设备的屏幕上查看您的应用程序设计。您可以使用屏幕截图或屏幕录像,甚至可以通过免费插件直接从Sketch和Adobe XD导入。从正面看到的iPhone X样机iPhone X和XS该样机非常详细,您可以放大并获得出色的拍摄效果。更多呈现iPhone 11 Pro样机的iPhone 11 Pro完美捕捉了背面的防雾玻璃和3个摄像头,请参见更中性的电话,看起来不像任何品牌的电话。中性电话没有缺口,没有按钮。只是一个简单而甜美的电话框架,可无限缩放查看适用于任何事物的更中性的设备样机通用此样机可适应您向其投掷的任何尺寸的视频或图像,并且仍可让您为静止图像和动画选择任何角度查看更多Samsung s9样机Android应用程序设计将完美地沿着三星精美的弧形屏幕流动。查看更多笔记本电脑模型Macbook Pro对于您的台式机网站模型,此笔记本电脑模型 具有完整的键盘-您可以调节盖子的开口!查看更多适用于平板电脑应用程序的ipad样机iPad Pro确保您在此平板电脑模型上尝试粘土模式。查看更多iphone 8实体模型iPhone 8更改此实体模型的设备颜色是强调您品牌色彩的绝好机会。查看更多Apple Watch实体模型Apple Watch所有细节,直至数字表冠上的涟漪。表带的深度很大。看更多
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值