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…

1 year ago

Merrimu Reservoir drone images

Merrimu Reservoir from drone. Click images to view larger.

1 year ago

FTP getting array of file details such as size using PHP

Using FTP and PHP to get an array of file details such as size and…

2 years ago

Creating Laravel form requests

Creating and using Laravel form requests to create cleaner code, separation and reusability for your…

2 years ago

Improving the default Laravel login and register views

Improving the default Laravel login and register views in such a simple manner but making…

2 years ago

Laravel validation for checking if value exists in the database

Laravel validation for checking if a field value exists in the database. The validation rule…

2 years ago