The adventures and experiences documented…

My Notes: I wanted to install and use FFMPEG in conjunction with RASPIVID on the Raspberry Pi. The goal is to stream video to my YouTube Channel which can then be used to publish video (live or recorded) to a website. I am using the official Raspberry Pi camera which plugs into the RPi Board. I decided to do this because the video quality should be much better because it is directly plugged into the bus. If you use the RPi camera, then you have to turn on the camera feature/function using “sudo raspi-config”.

About FFMPEG: FFmpeg is the leading multimedia framework, able to decode, encode, transcode, mux, demux, stream, filter and play pretty much anything that humans and machines have created. It supports the most obscure ancient formats up to the cutting edge. No matter if they were designed by some standards committee, the community or a corporation. It is also highly portable: FFmpeg compiles, runs, and passes our testing infrastructure FATE across Linux, Mac OS X, Microsoft Windows, the BSDs, Solaris, etc. under a wide variety of build environments, machine architectures, and configurations.

 

Installing H264 Support: Run the following commands one at a time. (Note, I used “sudo” command because I needed the privileges. If you have the authority, you would not need to do this.)

cd /usr/src
sudo git clone git://git.videolan.org/x264
cd x264
sudo ./configure --host=arm-unknown-linux-gnueabi --enable-static --disable-opencl
sudo make
sudo make install

 

Installing FFMPEG: Run the following commands one at a time. Please note, that the “make” and “make install” will take some time.

cd /usr/src
sudo git clone git://source.ffmpeg.org/ffmpeg.git
cd ffmpeg
sudo ./configure --arch=armel --target-os=linux --enable-gpl --enable-libx264 --enable-nonfree
sudo make
sudo make install

 

The actual Syntax to stream to my YouTube Channel: 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/StreamNameKey

Breakdown the Syntax:

  • -o - makes it write the video data to STDOUT so it gets piped into ffmpeg.
  • -t 0 is how you make it record forever
  • -vf -hf flips it horizontal and vertical so it looks correct
  • -fps 30 sets frames per second to 30
  • -b 6000000 – output bitrate limit. YouTube recommends 400-600kbps, this is 600kbps. Change this to save upload bandwidth at the expense of a lower quality video
  • -re – tells ffmpeg to slow down the reading of the input to the native frame rate of the input (useful when live streaming)
  • -ar 44100 -ac 2 -acodec pcm_s16le -f s16le -ac 2 -i /dev/zero and -acodec aac -ab 128k and -strict experimental – 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)
  • -g 50 adds a keyframe every 50 frames. Feel free to tweak, its one of those tradeoff variables.
  • -f h264 and -f flv tells ffmpeg it’s receiving h264 input and that you should mux it into flvoutput (flv is the container format that works with YouTube. Others might work but I haven’t tried them)
  • by not specifying -w and -h to raspivid we get the full 1920×1080 resolution (aka 1080p). You can specify these if you want a lower resolution

Remember – you have to be in the directory you installed ffmpeg when running the above command. In our case, we installed ffmpeg in the “/usr/src/ffmpeg” directory

 

Live Video: if the camera is on, stop by and see the live video I am streaming with this project: https://www.youtube.com/watch?v=tiUf-H5X4rw