Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
ffmpeg youtube live event rtmp stream from raspberry pi with raspi camera (raspivid)
  1. compile ffmpeg for arm https://github.com/fiorix/ffmpeg-arm
  2. create youtube 'live event'. get rtmp url + session id
  3. run this:
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/<SESSION>

you can tweak -b and -fps to your liking. the settings above work well for 1080p. by not specifying width or height we get the full 1920x1080 resolution from the raspi camera

note: it might work with libav-tools instead of ffmpeg (ffmpeg isnt on apt-get in raspbian) but I haven't tested it

example video created using above method: https://www.youtube.com/watch?v=Xn4yNavjdR4&t=28m0s

@mooneyguy

This comment has been minimized.

Copy link

mooneyguy commented Jan 20, 2016

I would love to do this but don't know how to do the first part: compile ffmpeg for arm https://github.com/fiorix/ffmpeg-arm. I am a newbie to Raspberry Pi and the camera. I would like to do this but need a little more help to get started. Can you explain in detail how to compile the code? I have a Raspberry Pi 2 and Raspberry Pi Camera (B) Rev 2.0.

@fretsbiz

This comment has been minimized.

Copy link

fretsbiz commented Jan 24, 2016

Ditto here also. I'm and old ex-UNIX admin who can't stop playing with Linux. So, I've tried going the Docker route but I don't want to set up a box just to do a cross compile. The RPi2 is completely capable of compiling this code, but.......we can get a hold of the necessary resources unless we cross do containers and cross compile. Therefore, could you please steer us in the direction of where we can do this on our own little Pi's? Your YouTube kitty stream is absolutely the cat's meow...sorry about that, but it's true. Now could you please share with and guide the noobs?
Much obiged,
-b|d-

@fretsbiz

This comment has been minimized.

Copy link

fretsbiz commented Jan 24, 2016

Wow, I really butchered the English language with the above post....apologies!!!!

@mooneyguy

This comment has been minimized.

Copy link

mooneyguy commented Feb 9, 2016

I have since figured it out and posted it on the raspberry pi forum https://www.raspberrypi.org/forums/viewtopic.php?f=63&t=134141&p=893318#p893318

@phedoreanu

This comment has been minimized.

Copy link

phedoreanu commented Feb 10, 2016

@fretsbiz You don't need Docker. Compile and install ffmpeg directly on the pi:

cd /usr/src
git clone git://source.ffmpeg.org/ffmpeg.git
cd ffmpeg
./configure --enable-gpl --enable-nonfree --enable-libx264 --enable-libmp3lame
make -j$(nproc) && make install

Then run the command in step 3. Enjoy streaming!

@thebestapp

This comment has been minimized.

Copy link

thebestapp commented Aug 5, 2016

Hi, take a look at this one, live streaming for youtube - https://yatko.com/goLive

@neilzheng

This comment has been minimized.

Copy link

neilzheng commented Aug 17, 2016

Hi, lib-avtools from raspbian jessie official repo not working, from my test.
Rtmp video plays in VLC, but only the first frame(s), picture stays still.
FFmpeg works fine.

@hblanken

This comment has been minimized.

Copy link

hblanken commented Dec 10, 2016

Thank you so much @maxogden and @neilzheng. I have tried many days to get avconv to work with youtube. It streams fine from Pi3, but youtube never displays any video. It also streams well to facebook. I almost gave up. Then I read this thread, and compiled ffmpeg. Now it works flawlessly. Thanks!
ffmpeg gives me this warning - I am not sure what to do about it. Any suggestions?

[flv @ 0x1cb1370] Timestamps are unset in a packet for stream 0. This is deprecated and will stop working in the future. Fix your code to set the timestamps properly
[h264 @ 0x1b77510] Thread message queue blocking; consider raising the thread_queue_size option (current value: 8)
@o2bnmaine

This comment has been minimized.

Copy link

o2bnmaine commented Jan 28, 2017

I was able to get ffmpeg set up using http://www.jeffreythompson.org/blog/2014/11/13/installing-ffmpeg-for-raspberry-pi/. It worked pretty well, and as he points out it goes a lot faster if you use make -j4 (to use 4 cpus). Now to figure out why YouTube doesn't seem to stream very smoothly. I have -b 100000 to reduce quality and it still buffers for a very long time. I can see I'm not using 100% of my upload bandwidth, so I'm not sure what's up.

Still, this is progress!! Thanks for the help with this. I'll keep plugging away at it to see if I can get the buffering to go away.

o2bnMaine

@zomerfeld

This comment has been minimized.

Copy link

zomerfeld commented Feb 26, 2017

@o2bnmaine - I'm having the same issue. Did you find a solution?

@wassimmeziou

This comment has been minimized.

Copy link

wassimmeziou commented Apr 6, 2017

it has a late streaming for 20-30 secconds any idea !

@GSThina

This comment has been minimized.

Copy link

GSThina commented Jun 15, 2017

It's all working good. Is there any way to define a custom URL to stream? Or at least, can we get the URL of the video by code?

@ikenti

This comment has been minimized.

Copy link

ikenti commented Mar 13, 2018

Hi, it works for me but how do you had a sound recorded from a mic to the video? Thanks.

@ethaniel

This comment has been minimized.

Copy link

ethaniel commented Mar 14, 2018

Did you manage to get live true 1080p using this method?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.