Difference between revisions of "Streaming Video With RaspberryPi"
(→Solution 4 : HLS + RSYNC) |
(→Solution 1 : OGG/VORBIS + Icecast) |
||
Line 47: | Line 47: | ||
http://sirlagz.net/2013/01/07/how-to-stream-a-webcam-from-the-raspberry-pi-part-3/ | http://sirlagz.net/2013/01/07/how-to-stream-a-webcam-from-the-raspberry-pi-part-3/ | ||
+ | |||
+ | '''POC''' | ||
+ | |||
+ | 1. Compile FFMPEG on pi & server | ||
+ | 2. Start capture in a screen | ||
+ | |||
+ | <code>cd /tmp/capture && rm -f ./* && /usr/local/bin/ffmpeg -f v4l2 -framerate 25 -video_size 320x240 -i /dev/video0 -f segment -segment_list out.list -segment_list_flags +live -segment_time 3 %4d.ts</code> | ||
+ | |||
+ | 3. Run rsync to server in a screen | ||
+ | |||
+ | <code> while true; do rsync -a /tmp/capture user@server:/tmp/; sleep 1; done</code> | ||
+ | |||
+ | 4. Broadcast from server to icecast | ||
+ | |||
+ | This requires | ||
+ | # a PHP streamer for your incoming files : http://pastebin.com/3f5t9vDS | ||
+ | # the oggfwd command line tool | ||
+ | |||
+ | <code > php /usr/local/bin/stream.php | ffmpeg -i - -f ogg - | oggfwd -p -n "Test" stream.server.com 8000 mySecretIceCastStreamingPassword /test </code> | ||
+ | |||
+ | <code> | ||
== Solution 2 : FLVSTR + PHP Streamer == | == Solution 2 : FLVSTR + PHP Streamer == |
Revision as of 23:50, 13 January 2015
Contents
General
Caution: this is a Work in progress, things are being tested. The objective is to provide in the end one or more working solutions for everyone.
Video streaming is a problem
The RaspberryPi camera offers an interesting solution to this problem. It is a very well integrated module of the Pi with one huge advantage: h264 encoding can be performed directly by the CPU as the camera uses the Serial Camera Interface protocol.
So theorically, solving the video problem with the Pi is easy but there are many subtle problems.
Problems
Audio As we use video webstreaming mostly for conferences broadcasting, good audio quality is necessary.
Slides It would be interesting to include slides of conferences while filming.
File It is important to have a file at the end of the filming.
Web It is important to have a large viewer base, therefore a well supported format.
Raspicam basics
http://elinux.org/Rpi_Camera_Module
raspivid is the basic command line used to capture video in h264.
raspivid -t 3 -fps 25 -b 1000k -w 1920 -h 1080 -o /tmp/video.h264
A very simple tutorial : http://www.raspberrypi-spy.co.uk/2013/05/capturing-hd-video-with-the-pi-camera-module/
Solution
Solution 1 : OGG/VORBIS + Icecast
Basic idea use the PI to capture MP4, stream it locally to a laptop. Merge audio in the laptop with ffmpeg and push the resulting ogg/vorbis stream to an icecast server.
CON Mandatory local network between pi and laptop for socket,
PRO Icecast is simple, open, and handles authentification. The file is saved on the server. Vorbis is HTML5 compatible.
Sources
http://sirlagz.net/2013/01/07/how-to-stream-a-webcam-from-the-raspberry-pi-part-3/
POC
1. Compile FFMPEG on pi & server 2. Start capture in a screen
cd /tmp/capture && rm -f ./* && /usr/local/bin/ffmpeg -f v4l2 -framerate 25 -video_size 320x240 -i /dev/video0 -f segment -segment_list out.list -segment_list_flags +live -segment_time 3 %4d.ts
3. Run rsync to server in a screen
while true; do rsync -a /tmp/capture user@server:/tmp/; sleep 1; done
4. Broadcast from server to icecast
This requires
- a PHP streamer for your incoming files : http://pastebin.com/3f5t9vDS
- the oggfwd command line tool
php /usr/local/bin/stream.php | ffmpeg -i - -f ogg - | oggfwd -p -n "Test" stream.server.com 8000 mySecretIceCastStreamingPassword /test
Solution 2 : FLVSTR + PHP Streamer
Basic idea the Octopuce company has a solution to convert live MP4 to F4V. With an USB audio card, we could mux the MP4 and AAC audio and have a standalone solution.
CON authentification is hard, F4V means Flash, requires an USB disk for local backup
PRO the pi can be autonomous
First, authentification. This problem is adressed by solving encryption as well: we use an SSL socket to communicate with the server.
Solution 3 : RTSP
Basic idea Use an RTSP stream with VLC and the V4L driver
CON Non commercial RTSP server are not the norm, requires VLC or Flash player, Quality with v4l is low
PRO Easy to work out
Sources
http://www.ics.com/blog/raspberry-pi-camera-module#.VJFhbyvF-b8
http://ffmpeg.gusari.org/viewtopic.php?f=16&t=1130
Solution 4 : HLS + RSYNC
Basic idea Use HLS segmentation and rsync
CON Not all web players can do HLS
PRO Almost out of the box, robust
Howto
1. Compile fresh ffmpeg on the pi :
sudo -s cd /usr/src git clone --depth 1 git://source.ffmpeg.org/ffmpeg.git cd ffmpeg ./configure --enable-gpl --enable-libx264 make make install
Note : compiler ffmpef sur le serveur
aptitude install libass-dev libavcodec-extra libfdk-aac-dev libmp3lame-dev libopus-dev libtheora-dev libvorbis-dev libvpx-dev pkg-config yasm ./configure --enable-gpl --enable-libass --enable-libfdk-aac --enable-libfreetype --enable-libmp3lame --enable-libopus --enable-libtheora \ --enable-libvorbis --enable-libvpx --enable-libx264 --enable-nonfree --enable-x11grab
2. Run a capture : <code>raspivid -t 0 -b 1000000 -w 1080 -h 720 -v -o - | ffmpeg -i - -f alsa -ac 1 -itsoffset 6.5 -i hw:1 -acodec aac -strict -2 -vcodec copy out.m3u8
3. Run a cron rsync to server (todo)
4. Connect a client (todo)
Sources
http://www.ffmpeg.org/ffmpeg-formats.html#hls
References
http://techzany.com/2013/09/live-streaming-video-using-avconv-and-a-raspberry-pi/
https://trac.ffmpeg.org/wiki/StreamingGuide
Node
http://phoboslab.org/log/2013/09/html5-live-video-streaming-via-websockets
https://github.com/fluent-ffmpeg/node-fluent-ffmpeg
http://ffmpeg.org/ffmpeg-all.html#segment_002c-stream_005fsegment_002c-ssegment