I am new to the Raspberry Pi and even new to the Raspberry Pi camera. I have seen a lot of tutorials online for the Raspberry Pi camera but have yet to find on that lets me stream straight from the Raspberry Pi camera like you can with a webcam (using SimpleCV or OpenCV). Was hoping someone could point me in the right direction.
15 Answers
The solution suggested by Diego is good except that it's pretty slow and has a huge video delay since the vlc there re-streams a stream of the raspvid. Since 12/2013 there is an official v4l2 driver available: http://www.ics.com/blog/raspberry-pi-camera-module#.VJFhbyvF-b8 This renders the mentioned re-streaming obsolete. Simply load the module and use it:
sudo modprobe bcm2835-v4l2
cvlc v4l2:///dev/video0 --v4l2-width 1920 --v4l2-height 1080 --v4l2-chroma h264 --sout '#standard{access=http,mux=ts,dst=0.0.0.0:12345}'
This creates an http stream at port 12345, you can use other formats too, like the rtcp one from the Diego's answer. Read more on it here: https://wiki.videolan.org/Documentation:Streaming_HowTo/Advanced_Streaming_Using_the_Command_Line/
The easiest way I have found, to get a live videofeed from an headless raspberry pi, with a raspberry pi camera.
This solution works right out of the box, without installing additional software on the PI.
On the PI:
raspivid -t 0 -l -o tcp://0.0.0.0:3333
On the Computer, one can stream with VLC:
vlc tcp/h264://192.168.66.154:3333
(assuming 192.168.66.154 is the PI's IP address)
- 631
- 6
- 2
There are several options you can choose between. At my work we are using VLC to stream video captured by Raspberry Pi Camera from our server-rooms to the office. One downside of this is that there are about 5 seconds delay and I haven't found a solution to this. The following is our setup:
Have raspbian installed and updated and make sure your camera is enabled (you enable this by running sudo raspi-config and choose Enable Camera)
sudo apt-get update sudo apt-get upgradeInstall vlc
sudo apt-get install vlcCreate a script to start the stream with the following content, or run the command (you can't do anything else if you just run the command).
sudo nano myscript.sh raspivid -o - -t 0 -hf -w 640 -h 360 -fps 25 | cvlc -vvv stream:///dev/stdin --sout '#rtp{sdp=rtsp://:8554}' :demux=h264Make the script runable
sudo chmod +x myscript.shIf you want to start the stream automatically you have to add the script to crontab. To make this work I had to make another script runned by cron (OBS! VLC can't be run as sudo so make sure you're in the right cron).
sudo nano myscript2.sh:#!/bin/bash /path/to/myscript.shThen:
sudo chmod +x myscript2.sh crontab -e @reboot /path/to/myscript2.shTo watch the videostream, open VLC on a computer on the same network as the raspberry pi you are using for streaming. Press Media -> Open Networkstream and paste the following in the field:
rtsp://[IP].[TO].[THE].[PI]:8554/
If you don't care about FPS (frames per second) and don't want any delay you could use MJPEG. You can read more about this HERE
Watch THIS wiki about Raspberry Pi Camera Module. Hope you find what you're looking for.
- 60,325
- 17
- 117
- 234
- 1,259
- 10
- 14
I tried some options. However, I found the best result using that project: RPi-Cam-Web-Interface from eLinux community
the stream has almost zero delay.
good luck :)
- 449
- 4
- 4
I posted a possible solution in raspberry forum using a lightweight RTSP server based on live555 that is fed with a V4L2 driver supporting H264 capture :
sudo modprobe -v bcm2835-v4l2
git clone https://github.com/mpromonet/v4l2rtspserver.git
cd v4l2rtspserver
cmake .
make install
v4l2rtspserver -H <height> -W <width> -F <fps>
Next you should be able to access to the RTSP stream using :
vlc rtsp://<raspberry>:8554/unicast
- 1,124
- 1
- 19
- 38
UV4L (also) supports standard HTML5 video and audio streaming with no configuration required. Other options are possible too, like MJPEG over http.
Update:
UV4L now also supports live audio & video broadcasting to Jitsi Meet Rooms over the Web. No special configuration is required. It's as easy as filling your name, room and clicking on Start.
2nd Update:
UV4L now supports H264 hardware-encoded video too, at full fps, HD and possibly Full HD in the future.
- 276
- 3
- 4
Both mjpeg_streamer and motion seem to have better latency than cvlc.
Using mjpg_streamer
mjpeg_streamer requires compilation but the instructions on the github are straightforward.
After compilation it can be run by launching start.sh from the project dir, or by running directly (in the project dir):
# stream with default options (port=8080) (works for USB cameras too)
./mjpg_streamer -i "./input_uvc.so" -o "./output_http.so"
# set resolution to 1920x1080 and 180° rotation
./mjpg_streamer -i "./input_uvc.so -rot 180 -r 1920x1080" -o "./output_http.so -w ./www -p 8090"
where 8090 is the TCP port. If not specified, then port 8080 will be used by default. The start.sh script contains some usage examples with extra options.
If the input_uvc.so driver is not working for you or you don't want to configure the raspberry pi camera as a UVC device, then you can also try the input_raspi.so driver.
Custom config options supported by each driver:
Using motion
Motion includes a systemd service which makes it easy to autostart at boot, stop or restart.
To use it in IP webcam mode the following settings should be set in /etc/motion/motion.conf:
daemon on
stream_localhost off # when 'on' others hosts will NOT see the server
output_pictures off
ffmpeg_output_movies off
stream_maxrate 24
framerate 24
width 640
height 480
Next, in /etc/default/motion set:
start_motion_daemon=yes
To make the service autostart on boot:
systemctl enable motion
Use systemctl start/stop/restart motion for the corresponding action.
Default streaming port is 8081. The port is set under stream_port in /etc/motion/motion.conf.
- 429
- 4
- 9
Try my lightweight python solution. It uses the camera's V4L2 h264 stream, adds some (f)mp4 header and streams it over http.
- 161
- 5
I don't know if you are looking for a surveillance software, but I have succeeded in installing and running motion, a software motion detector. You should have a look in the official guide.
- 3,703
- 3
- 23
- 38
I was having trouble getting the video stream on windows 7. There were many linux solutions, not I couldn't replicate them on windows until now. I got a pretty quick solution eventually:
- get a windows version of netcat: http://joncraton.org/files/nc111nt.zip, unzip it and add to path
- get a new version of mpc-hc, which may read from stdin: https://mpc-hc.org/downloads/ install and add its path to path as well (mine is 64-bit, but 32-bit will hopefully do as well)
On raspberry pi:
raspivid -t 0 -w 1024 -h 768 -fps 20 -b 1000000 -o - | nc your.receiver.ip.address 5001
On windows machine:
nc -l -p 5001 | mpc-hc64 -
Thus, i deem, nothing gets repacked or restreamed, remuxed or what so ever. Binary stream from raspvid is feeded into mpc and shown. My raspberry operates over wifi, so at first I get a fair delay, which is in a matter of half a minute reduced to those 0.2-0.3 seconds delay.
Unfortunately, I couldn't use vlc in the same manner, as nc -l -p 5001 | vlc - just opens vlc window without any video.
- 1,124
- 1
- 19
- 38
- 111
- 1
I have installed an ONVIF solution from https://github.com/BreeeZe/rpos on my pi, following the instructions on README.md.
The only difference is that I have installed node v8.4.0. This allows me to see my camera output in a NVR connected on same network. Also, camera can be directly played through VLC player network stream using address rtsp://192.168.1.3:8554/h264
While Peter Hansen's code quite possibly works fine on a LAN, for completeness sake : TCP is about data integrity as against real-time. In a real-time stream some data loss may be acceptable for the sake of timely display. In this case UDP may be better. I haven't tested that code.
If it is a security camera, multicasting may be considered. Modern routers can do it even the $100 models.
- 1
A while a go had a similar problem came up with this:
https://www.npmjs.com/package/ws-avc-player
Its more barebone than other proposed solutions, but I think it works well if low latency over web is the priority.
Works on most browsers (even mobile at 480p) without any plugins needed on the browser.
- 101
- 1