Raspberry Pi – Live Stream to YouTube with ‚FFmpeg‘

raspberrypi_logo.jpg    By adding a camera module to your Raspberry Pi you essentially get a portable, lightweight and easy-to-hold-or-mount internet-connected camera

You’ll need the Server URL and the Stream Name/Key fields from the YouTube Live Dashboard

# apt-get update
# apt-get  dist-upgrade
cd /usr/src
# git clone git://git.videolan.org/x264
# cd x264
# ./configure –host=arm-unknown-linux-gnueabi –enable-static –disable-opencl
# make -j2
# make install
# cd /usr/src
# git clone git://source.ffmpeg.org/ffmpeg.git
# cd ffmpeg
# ./configure –arch=armel –target-os=linux –enable-gpl –enable-libx264 –enable-nonfree
# make -j2
# make install
ffmpeg -thread_queue_size 512 -f v4l2 -i /dev/video0 -ar 44100 -ac 2 -acodec pcm_s16le -f s16le -ac 2 -i /dev/zero -acodec aac -ab 128k -strict experimental -aspect 16:9 -s 640×360 -vcodec h264 -preset veryfast -crf 25 -pix_fmt yuv420p -g 60 -vb 820k -maxrate 820k -bufsize 820k -profile:v baseline -r 30 -f flv rtmp://a.rtmp.youtube.com/live2/[your-secret-key-here]
# vi /usr/src/ffmpeg/ffmpeg.sh
#!/bin/bash
while true; do
/usr/src/ffmpeg/ffmpeg -thread_queue_size 512 -f v4l2 -i /dev/video0 -ar 44100 -ac 2 -acodec pcm_s16le -f s16le -ac 2 -i /dev/zero -acodec aac -ab 128k -strict experimental -aspect 16:9 -s 640×360 -vcodec h264 -preset veryfast -crf 25 -pix_fmt yuv420p -g 60 -vb 820k -maxrate 820k -bufsize 820k -profile:v baseline -r 30 -f flv rtmp://a.rtmp.youtube.com/live2/[your-secret-key-here]
sleep 5

done
# crontab -e
@reboot /usr/bin/screen -dmS ffmpeg /usr/src/ffmpeg/ffmpeg.sh

You can find your [your-channel-id] at https://www.youtube.com/account_advanced

The Live Stream permanent URL format is

https://www.youtube.com/channel/[your-channel-id]/live

and you have to use the following URL format for the embed code

https://www.youtube.com/embed/live_stream?channel=[your-channel-id]

Leave a Reply

You must be logged in to post a comment.