FFmpeg YouTube Live stream

YouTube Live streaming is simple and stable with FFmpeg on Windows, Mac and Linux.

You can use my cross-platform Python script for YouTube FFmpeg streaming. The Python script automatically computes good YouTube Live streaming parameters based on your inputs.

Alternatively, below are commands to use FFmpeg directly from Terminal/Command Prompt.

Webcam FFmpeg YouTube Live

ffmpeg \
-f alsa -ac 1 -i hw:1,0 \
-f v4l2 -r 10 -i /dev/video0 \
-vcodec libx264 -pix_fmt yuv420p -preset ultrafast -g 20 -b:v 2500k \
-acodec libmp3lame -ar 44100 \
-threads 0 -bufsize 512k \
-f flv rtmp://a.rtmp.youtube.com/live2/YOURSTREAM &> stream.log

audio options

-f alsa -ac 1 -i hw:1,0
send mono audio stream (-ac 2 for stereo) to hardware address 1,0. For default audio device, use -f alsa -i pulse. Obtain hardware addresses via arecord -l.
-acodec libmp3lame -ar 44100
MP3 encode audio at 44.1 kHz sampling frequency (passing audio up to about 22 kHz, CD-quality).

video options

-f v4l2 -r 10 -i /dev/video0
acquire video from webcam /dev/video0 at 10 fps, using the native resolution of the webcam. Force webcam resolution like -s 640x480.
-vcodec libx264 -pix_fmt yuv420p -preset ultrafast -g 20 -b:v 2500k
encode video using the H.264 video compression algorithm, prioritizing reduced CPU utilization, in blocks of 20 frames with a target bitrate of 2.5 Mbps.

FFmpeg config

-threads 0 -bufsize 512k
let FFmpeg choose the number of CPU threads, with a 512kB buffer. Adjust buffer size as needed–tradeoff between latency and robustness.
-f flv rtmp://a.rtmp.youtube.com/live2/YOURSTREAM &> stream.log
using the FLV container format, live stream to YouTube, with stream ID YOURSTREAM. Don’t let others know the Stream ID!.

Screenshare FFmpeg YouTube Live

It’s better to run YouTube Live screenshare with my Python script so that your password doesn’t get accidentally broadcast from your screen.

Otherwise, use the same command as above, swapping -f v4l2 -r 10 -i /dev/video0 with

-f x11grab -r 10 -s 1024x720 -i :0.0+0,24

video options

-f x11grab -r 10 -s 1024x720 -i :0.0+0,24
screengrab at 10 fps, starting in the upper left hand corner, send a 1024x720 pixel video. If your screen resolution is more than 1024x720, there would be unsent regions at the bottom and/or right side.

General FFmpeg stream source

Audio-only stream source

ffmpeg -f alsa -ac 1 -i pulse -acodec aac -ar 8000 -f rtp rtp://localhost:1234

Connect from the local or remote PC to rtp:://serverip:1234.

Leave a Comment