create account

How I made a $50 HD Livestream Camera with a Raspberry Pi and Youtube by roelandp

View this thread on: hive.blogpeakd.comecency.com
· @roelandp · (edited)
$113.30
How I made a $50 HD Livestream Camera with a Raspberry Pi and Youtube
<b>Since I am a kitesurfing fanatic I wanted to  have a decent livestream view of one of the main 'flatwater' spots near Amsterdam, the Netherlands. It wasn't only me who wanted this, many more kiters with me were longing for this... </b>

https://s31.postimg.org/c92y3bsqz/Screen_Shot_2016_07_12_at_16_26_56.png

A camera would be a great way to make this happen, however the IP camera solutions where either quite expensive or just outputting a MJPEG stream (image stills). Another thingy was my desire to be able to view on mobile, desktop or even TV... <b>Below the current screen of the livestream, an explanation how I did it and how you can do it too!</b>

<h2>The Livestream result: </h2>Hit play to watch the livestream... Note that overnight I have programmed a filler video loop. The camera is live from around 05:00 AM CET - 22:00 PM CET. 

https://www.youtube.com/watch?v=eW8witd_DZ0
<h3>Here is how I managed to get a HD Camera Stream from Raspberry Pi to Youtube </h3><h4> What you need </h4>
* A Raspberry Pi (model 2 or higher for performance)
* A Raspberry Pi Camera Module
* Some ethernet cable
* A USB charger for your Pi
* Dummy Camera Housing to put everything in

<h4>Step 1. Install a RPI OS software image and FFMPEG</h4>1. You can go for a barebones Noobs install of Raspbian.
2. Install FFMPEG... This needs to be compiled... So it will take a shitload of time because of the RPI's processing (or lack thereof :D) power.
3. Poweroff the Raspberry Pi.
4. Remove the SD card and clone as an image so you never have to compile FFMpeg again should your SD card get's corrupted

<h4>Step 2. Connect the Camera Module</h4>
<h4>Step 3. Go to your Youtube account and setup a 'Livestream' via 'Events'</h4>Note that your Youtube Account has to be in Good Standing. You can find the Livestream tab in the <a href="https://www.youtube.com/dashboard?o=U">Dashboard</a> section. 
1. Start a new stream in the events section.. Fill out all the blanks 
2. Now you will see your stream listed
3. Go to the Ingestion Settings and update the stream rate speed your internet connection will be able to serve the video to youtube. Select for example Basic Ingestion 720P
4. Under "Copy and paste into your encoder" you will find the necessary 'Stream Name' authorization details... Copy those as we need them in the script in the next step.

<h4>Step 4. Run a commandline from your Raspberry Pi: </h4><code>raspivid -o - -t 0 -vf -hf -fps 30 -b 6000000 | ffmpeg -re -ar 44100 -ac 2 -acodec pcm_s16le -f s16le -ac 2 -i /dev/zero -f h264 -i - -vcodec copy -acodec aac -ab 128k -g 50 -strict experimental -f flv rtmp://a.rtmp.youtube.com/live2/<b>your-custom-session-here</b>
</code> ... where 'your-custom-session-here' should be the 'stream key' which you found in the previous step under 'Stream Name' .

<b>Congratulations you are now streaming to youtube in HD from your Raspberry Pi!</b>
The command above explained thanks to <a href="http://maxogden.com/hd-live-streaming-cats.html">Max Blogotronz</a>: 
<ul>
<li><code>-o -</code> makes it write the video data to STDOUT so it gets piped into <code>ffmpeg</code>. </li>
<li><code>-t 0</code> is how you make it record forever</li>
<li><code>-vf -hf</code> flips it horizontal and vertical so it looks correct</li>
<li><code>-fps 30</code> sets frames per second to 30</li>
<li><code>-b 6000000</code> - output bitrate limit. YouTube recommends 400-600kbps, this is 600kbps. Change this to save upload bandwidth at the expense of a lower quality video</li>
<li><code>-re</code> - tells ffmpeg to slow down the reading of the input to the native frame rate of the input (useful when live streaming)</li>
<li><code>-ar 44100 -ac 2 -acodec pcm_s16le -f s16le -ac 2 -i /dev/zero</code> and <code>-acodec aac -ab 128k</code> and <code>-strict experimental</code> - adds a fake audio channel filled with zeroes (silence). YouTube rejects streams without an audio channel. You can also change the input device to a microphone if you want (I haven't done this yet)</li>
<li><code>-g 50</code> adds a keyframe every 50 frames. Feel free to tweak, its one of those tradeoff variables.</li>
<li><code>-f h264</code> and <code>-f flv</code> tells ffmpeg it's receiving h264 input and that you should mux it into <code>flv</code> output (<code>flv</code> is the container format that works with YouTube. Others might work but I haven't tried them)</li>
<li>by <em>not</em> specifying <code>-w</code> and <code>-h</code> to raspivid we get the full 1920x1080 resolution (aka 1080p). You can specify these if you want a lower resolution</li>
</ul>

<h3>Optional enhancements I implemented</h3>
#### Use <code>sunwait</code> 
<code>sunwait</code> is a command line program which you can enable to execute a script to shutdown and startup the camera near Sunset and Sunrise. 
#### Add a filler video at night
I've added a filler video at night times because otherwise it would have a dark screen... Alternatively you can buy the Pi Noir Nightview Camera Module which has Infrared sighting built in so you can stream in the dark.
#### Add a reverse tunnel proxy so your camera connects to the middle man acting server and you don't have to open ports to connect to the camera from remote locations. 

