{"id":255,"date":"2017-04-18T23:10:19","date_gmt":"2017-04-19T03:10:19","guid":{"rendered":"http:\/\/teakdata.com\/blog\/?p=255"},"modified":"2019-06-17T08:43:54","modified_gmt":"2019-06-17T12:43:54","slug":"youtube-live-streaming-device-using-raspberry-pi","status":"publish","type":"post","link":"https:\/\/teakdata.com\/blog\/youtube-live-streaming-device-using-raspberry-pi\/","title":{"rendered":"Youtube Live Streaming device using Raspberry Pi"},"content":{"rendered":"<p>This post shows how to create a\u00a0Youtube Live Streaming device using Raspberry Pi.<\/p>\n<p>Recently we have bought a fish tank with two goldfish and we were thinking about\u00a0integrating technology into this context.<\/p>\n<p>Our first project is a Live streaming device using Raspbery Pi that will be able to stream live video from the aquarium.<\/p>\n<div id=\"attachment_257\" style=\"width: 310px\" class=\"wp-caption alignnone\"><a href=\"http:\/\/teakdata.com\/blog\/wp-content\/uploads\/2017\/04\/IMG_4464-Edit.jpg\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-257\" class=\"wp-image-257 size-medium\" src=\"http:\/\/teakdata.com\/blog\/wp-content\/uploads\/2017\/04\/IMG_4464-Edit-300x280.jpg\" alt=\"Youtube Live Streaming device using Raspberry Pi 1\" width=\"300\" height=\"280\" srcset=\"https:\/\/teakdata.com\/blog\/wp-content\/uploads\/2017\/04\/IMG_4464-Edit-300x280.jpg 300w, https:\/\/teakdata.com\/blog\/wp-content\/uploads\/2017\/04\/IMG_4464-Edit-768x717.jpg 768w, https:\/\/teakdata.com\/blog\/wp-content\/uploads\/2017\/04\/IMG_4464-Edit-1024x956.jpg 1024w, https:\/\/teakdata.com\/blog\/wp-content\/uploads\/2017\/04\/IMG_4464-Edit.jpg 1200w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><p id=\"caption-attachment-257\" class=\"wp-caption-text\">Youtube Live Streaming Raspberry Pi Fish Tank 1<\/p><\/div>\n<h2>Prerequisites<\/h2>\n<p>In order to do Youtube Live Streaming you will need:<\/p>\n<ul>\n<li>Youtube account that has live streaming (<a href=\"https:\/\/support.google.com\/youtube\/answer\/2474026?hl=en\">https:\/\/support.google.com\/youtube\/answer\/2474026?hl=en<\/a><\/li>\n<li>Raspberry Pi (version 3 used in this project)\u00a0<a href=\"https:\/\/www.raspberrypi.org\/products\/raspberry-pi-3-model-b\/\">https:\/\/www.raspberrypi.org\/products\/raspberry-pi-3-model-b\/<\/a><\/li>\n<li>Raspberry Pi Camera (PiCam Noir used in this project) \u00a0<a href=\"https:\/\/www.raspberrypi.org\/products\/pi-noir-camera\/\">https:\/\/www.raspberrypi.org\/products\/pi-noir-camera\/<\/a><\/li>\n<li>In case you have a Raspberry Pi version lower than 3 that does not have a wifi chip &#8211; you also need a wifi dongle or use a ethernet cable for networking<\/li>\n<li>Optional &#8211; cardboard box, tape, battery<\/li>\n<\/ul>\n<h2>Hardware<\/h2>\n<p>As a Raspberry Pi case we have used a cardboard box (the box received with several products shipped by Adafruit)<\/p>\n<p>With a cutter knife created the openings for connectors (usb, power, network, hdmi) and fixed the Raspberry Pi board inside with folded paper).<\/p>\n<p>Connected the Pi Camera, wrapped the connector outside the box and taped the camera on the box.<\/p>\n<div id=\"attachment_259\" style=\"width: 235px\" class=\"wp-caption alignnone\"><a href=\"http:\/\/teakdata.com\/blog\/wp-content\/uploads\/2017\/04\/IMG_4466-Edit.jpg\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-259\" class=\"size-medium wp-image-259\" src=\"http:\/\/teakdata.com\/blog\/wp-content\/uploads\/2017\/04\/IMG_4466-Edit-225x300.jpg\" alt=\"Youtube Live Streaming device using Raspberry Pi\" width=\"225\" height=\"300\" srcset=\"https:\/\/teakdata.com\/blog\/wp-content\/uploads\/2017\/04\/IMG_4466-Edit-225x300.jpg 225w, https:\/\/teakdata.com\/blog\/wp-content\/uploads\/2017\/04\/IMG_4466-Edit-768x1024.jpg 768w, https:\/\/teakdata.com\/blog\/wp-content\/uploads\/2017\/04\/IMG_4466-Edit.jpg 900w\" sizes=\"auto, (max-width: 225px) 100vw, 225px\" \/><\/a><p id=\"caption-attachment-259\" class=\"wp-caption-text\">Youtube Live Streaming device using Raspberry Pi<\/p><\/div>\n<h2>Software Installation<\/h2>\n<p>This part requires more effort and we have spent some time trying to use the default software installed on raspbian linux.<\/p>\n<p>Alternatively you can try this <a href=\"http:\/\/www.makeuseof.com\/tag\/live-stream-youtube-raspberry-pi\/\">article<\/a> that describes the use of raspivid tool to stream, in our case, using raspivid did not work and we have tried the ffmpeg tool.<\/p>\n<p>Let&#8217;s proceed with the installation:<\/p>\n<ol>\n<li>If not enabled already, enable the camera using the raspi-config command<\/li>\n<li>Install the default video tools<\/li>\n<\/ol>\n<pre class=\" language-bash\"><code class=\" language-bash\"><span class=\"token function\">sudo<\/span> <span class=\"token function\">apt-get<\/span> <span class=\"token function\">install<\/span> libav-tools<\/code><\/pre>\n<p>3. Try the camera with the following command and check the file image.jpg on home folder<\/p>\n<pre class=\" language-bash\"><code class=\" language-bash\">raspistill \u2013o image.jpg<\/code><\/pre>\n<p>4. Install video tools (ffmpeg) &#8211; used this article as reference:\u00a0<a href=\"https:\/\/www.jeffreythompson.org\/blog\/2014\/11\/13\/installing-ffmpeg-for-raspberry-pi\/\">https:\/\/www.jeffreythompson.org\/blog\/2014\/11\/13\/installing-ffmpeg-for-raspberry-pi\/<\/a><\/p>\n<ol>\n<li>\n<pre class=\" language-bash\">cd \/usr\/src<\/pre>\n<\/li>\n<li>\n<pre class=\" language-bash\">git clone git:\/\/git.videolan.org\/x264\n<\/pre>\n<\/li>\n<li>\n<pre class=\" language-bash\">cd x264\n<\/pre>\n<\/li>\n<li>\n<pre class=\" language-bash\">.\/configure --host=arm-unknown-linux-gnueabi --enable-static --disable-opencl\n<\/pre>\n<\/li>\n<li>\n<pre class=\" language-bash\">make<\/pre>\n<\/li>\n<li>\n<pre class=\" language-bash\">sudo make install\n<\/pre>\n<\/li>\n<li>\n<pre class=\" language-bash\">cd \/usr\/src<\/pre>\n<pre class=\" language-bash\">git clone https:\/\/github.com\/FFmpeg\/FFmpeg.git<\/pre>\n<\/li>\n<li>\n<pre class=\" language-bash\">cd ffmpeg<\/pre>\n<\/li>\n<li>\n<pre class=\" language-bash\">sudo .\/configure --arch=armel --target-os=linux --enable-gpl --enable-libx264 --enable-nonfree\n[if receive Error libx264 not found\ninstall:\nsudo apt-get install yasm libvpx. libx264.]<\/pre>\n<\/li>\n<li>\n<pre class=\" language-bash\">make<\/pre>\n<\/li>\n<li>\n<pre class=\" language-bash\">sudo make install<\/pre>\n<\/li>\n<\/ol>\n<p>If no errors during installation, you can test ffmpeg running the ffmpeg command.<\/p>\n<p>5. Install sox to create loop background sound (optional)<\/p>\n<pre class=\" language-bash\">sudo apt install sox\nsudo apt-get install libsox-fmt-mp3<\/pre>\n<p>6. \u00a0Create loop audio for background sound (optional)<\/p>\n<pre class=\" language-bash\"># download mp3 sample and create loop\n# save the file (as example sample.mp3), create loop_sound.mp3 using sox\nsox sound.mp3 loop_sound.mp3 repeat 1000<\/pre>\n<h2>Running<\/h2>\n<p>replace the YOUR_KEY tag with your youtube secret key provided by youtube.<\/p>\n<pre>raspivid -rot 90 -o - -t 0 -vf -hf -fps 30 -b 6000000 | ffmpeg -i loop_sound.mp3 \u00a0-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 -shortest -f flv rtmp:\/\/a.rtmp.youtube.com\/live2\/YOUR_KEY<\/pre>\n<p>In order to run the command in background you can create a shell file with the command above (e.g stream.sh, be sure give run permissions &#8220;chmod a+x stream.sh&#8221;) and run<\/p>\n<pre>nohup .\/stream.sh &amp;<\/pre>\n<div id=\"attachment_263\" style=\"width: 310px\" class=\"wp-caption alignnone\"><a href=\"http:\/\/teakdata.com\/blog\/wp-content\/uploads\/2017\/04\/IMG_4465-Edit.jpg\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-263\" class=\"size-medium wp-image-263\" src=\"http:\/\/teakdata.com\/blog\/wp-content\/uploads\/2017\/04\/IMG_4465-Edit-300x247.jpg\" alt=\"Youtube Live Streaming using Raspbery Pi\" width=\"300\" height=\"247\" srcset=\"https:\/\/teakdata.com\/blog\/wp-content\/uploads\/2017\/04\/IMG_4465-Edit-300x247.jpg 300w, https:\/\/teakdata.com\/blog\/wp-content\/uploads\/2017\/04\/IMG_4465-Edit-768x631.jpg 768w, https:\/\/teakdata.com\/blog\/wp-content\/uploads\/2017\/04\/IMG_4465-Edit-1024x841.jpg 1024w, https:\/\/teakdata.com\/blog\/wp-content\/uploads\/2017\/04\/IMG_4465-Edit.jpg 1200w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><p id=\"caption-attachment-263\" class=\"wp-caption-text\">Youtube Live Streaming using Raspbery Pi<\/p><\/div>\n<div style=\"width: 640px;\" class=\"wp-video\"><video class=\"wp-video-shortcode\" id=\"video-255-1\" width=\"640\" height=\"360\" preload=\"metadata\" controls=\"controls\"><source type=\"video\/mp4\" src=\"http:\/\/teakdata.com\/blog\/Fishtank%20Live%20Stream.mp4?_=1\" \/><a href=\"http:\/\/teakdata.com\/blog\/Fishtank%20Live%20Stream.mp4\">http:\/\/teakdata.com\/blog\/Fishtank%20Live%20Stream.mp4<\/a><\/video><\/div>\n<p>A full list of commands used in this article can be found on this git repository:\u00a0<a href=\"https:\/\/github.com\/smarcu\/youtube-live-streaming-raspberry-pi\">https:\/\/github.com\/smarcu\/youtube-live-streaming-raspberry-pi<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>This post shows how to create a\u00a0Youtube Live Streaming device using Raspberry Pi. Recently we have bought a fish tank with two goldfish and we were thinking about\u00a0integrating technology into this context. Our first&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":257,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2,11,12,10],"tags":[16,3,15,17],"class_list":["post-255","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-daniel-dad-laboratories","category-education","category-linux","category-raspberrypi","tag-live","tag-raspberry-pi","tag-streaming","tag-youtube"],"_links":{"self":[{"href":"https:\/\/teakdata.com\/blog\/wp-json\/wp\/v2\/posts\/255","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/teakdata.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/teakdata.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/teakdata.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/teakdata.com\/blog\/wp-json\/wp\/v2\/comments?post=255"}],"version-history":[{"count":11,"href":"https:\/\/teakdata.com\/blog\/wp-json\/wp\/v2\/posts\/255\/revisions"}],"predecessor-version":[{"id":564,"href":"https:\/\/teakdata.com\/blog\/wp-json\/wp\/v2\/posts\/255\/revisions\/564"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/teakdata.com\/blog\/wp-json\/wp\/v2\/media\/257"}],"wp:attachment":[{"href":"https:\/\/teakdata.com\/blog\/wp-json\/wp\/v2\/media?parent=255"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/teakdata.com\/blog\/wp-json\/wp\/v2\/categories?post=255"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/teakdata.com\/blog\/wp-json\/wp\/v2\/tags?post=255"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}