[FFmpeg-user] Raspberry Pi to YouTube Live

kathodus pfribeiro at gmail.com
Sun Apr 6 22:33:32 CEST 2014

Hi Daryll,

I came across your post a few days ago while trying to do exactly the same.
I have now succeeded to live stream to Youtube and would like to share my
solution so that others do not need to spend as much time tinkering with
ffmpeg :-)

1) I disregarded Raspbian's ffmpeg version and just downloaded the source
followed by a custom compile. I used the guide in
https://trac.ffmpeg.org/wiki/UbuntuCompilationGuide and changed the script
in http://chrisandjo.com/redletter/compiling-ffmpeg/ to cope with the
appropriate packages. (Namely I was after adding support for libfdk_aac,
which in the end wasn't necessary).

2) Through numerous attempts I worked out that the bitrate sent with audio
being AAC-encoded was very low! (in fact significantly lower than what
raspivid was producing) and thus Youtube refused to take it. The trick is
with the order of the command line arguments to ffmpeg. I used the following
(where XXXXXXX is the youtube RTMP stream identifier):

raspivid -o - -t 0 -w 1280 -h 720 -fps 25 -b 600000 -g 50 | ./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

I note the following:

a) '-re' is the right enabler for getting the appropriate bitrate out of the
audio encoding. It seems the Pi can cope with AAC encoding very well. I have
obviously not tested any real audio input as I have no soundcard for it.
b) '-g 50' there is a minimum requirement for the keyframe interval of less
than or equal to 2 seconds. I have been able to work out that this
corresponds to less than or equal to 2*fps. (Note that I could not find the
unit for the -g parameter anywhere, not even for ffmpeg itself. So this is
guessing really.) See Youtube's streaming requirements

Despite Youtube's bandwidth requirements. I could easily stream
1080p at 25fps+AAC with only 600~700Kbps of bandwidth available.

c) The audio stream part of the command seems to need to come before the
video part, because of '-re'.

Hope this is useful to people looking into streaming to Youtube live with
the Pi! :-)

View this message in context: http://ffmpeg-users.933282.n4.nabble.com/Raspberry-Pi-to-YouTube-Live-tp4663435p4664673.html
Sent from the FFmpeg-users mailing list archive at Nabble.com.

More information about the ffmpeg-user mailing list