使用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.