<h2>Let me know if it worked out of you! </h2>
<h5>Other usefull resources</h5>
* Another tutorial about the livestreaming with Pi http://maxogden.com/hd-live-streaming-cats.html
* Reverse tunnel setup http://www.tunnelsup.com/raspberry-pi-phoning-home-using-a-reverse-remote-ssh-tunnel
* Sunwait program: http://www.risacher.org/sunwait/
* FFMPEG RPI compilation guide: https://trac.ffmpeg.org/wiki/CompilationGuide/RaspberryPi

<sup>#introduction #youtube #art #news #surf #surfin #kitesurf #kitesurfing #video #photography #video #help #tutorial #diy #rpi #raspberrypi #raspberry</sup>
👍  , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , and 32 others
properties (23)
authorroelandp
permlinkhow-i-made-a-usd50-hd-livestream-camera-with-a-raspberry-pi-and-youtube
categorylivestream
json_metadata{"tags":["help","raspberrypi","art","youtube","kitesurf","raspberry","rpi","livestream","news","diy","surf","introduction","video","surfin","kitesurfing","photography","tutorial"],"image":["https://s31.postimg.org/c92y3bsqz/Screen_Shot_2016_07_12_at_16_26_56.png"],"links":["https://www.youtube.com/watch?v=eW8witd_DZ0","https://www.youtube.com/dashboard?o=U","http://maxogden.com/hd-live-streaming-cats.html"]}
created2016-07-12 15:06:06
last_update2016-07-12 15:08:48
depth0
children5
last_payout2016-08-17 22:10:06
cashout_time1969-12-31 23:59:59
total_payout_value109.522 HBD
curator_payout_value3.780 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length5,832
author_reputation662,936,810,561,284
root_title"How I made a $50 HD Livestream Camera with a Raspberry Pi and Youtube"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id85,757
net_rshares55,141,956,609,179
author_curate_reward""
vote details (96)
@amartinezque ·
Incredible! Good work and good guide! 

Regards!
👍  
properties (23)
authoramartinezque
permlinkre-roelandp-how-i-made-a-usd50-hd-livestream-camera-with-a-raspberry-pi-and-youtube-20160712t155020393z
categorylivestream
json_metadata{"tags":["livestream"]}
created2016-07-12 15:50:21
last_update2016-07-12 15:50:21
depth1
children0
last_payout2016-08-17 22:10:06
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length48
author_reputation15,722,620,471,145
root_title"How I made a $50 HD Livestream Camera with a Raspberry Pi and Youtube"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id86,034
net_rshares235,793,084
author_curate_reward""
vote details (1)
@makgorn ·
молодец
properties (22)
authormakgorn
permlinkre-roelandp-how-i-made-a-usd50-hd-livestream-camera-with-a-raspberry-pi-and-youtube-20160716t074022093z
categorylivestream
json_metadata{"tags":["livestream"]}
created2016-07-16 07:37:45
last_update2016-07-16 07:37:45
depth1
children0
last_payout2016-08-17 22:10:06
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length7
author_reputation666,514,786,070
root_title"How I made a $50 HD Livestream Camera with a Raspberry Pi and Youtube"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id132,209
net_rshares0
@nieltoro · (edited)
Awesome!
I liked the way  you worked on it with such a low budget.
It made us to remember that it's not about spending money on something expensive to get what you want, but actually **make** things, put the brain to work and that's the awesome result we get.
Congrats! I'd love to follow your guide and see what i can get.
properties (22)
authornieltoro
permlinkre-roelandp-how-i-made-a-usd50-hd-livestream-camera-with-a-raspberry-pi-and-youtube-20160713t023513989z
categorylivestream
json_metadata{"tags":["livestream"]}
created2016-07-13 02:35:15
last_update2016-07-13 02:35:45
depth1
children0
last_payout2016-08-17 22:10:06
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length323
author_reputation0
root_title"How I made a $50 HD Livestream Camera with a Raspberry Pi and Youtube"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id90,170
net_rshares0
@scotch ·
I love the idea of bring back the webcam (not that it ever really died).  It's great that you can setup a realtime HD webcam for little money.  How easy would it be to make a nightvision (IR) version?
properties (22)
authorscotch
permlinkre-roelandp-how-i-made-a-usd50-hd-livestream-camera-with-a-raspberry-pi-and-youtube-20160712t192155006z
categorylivestream
json_metadata{"tags":["livestream"]}
created2016-07-12 19:21:54
last_update2016-07-12 19:21:54
depth1
children0
last_payout2016-08-17 22:10:06
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length200
author_reputation1,368,142
root_title"How I made a $50 HD Livestream Camera with a Raspberry Pi and Youtube"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id87,443
net_rshares0
@tbn0108 ·
good work &nice video
properties (22)
authortbn0108
permlinkre-roelandp-how-i-made-a-usd50-hd-livestream-camera-with-a-raspberry-pi-and-youtube-20160713t033219972z
categorylivestream
json_metadata{"tags":["livestream"]}
created2016-07-12 19:34:00
last_update2016-07-12 19:34:00
depth1
children0
last_payout2016-08-17 22:10:06
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length21
author_reputation0
root_title"How I made a $50 HD Livestream Camera with a Raspberry Pi and Youtube"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id87,512
net_rshares0