How to stream mp4 video to YouTube with FFmpeg

Here is a method to live stream a mp4 video file to YouTube with FFmpeg. There are many configuration options but here is what i found works best. Read the docs to learn more and/or understand the commands used.

My post about restreaming an m3u8 link to YouTube Live can be found here.

ffmpeg -re -i YOURVIDEO.mp4 -c:v libx264 -b:v 2M -c:a copy -strict -2 -flags +global_header -bsf:a aac_adtstoasc -bufsize 2100k -f flv rtmp://

YOURVIDEO.mp4 is the video that will be streamed, make sure you change it to your video file, including and depending on its location (/folder/anotherfolder/video.mp4 etc).

-b:v 2m is the target bitrate which is 2 Megabits (2,000 Kbps). Adjusting this will be dependent on your upload speed and the original quality of the video you are streaming.

It wont be exactly 2 Megabits all the time but will be close, this is dependent on the -bufsize. You can also set the bitrate max and min with: -maxrate and -minrate.

The lower -bufsize means your stream has potential to be dropping inbetween low and high quality every second. Setting this value at something adequate such as 2 Megabits means if networks issues occur. A good rule of thumb is to try the same of down to half of  -b:v.

Getting YouTube stream key

To get your YouTube Live stream key go to the live dashboard, at the bottom of the page in the encoder setup tab you will find it. Click reveal and put this key where it says YOUTUBESTREAMKEY in the script above.

YouTube stream key

Save the above script into a .bat file or use it in terminal and you will be streaming a mp4 video to YouTube.