Skip to content

ThirteeNov

My personal blog about coding and internet

Menu
  • About me
  • About Zofia Kreasi
  • Cart
  • Checkout
  • Making an airplane game from scratch in Unity
  • My account
  • Privacy Policy
  • Privacy Policy – zkLeaderboard
  • Sample Page
  • Shop
  • Tutorials on Learning JavaScript
  • ZKAccounts – Privacy Policy
Menu

How to stream a video file to YouTube using ffmpeg

Posted on March 15, 2025 by Habibie

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 veryfast or -preset ultrafast, but this may reduce quality.
Post Views: 1,216
ciihuy2020

Welcome!

  • My YouTube Channel
  • My GitHub Page
  • About me

Categories

  • 3DVista
  • Android
  • Apache
  • C#
  • Cordova
  • Electron & Node JS
  • HTML5, CSS & JavaScript
  • iOS
  • Let's Make Unity Games
  • Misc
  • Photoshop
  • PHP
  • Python
  • Uncategorized
  • Unity
  • WordPress

Recent Posts

  • Make objects like wires and cables easily in Unity using Ciihuy Curved Mesh
  • [SOLVED] Can’t Add Custom Domain to Blogger After Losing CNAME Verification
  • iOS App Icon Generator by CiihuyCom
  • Advanced Blinking Marker Script to show objects position in your game canvas
  • Ciihuy Images Merger – Fast & Easy Online Image Combiner
© 2025 ThirteeNov | Powered by Superbs Personal Blog theme