[FFmpeg-user] Raspberry Pi to YouTube Live

Daryll Strauss daryll.strauss at gmail.com
Sun Jan 26 23:51:45 CET 2014


I've got this idea of using a raspberry pi as a cheap camera system to 
stream live events. You can get a board with a camera for $60, and 
$under $100 all in with Wifi, case, compact flash, power, etc.

Streaming to YouTube works with the following command on my laptop:

ffmpeg -f alsa -ar 44100 -b:a 128k -i pulse -f v4l2 -i /dev/video0 
-codec:v libx264 -s 1280x720 -r 30 -profile:v main -b:v 3000k -f flv 
-codec:a aac -strict experimental rtmp://a.rtmp.youtube.com/live2/STREAM

You can tweak the parameters from there to go higher or lower resolution.

That won't work for the Pi, because it doesn't have the horsepower to 
encode the video, (and they don't have audio in, but that's a different 
problem). They do have a dedicated video processor that can output h264, 
so if I can feed that to ffmpeg, then I might be able to get somewhere. 
That lead me to something like this:

raspivid -t 999999 -w 1280 -h 720 -fps 30 -b 3000000 -pf main -g 30 -o - 
-ih -qp 10 -n | avconv -re -f h264 -i - -b:a 128k -f s16le -ar 44100 -ac 
2 -i /dev/zero -f flv -codec:v copy -codec:a aac -strict experimental 
out.flv

The rapivid parameters are specifying 999999 seconds of 1280x720 video 
at 30fps with a 3Mb/s bitrate, main h264 profile, 30 frame GOP, output 
to std out, include headers (SPS, PPS which seemed like it might be 
useful), and quantization level 10 (which is fairly high quality).

It spits out lines like:

frame=  191 fps= 95 q=-1.0 size=       0kB time=10000000000.00 
bitrate=   0.0kbit
frame=  206 fps= 82 q=-1.0 size=       0kB time=10000000000.00 
bitrate=   0.0kbit
...
frame= 2845 fps= 31 q=-1.0 size=   34789kB time=0.02 
bitrate=12390920.3kbits/s

That's quite odd, because the time is always 0.02 and the bitrate is 
wrong. Something gets written to out.flv, but if I ffprobe out.flv I see:

Input #0, flv, from '/tmp/out.flv':
   Metadata:
     encoder         : Lavf53.21.1
   Duration: 00:00:00.04, start: 0.000000, bitrate: 200 kb/s
     Stream #0.0: Video: h264 (Main), yuv420p, 1280x720, 1k tbr, 1k tbn, 
2k tbc
     Stream #0.1: Audio: aac, 44100 Hz, 2 channels, 200 kb/s

Clearly that's not right and doesn't play. The total bitrate is just the 
audio. The tbr, and tbc are wrong. I should be seeing something like this:

Input #0, flv, from '/usr/tmp/good.flv':
   Metadata:
     encoder         : Lavf54.63.104
   Duration: 00:00:11.65, start: 0.044000, bitrate: 3058 kb/s
     Stream #0:0: Video: h264 (Main), yuv420p, 1280x720, 3000 kb/s, 30 
tbr, 1k tbn, 60 tbc
     Stream #0:1: Audio: aac, 44100 Hz, stereo, fltp, 128 kb/s

It seems like the copy is sort of working, but the timing information 
isn't getting passed through. I'd tried a variety of options to get this 
working, but I'm stumped.

Anyone have a suggestion for me?




More information about the ffmpeg-user mailing list