To stream an existing video file to YouTube Live using FFmpeg, use the following command:
ffmpeg -re -i input.mp4 -c:v libx264 -preset fast -b:v 4500k -maxrate 4500k -bufsize 9000k -c:a aac -b:a 128k -f flv rtmp://a.rtmp.youtube.com/live2/YOUR_STREAM_KEY
Explanation:
-re→ Reads the input file at its natural rate (important for streaming).-i input.mp4→ Specifies the input video file.-c:v libx264→ Encodes the video using H.264.-preset fast→ Balances speed and compression.-b:v 4500k→ Sets the video bitrate to 4500 kbps.-maxrate 4500k -bufsize 9000k→ Controls the rate of encoding.-c:a aac -b:a 128k→ Encodes audio using AAC at 128 kbps.-f flv→ Outputs in FLV format (needed for RTMP streaming).rtmp://a.rtmp.youtube.com/live2/YOUR_STREAM_KEY→ The YouTube Live RTMP server URL with your stream key.
🔹 Replace YOUR_STREAM_KEY with your actual YouTube Live stream key.
🔹 Ensure your stream settings in YouTube Studio match the encoding settings in FFmpeg.
To stream an existing video file to YouTube Live in a loop, use the following FFmpeg command:
ffmpeg -re -stream_loop -1 -i input.mp4 -c:v libx264 -preset fast -b:v 4500k -maxrate 4500k -bufsize 9000k -c:a aac -b:a 128k -f flv rtmp://a.rtmp.youtube.com/live2/YOUR_STREAM_KEY
Explanation:
-stream_loop -1→ Loops the input video indefinitely.- Other settings remain the same to ensure smooth streaming.
Notes:
- This will only work with file inputs (not streams).
- If the video is short, ensure the bitrate settings match YouTube’s recommended settings to avoid buffering.
- If you want lower latency, use
-preset veryfastor-preset ultrafast, but this may reduce quality.