How to live stream on YouTube using FFmpeg?

I want to live stream on YouTube and I have FFmpeg installed on my pc. How can I live stream using FFmpeg?

1 Like

Hi Ekaterina,

Since you want to live stream on YouTube you must have an RTMP ingest URL which looks like rtmp://a.rtmp.youtube.com/live2/{stream_key} to stream your content to YouTube.

Live streaming is usually done with RTMP (Real-Time Messaging Protocol) so your video content should be pushed in FLV format only.

You can capture the screen or provide a video file as input to FFmpeg. You can check this link for the tutorial.

https://trac.ffmpeg.org/wiki/Capture/Desktop

Or visit: How can I serve multiple audio files continuously as a live stream using FFmpeg?

  1. To create an output stream, you have to use the following FFmpeg command

ffmpeg -i input_source -deinterlace -vcodec libx264 -pix_fmt yuv420p -preset fast -r 30 -g 60 -b:v 2000k -bufsize 4000k -acodec libmp3lame -ar 44100 -b:a 712000 -f flv YouTube_RTMP_URL

You can adjust the frame rate and video bitrate according to your requirements with -r and -b:v options.

  1. Execute the above command in a terminal, if everything goes well then, you will able to see the output indicating the streaming process.

Visit this thread if you face any problems while streaming.

Error while recording the live streaming video

Thanks

I am also trying to do the same thing but am confused about how to leverage hardware video transcoding acceleration while live streaming to YouTube any suggestions?

To leverage hardware acceleration, you have to first check your hardware capabilities and then add related FFmpeg options to enable it from the following guide.
https://trac.ffmpeg.org/wiki/HWAccelIntro

For example, if you want to use NVIDIA hardware acceleration then you can consider following the FFmpeg command:

ffmpeg -hwaccel cuda -hwaccel_output_format cuda -i input_source -deinterface -vcodec h264_nvenc -pix_fmt yuv420p -preset fast -r 30 -g 60 -b:v 2000k -bufsize:v 4000k -acodec libmp3lame -ar 44100 -b:a 712000 -f flv YouTube_RTMP_URL