Categories: Development

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://a.rtmp.youtube.com/live2/YOUTUBESTREAMKEY

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.

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

Share

Recent Posts

Kennington reservoir drained drone images

A drained and empty Kennington reservoir images from a drone in early July 2024. The…

2 years ago

Merrimu Reservoir drone images

Merrimu Reservoir from drone. Click images to view larger.

2 years ago

Early September spring shots

Some early September spring shots from a bushwalk, It is still too early for wildflowers.

3 years ago

Cloning an NVMe to SK Hynix Platinum P41 NVMe

I recently needed to clone over a smaller NVMe to a 2TB SK Hynix Platinum…

3 years ago

Using Laravel’s deleteDirectory to delete folders and their contents

If you ever needed a simple solution in Laravel to delete an entire directory and…

3 years ago

How to allow only 1 user to register in a Laravel application

How to enforce only one user to register or be registered in a Laravel web…

3 years ago