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?

Hi Ekaterina,

Since you want to live stream on YouTube you must have an RTMP ingest URL which looks like rtmp://{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.

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_URLYou can adjust the frame rate and video bitrate according to your requirements with -r and -b:v options.

Visit this thread if you face any problems while streaming.
Error while recording the live streaming video


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.
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