Installing VLC Player
sudo apt-get install vlc
Streaming The Camera Video Using RTSP
Enter the following command to start the streaming:
raspivid -o - -t 0 -n | cvlc -vvv stream:///dev/stdin --sout '#rtp{sdp=rtsp://:8554/}' :demux=h264
raspivid is used to capture the video
"-o -" causes the output to be written to stdout
"-t 0" sets the timeout to disabled
"-n" stops the video being previewed (remove if you want to see the video on the HDMI output)
cvlc is the console vlc player
"-vvv" and its argument specifies where to get the stream from
"-sout" and its argument specifies where to output it to
Options
Specifying the camera resolution
raspivid -o - -t 0 -n -w 600 -h 400 -fps 12 | cvlc -vvv stream:///dev/stdin --sout '#rtp{sdp=rtsp://:8554/}' :demux=h264
-w
Width available range: 64 to 1920
-h
Height available range: 64 to 1080
-fps
Frames per second: 2 to 30 (may change in the future)
Viewing The RTSP Stream Over The Network
You need a player which supports RTSP, for instance VLC, Quicktime, etc. Open a network stream using
rtsp://###.###.###.###:8554/
where ###.###.###.### is the IP address of the RPi.
4 years ago
It’s important to set the fps and resolution on the raspivid command, otherwise it does this 3k grainy image that takes forever for VLC to buffer on the pi.
on a pi 3 b+, I found these would prevent serious buffering issues
Also, I wanted a username and password on the stream.
Two alternate commands, one for 60fps at 1280×1024:
raspivid -o - -t 0 -n -w 1280 -h 1024 -fps 60 | cvlc -vvv stream:///dev/stdin --sout '#rtp{sdp=rtsp://:8554/}' :demux=h264 --h264-fps=60 --sout-rtsp-user username --sout-rtsp-pwd password
one for 1440×1080 at 24 fps which kinda looks the best, at least for a cat camera
raspivid -o - -t 0 -n -w 1440 -h 1080 -fps 24 | cvlc -vvv stream:///dev/stdin --sout '#rtp{sdp=rtsp://:8554/}' :demux=h264 --h264-fps=24 --sout-rtsp-user username --sout-rtsp-pwd password
4 years ago
* remove ‘-vvv’ when you’re finished set up – it just logs extra info
3 years ago
Is It possible to make it with a web cam or an USB video capturer instead of pi camera??
8 years ago
delay is quite huge.
Does anyone have any ideas to solve this problem?
8 years ago
is there anyway to use this command to save the video file at the same time as streaming it and keep it to a minute long video?
9 years ago
Hi,
Thanks for the post. In my desktop VLC I can watch the stream easily, but watching in on an android device does not work :-( Any ideas? From the developer’s debug log, the 1st error I see is the following:
E/VLC/VideoPlayerActivity(27605): Invalid surface size
Any help will be appreciated. Thanks,
9 years ago
How many simultaneous streams would be possible from the viewer side? Would it be dependent upon the pi processor or the network bandwidth?
9 years ago
is it possible to zoom during the streaming?
9 years ago
I have been trying to run this command in a Java file using Runtime.exec has anyone else tried this? I have been unsuccessful so far. I have had to call a script file using runtime.exec on java, the script file runs the raspivid stream command.
9 years ago
hi
i used your approch to stream video and thanks about your guidance.i have question where this streamed video go i mean what register and what is the number of the bit that raspberry pi can stream video.
9 years ago
is there any way to do this with a webcam
9 years ago
whats the comment for 2 cameras?
9 years ago
working for me, thank you for adding this information.
The latency is about 5-7 sec, how can we reduced? for real time video streaming.
10 years ago
Here’s the rest of what is required to get it working on VLC: http://www.wowza.com/forums/content.php?64-How-to-configure-VLC-media-player-for-RTSP-RTP-playback-(RTSP-RTP-interleaved-and-tuning)
10 years ago
This is all i’m getting nothing but errors with this Pi Junk
pi@raspberrypi ~ $ raspivid -o – -t 0 -n | cvlc -vvv stream:///dev/stdin –sout ‘#rtp{sdp=rtsp://:8554/}’ :demux=h26
mmal: mmal_vc_component_enable: failed to enable component: ENOSPC
mmal: camera component couldn’t be enabled
mmal: main: Failed to create camera component
mmal: Failed to run camera app. Please check for firmware updates
VLC media player 2.0.3 Twoflower (revision 2.0.2-93-g77aa89e)
[0x1ef68f0] main libvlc debug: VLC media player – 2.0.3 Twoflower
[0x1ef68f0] main libvlc debug: Copyright © 1996-2012 VLC authors and VideoLAN
[0x1ef68f0] main libvlc debug: revision 2.0.2-93-g77aa89e
[0x1ef68f0] main libvlc debug: configured with ./configure ‘–enable-static’ ‘–build=arm-linux-gnueabihf’ ‘CFLAGS=-g -O2 -fstack-protector –param=ssp-buffer-size=4 -Wformat -Werror=format-security’ ‘CPPFLAGS=-D_FORTIFY_SOURCE=2’ ‘CXXFLAGS=-g -O2 -fstack-protector –param=ssp-buffer-size=4 -Wformat -Werror=format-security’ ‘LDFLAGS=-Wl,-z,relro’ ‘–config-cache’ ‘–disable-maintainer-mode’ ‘–disable-silent-rules’ ‘–disable-update-check’ ‘–enable-fast-install’ ‘–prefix=/usr’ ‘–docdir=/usr/share/doc/vlc-nox’ ‘–sysconfdir=/etc’ ‘–with-binary-version=5+deb7u2’ ‘–enable-a52’ ‘–enable-aa’ ‘–enable-bluray’ ‘–enable-bonjour’ ‘–enable-caca’ ‘–enable-dbus’ ‘–enable-dca’ ‘–enable-dirac’ ‘–enable-directfb’ ‘–enable-dvbpsi’ ‘–enable-dvdnav’ ‘–enable-faad’ ‘–enable-flac’ ‘–enable-fluidsynth’ ‘–enable-freetype’ ‘–enable-fribidi’ ‘–enable-gnutls’ ‘–enable-jack’ ‘–enable-kate’ ‘–enable-libass’ ‘–enable-libmpeg2’ ‘–enable-libproxy’ ‘–enable-libxml2’ ‘–enable-lirc’ ‘–enable-live555’ ‘–enable-mad’ ‘–enable-mkv’ ‘–enable-mod’ ‘–enable-mpc’ ‘–enable-mtp’ ‘–enable-mux_ogg’ ‘–enable-ncurses’ ‘–enable-notify’ ‘–enable-ogg’ ‘–enable-oss’ ‘–enable-pulse’ ‘–enable-qt4’ ‘–enable-realrtsp’ ‘–enable-samplerate’ ‘–enable-schroedinger’ ‘–enable-sdl’ ‘–enable-shout’ ‘–enable-skins2’ ‘–enable-smb’ ‘–enable-speex’ ‘–enable-svg’ ‘–enable-taglib’ ‘–enable-theora’ ‘–enable-twolame’ ‘–enable-upnp’ ‘–enable-vcd’ ‘–enable-vcdx’ ‘–enable-vorbis’ ‘–enable-x264’ ‘–enable-zvbi’ ‘–with-kde-solid=/usr/share/kde4/apps/solid/actions/’ ‘–disable-dxva2’ ‘–disable-gnomevfs’ ‘–disable-goom’ ‘–disable-portaudio’ ‘–disable-projectm’ ‘–disable-sqlite’ ‘–disable-telx’ ‘–enable-alsa’ ‘–enable-atmo’ ‘–enable-dc1394’ ‘–enable-dv’ ‘–enable-fbosd’ ‘–enable-libva’ ‘–enable-linsys’ ‘–enable-omxil’ ‘–enable-pvr’ ‘–enable-udev’ ‘–enable-v4l2’ ‘–disable-crystalhd’ ‘–disable-mmx’ ‘–disable-sse’ ‘–disable-neon’ ‘–disable-altivec’ ‘build_alias=arm-linux-gnueabihf’
[0x1ef68f0] main libvlc debug: searching plug-in modules
[0x1ef68f0] main libvlc debug: loading plugins cache file /usr/lib/vlc/plugins/plugins.dat
[0x1ef68f0] main libvlc debug: recursively browsing `/usr/lib/vlc/plugins’
[0x1ef68f0] main libvlc debug: saving plugins cache /usr/lib/vlc/plugins/plugins.dat
[0x1ef68f0] main libvlc debug: plug-ins loaded: 410 modules
[0x1ef68f0] main libvlc debug: opening config file (/home/pi/.config/vlc/vlcrc)
[0x1ef68f0] main libvlc debug: translation test: code is “en_GB”
[0x1ef68f0] main libvlc debug: CPU has capabilities FPU
[0x1ef68f0] main libvlc debug: looking for memcpy module: 1 candidate
[0x1ef68f0] main libvlc debug: using memcpy module “memcpy”
[0x2069b50] main input debug: Creating an input for ‘Media Library’
[0x2069b50] main input debug: Input is a meta file: disabling unneeded options
[0x2069b50] main input debug: using timeshift granularity of 50 MiB, in path ‘/tmp’
[0x2069b50] main input debug: `file/xspf-open:///home/pi/.local/share/vlc/ml.xspf’ gives access `file’ demux `xspf-open’ path `/home/pi/.local/share/vlc/ml.xspf’
[0x2069b50] main input debug: creating demux: access=’file’ demux=’xspf-open’ location=’/home/pi/.local/share/vlc/ml.xspf’ file=’/home/pi/.local/share/vlc/ml.xspf’
[0x1f09ea8] main demux debug: looking for access_demux module: 3 candidates
[0x1f09ea8] main demux debug: no access_demux module matching “file” could be loaded
[0x1f09ea8] main demux debug: TIMER module_need() : 5.180 ms – Total 5.180 ms / 1 intvls (Avg 5.180 ms)
[0x2069b50] main input debug: creating access ‘file’ location=’/home/pi/.local/share/vlc/ml.xspf’, path=’/home/pi/.local/share/vlc/ml.xspf’
[0x1f8f820] main access debug: looking for access module: 2 candidates
[0x1f8f820] filesystem access debug: opening file `/home/pi/.local/share/vlc/ml.xspf’
[0x1f8f820] main access debug: using access module “filesystem”
[0x1f8f820] main access debug: TIMER module_need() : 3.819 ms – Total 3.819 ms / 1 intvls (Avg 3.819 ms)
[0x1f906b8] main stream debug: Using stream method for AStream*
[0x1f906b8] main stream debug: starting pre-buffering
[0x1f906b8] main stream debug: received first data after 0 ms
[0x1f906b8] main stream debug: pre-buffering done 296 bytes in 0s – 505 KiB/s
[0x1f8ff38] main stream debug: looking for stream_filter module: 7 candidates
[0x1f8ff38] main stream debug: no stream_filter module matching “any” could be loaded
[0x1f8ff38] main stream debug: TIMER module_need() : 4.531 ms – Total 4.531 ms / 1 intvls (Avg 4.531 ms)
[0x1f8ff38] main stream debug: looking for stream_filter module: 1 candidate
[0x1f8ff38] main stream debug: using stream_filter module “stream_filter_record”
[0x1f8ff38] main stream debug: TIMER module_need() : 1.682 ms – Total 1.682 ms / 1 intvls (Avg 1.682 ms)
[0x2069b50] main input debug: creating demux: access=’file’ demux=’xspf-open’ location=’/home/pi/.local/share/vlc/ml.xspf’ file=’/home/pi/.local/share/vlc/ml.xspf’
[0x1f904d0] main demux debug: looking for demux module: 1 candidate
[0x1f904d0] playlist demux debug: using XSPF playlist reader
[0x1f904d0] main demux debug: using demux module “playlist”
[0x1f904d0] main demux debug: TIMER module_need() : 1.129 ms – Total 1.129 ms / 1 intvls (Avg 1.129 ms)
[0x1f91040] main demux meta debug: looking for meta reader module: 2 candidates
[0x1f91040] lua demux meta debug: Trying Lua scripts in /home/pi/.local/share/vlc/lua/meta/reader
[0x1f91040] lua demux meta debug: Trying Lua scripts in /usr/lib/vlc/lua/meta/reader
[0x1f91040] lua demux meta debug: Trying Lua playlist script /usr/lib/vlc/lua/meta/reader/filename.luac
[0x1f91040] lua demux meta debug: Trying Lua scripts in /usr/share/vlc/lua/meta/reader
[0x1f91040] main demux meta debug: no meta reader module matching “any” could be loaded
[0x1f91040] main demux meta debug: TIMER module_need() : 23.430 ms – Total 23.430 ms / 1 intvls (Avg 23.430 ms)
[0x2069b50] main input debug: `file/xspf-open:///home/pi/.local/share/vlc/ml.xspf’ successfully opened
[0x1f84ee0] main xml reader debug: looking for xml reader module: 1 candidate
[0x1f84ee0] main xml reader debug: using xml reader module “xml”
[0x1f84ee0] main xml reader debug: TIMER module_need() : 8.840 ms – Total 8.840 ms / 1 intvls (Avg 8.840 ms)
[0x1f904d0] playlist demux debug: parsed 0 tracks successfully
[0x2069b50] main input debug: EOF reached
[0x1f904d0] main demux debug: removing module “playlist”
[0x1f8ff38] main stream debug: removing module “stream_filter_record”
[0x1f8f820] main access debug: removing module “filesystem”
[0x2069b50] main input debug: TIMER input launching for ‘Media Library’ : 49.830 ms – Total 49.830 ms / 1 intvls (Avg 49.830 ms)
[0x1f906b8] main interface debug: looking for interface module: 1 candidate
[0x1f906b8] main interface debug: using interface module “hotkeys”
[0x1f906b8] main interface debug: TIMER module_need() : 2.304 ms – Total 2.304 ms / 1 intvls (Avg 2.304 ms)
[0x1f09748] main interface debug: looking for interface module: 1 candidate
[0x1f09748] inhibit interface error: Failed to connect to the D-Bus session daemon: Unable to autolaunch a dbus-daemon without a $DISPLAY for X11
[0x1f09748] main interface debug: no interface module matching “inhibit,none” could be loaded
[0x1f09748] main interface debug: TIMER module_need() : 2.727 ms – Total 2.727 ms / 1 intvls (Avg 2.727 ms)
[0x1f09748] main interface error: no suitable interface module
[0x1f7e600] main playlist debug: playlist threads correctly activated
[0x1f7e600] main playlist debug: adding item `stdin’ ( stream:///dev/stdin )
[0x1f7e600] main playlist debug: rebuilding array of current – root Playlist
[0x1f7e600] main playlist debug: rebuild done – 0 items, index -1
[0x1f09748] main input debug: Creating an input for ‘stdin’
[0x74f00620] main interface debug: looking for interface module: 1 candidate
[0x1f7e600] main playlist debug: meta ok for (null), need to fetch art
[0x1f904a0] main demux meta debug: looking for meta fetcher module: 1 candidate
[0x1f904a0] lua demux meta debug: Trying Lua scripts in /home/pi/.local/share/vlc/lua/meta/fetcher
[0x74f00620] main interface debug: no interface module matching “globalhotkeys,none” could be loaded
[0x1f904a0] lua demux meta debug: Trying Lua scripts in /usr/lib/vlc/lua/meta/fetcher
[0x74f00620] main interface debug: TIMER module_need() : 2.072 ms – Total 2.072 ms / 1 intvls (Avg 2.072 ms)
[0x74f00620] main interface error: no suitable interface module
[0x1ef68f0] main libvlc error: interface “globalhotkeys,none” initialization failed
[0x1f09588] main interface debug: looking for interface module: 1 candidate
[0x1f09588] dummy interface: using the dummy interface module…
[0x1f09588] main interface debug: using interface module “dummy”
[0x1f09588] main interface debug: TIMER module_need() : 1.168 ms – Total 1.168 ms / 1 intvls (Avg 1.168 ms)
[0x1f7e600] main playlist debug: processing request item: null, node: Playlist, skip: 0
[0x1f7e600] main playlist debug: rebuilding array of current – root Playlist
[0x1f7e600] main playlist debug: rebuild done – 1 items, index -1
[0x1f7e600] main playlist debug: starting playback of the new playlist item
[0x1f7e600] main playlist debug: resyncing on stdin
[0x1f7e600] main playlist debug: stdin is at 0
[0x1f7e600] main playlist debug: creating new input thread
[0x1f84d80] main input debug: Creating an input for ‘stdin’
[0x1f84238] main stream output debug: using sout chain=`rtp{sdp=rtsp://:8554/}’
[0x1f84238] main stream output debug: stream=`rtp’
[0x1f84408] main stream out debug: looking for sout stream module: 1 candidate
[0x1f84408] main stream out debug: set config option: sout-rtp-sdp to rtsp://:8554/
[0x1f904a0] lua demux meta debug: Trying Lua playlist script /usr/lib/vlc/lua/meta/fetcher/tvrage.luac
[0x1f84408] stream_out_rtp stream out debug: RTSP stream at /
[0x1f84408] main stream out debug: net: listening to * port 8554
[0x1f904a0] main demux meta debug: using meta fetcher module “lua”
[0x1f904a0] main demux meta debug: TIMER module_need() : 9.767 ms – Total 9.767 ms / 1 intvls (Avg 9.767 ms)
[0x1f904a0] main demux meta debug: removing module “lua”
[0x1f7e600] main playlist debug: searching art for stdin
[0x1f86bc0] main art finder debug: looking for art finder module: 2 candidates
[0x1f86bc0] lua art finder debug: Trying Lua scripts in /home/pi/.local/share/vlc/lua/meta/art
[0x1f86bc0] lua art finder debug: Trying Lua scripts in /usr/lib/vlc/lua/meta/art
[0x1f86bc0] lua art finder debug: Trying Lua playlist script /usr/lib/vlc/lua/meta/art/00_musicbrainz.luac
[0x1f86bc0] lua art finder debug: Trying Lua playlist script /usr/lib/vlc/lua/meta/art/01_googleimage.luac
[0x1f86bc0] lua art finder debug: Trying Lua playlist script /usr/lib/vlc/lua/meta/art/02_frenchtv.luac
[0x1f86bc0] lua art finder debug: Trying Lua playlist script /usr/lib/vlc/lua/meta/art/03_lastfm.luac
[0x1f84408] main stream out debug: socket error: Address family not supported by protocol
[0x1f84408] main stream out debug: using sout stream module “stream_out_rtp”
[0x1f84408] main stream out debug: TIMER module_need() : 18.654 ms – Total 18.654 ms / 1 intvls (Avg 18.654 ms)
[0x1f84d80] main input debug: using timeshift granularity of 50 MiB, in path ‘/tmp’
[0x1f84d80] main input debug: `stream:///dev/stdin’ gives access `stream’ demux `’ path `/dev/stdin’
[0x1f84d80] main input debug: enforced demux ` h26′
[0x1f84d80] main input debug: creating demux: access=’stream’ demux=’h26′ location=’/dev/stdin’ file=’/dev/stdin’
[0x1f187d0] main demux debug: looking for access_demux module: 0 candidates
[0x1f187d0] main demux debug: no access_demux module matched “stream”
[0x1f187d0] main demux debug: TIMER module_need() : 0.391 ms – Total 0.391 ms / 1 intvls (Avg 0.391 ms)
[0x1f84d80] main input debug: creating access ‘stream’ location=’/dev/stdin’, path=’/dev/stdin’
[0x1f8a220] main access debug: looking for access module: 1 candidate
[0x1f8a220] filesystem access debug: opening file `/dev/stdin’
[0x1f86bc0] lua art finder debug: Trying Lua scripts in /usr/share/vlc/lua/meta/art
[0x1f86bc0] main art finder debug: no art finder module matching “any” could be loaded
[0x1f86bc0] main art finder debug: TIMER module_need() : 14.609 ms – Total 14.609 ms / 1 intvls (Avg 14.609 ms)
[0x1f8a220] main access debug: using access module “filesystem”
[0x1f7e600] main playlist debug: art not found for stdin
[0x1f8a220] main access debug: TIMER module_need() : 0.868 ms – Total 0.868 ms / 1 intvls (Avg 0.868 ms)
[0x1f8b7a8] main stream debug: Using stream method for AStream*
[0x1f8b7a8] main stream debug: starting pre-buffering
[0x1f8b7a8] main stream error: cannot pre fill buffer
[0x1f84d80] main input warning: cannot create a stream_t from access
[0x1f8a220] main access debug: removing module “filesystem”
[0x1f7e600] main playlist debug: dead input
[0x1f84238] main stream output debug: destroying useless sout
[0x1f84408] main stream out debug: destroying chain… (name=rtp)
[0x1f84408] main stream out debug: removing module “stream_out_rtp”
[0x1f8c200] main http host debug: waitpipe: object killed
[0x1f8c200] main http host debug: HTTP host removed
[0x1f84408] main stream out debug: destroying chain done
[0x1f84d80] main input debug: TIMER input launching for ‘stdin’ : 23.902 ms – Total 23.902 ms / 1 intvls (Avg 23.902 ms)
[0x1f7e600] main playlist debug: changing item without a request (current 0/1)
[0x1f7e600] main playlist debug: nothing to play
10 years ago
Can’t we stream from web browser by using this method?
10 years ago
Can´t play videos and can´t stream…
is there a solution to this??
Best regards,
10 years ago
Le streaming vidéo avec le Pi reste un sujet à peaufiner à mon avis.
Parmis toutes les méthodes possibles http://www.magdiblog.fr/divers/raspberry-pi-camera-5-facons-de-faire-du-streaming/, je pense que mjpg-streamer est la meilleure solution.
10 years ago
Is it possible to password protect the stream?
10 years ago
I’ve been having the same problems you did. How did you use OpenCV to resolve them?
10 years ago
As far as I can tell, these instructions are obsolete. I’m having much more success with the (new?) v4l2 kernel driver for the camera. Run `sudo modprobe bcm2835-v4l2`, then any vlc command such as `cvlc v4l2:///dev/video0 –v4l2-width 1920 –v4l2-height 1080 –v4l2-chroma h264 –sout ‘#rtp{sdp=rtsp://:8554/}’`.
8 years ago
This doesn’t work any more (if it ever did), as of raspbian-jessie of 9/2016 with vlc 2.2.1
10 years ago
Is any of this a seriously laughable or is it just me? Piping to another streamer just because of the crazy design on how raspivid pulls the data via i2c??
Please where is a workable solution using mjpgstreamer?
10 years ago
You neglected to say that using RTSP in VLC makes it virtually impossible to access the video from the Internet because VLC opens two ports for each connection request, and chooses them randomly. So forget about mapping them through your router.
Because of that, my real interest has become using http instead of rtsp, with a single port, but none of the http commands for cvlc work for me. VLC Media Player connects but the video is just gray with a few blobs. Everything is the latest version. Has anyone had the same problem ?
8 years ago
Lots of cameras use RTSP behind NAT boxes.
4 years ago
i tried to set up my pi as a streaming device but i’m getting the following error:
ES_OUT_SET_(GROUP_)PCR is called to late(pts delay increased to 476ms
ES_OUT_RESET_PCR called
does anyone know how to fix this?
3 years ago
Yes after :demux=h264 you have to write –h264-fps=15
:demux=h264 –h264-fps=15
4 years ago
Was able to capture some frames, though there were long spells of buffering at times, counting all the way up to 100%, with output such as;
…
[0x619be0] main input debug: Buffering 91%
…
[0x92add8] main input debug: Stream buffering done (3240 ms in 40357 ms)
[0x92add8] main input debug: Decoder buffering done in 0 ms
[0x92add8] main input error: ES_OUT_SET_(GROUP_)PCR is called too late (jitter of 36359 ms ignored)
and,
[0x92add8] main input error: ES_OUT_RESET_PCR called
[0x92add8] main input debug: Buffering 0%
[0x92add8] main input debug: Buffering 1%
And this may have something to do with it;
[0x1bcd350] main input error: Invalid PCR value in ES_OUT_SET_(GROUP_)PCR !
UPDATE:
I’ve been tweaking the resolution and framerate, and it now works fairly well with my OpenCV app that pulls and evaluates frames. I’ve settled in around 640×480 at 15fps and it’s been stable for about 12 hours now, will continue to monitor and report back. Even though I’ve set it to 15pfs, the stream information reports a frame rate of 9000 fps, so I’ve adjusted my app to recognize this condition and readjust.
I’m getting a very short delay (less than 1 sec), though oddly enough when I also monitor this stream with VLC, the VLC delays slowly grow (more than 10 secs after a while).
4 years ago
Thanks, the method works fine although I am getting about a 40 second delay. Is this normal ?