DriversRecommendedOutdated drivers can make a good PC feel brokenScan driver issues before chasing fixes manually.Scan NowOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsSlow PC?RecommendedPC slow today? Run a repair scan before it gets worseResolve common Windows issues and optimize system performance.Scan Now×
Skip to content
VGSources
FFmpeg

How to Encode a Video for Continuous YouTube Streaming with FFmpeg

A practical FFmpeg workflow for looping a local video into YouTube Live, with YouTube encoder settings, a command template, upload checks, and recovery limits.

By VGSources Team 9 min read
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

To loop a local video into YouTube Live with FFmpeg, read the file in real time, encode it to a YouTube-compatible profile, and send it to the stream URL and key shown in YouTube Live Control Room. The command below is a starting template—not an outage-proof service: -stream_loop -1 repeats the input, but it does not by itself recover a failed network connection, restart a crashed process, or keep a YouTube event active.

What the setup needs to do

A continuous file-based stream has three separate jobs. Keeping them distinct makes it easier to configure and troubleshoot:

  1. Read and repeat the file: FFmpeg reads the local source at its native frame rate and loops it.
  2. Encode for YouTube: FFmpeg produces video and audio in a supported format and at a suitable bitrate, frame rate, and keyframe interval.
  3. Keep the transmission healthy: the computer, source file, encoder process, upload connection, stream key, and YouTube event all need to remain available.

YouTube transcodes incoming live streams for playback, so configure the encoder for YouTube’s ingestion guidance rather than encoding separate copies for every viewer playback format. The official YouTube encoder guidance supports RTMP/RTMPS, H.264, H.265/HEVC, or AV1 video, AAC or MP3 audio, and up to 60 fps. It recommends constant bitrate (CBR) and a 2-second keyframe interval, which should not exceed 4 seconds. For transport security, use RTMPS when the event provides it.

Choose the stream profile before writing the command

Video codec and bitrate

Choose a codec your installed FFmpeg build can encode and use the YouTube bitrate row for that codec, resolution, and frame rate. The figures below are YouTube’s current encoder recommendations, not a guarantee of picture quality on every source or network.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
#1 Best Overall
Elebase USB to USB C Adapter for iPhone 18 Pro Max,USBC Car Charger Adapter
  • Read Before You Buy — No Video Output: These adapters support charging and USB 2.0 data transfer, but cannot transmit video signals. Except for standard USB webcams (which use USB data only), they are not compatible with HDMI/DisplayPort cables, video-capable USB-C hubs, or docking stations with video output.
  • Convert USB-A Ports to USB-C: Designed to connect USB-C earphones, cables, flash drives, card readers, and other USB-C accessories to standard USB-A ports. Plug-and-play with no drivers or software required.
  • Aluminum Alloy Housing: Built with a sturdy aluminum alloy shell that aids in heat dissipation and protects against daily wear and scratches. Designed to maintain a stable and secure connection.
  • Compact & Travel-Friendly: The ultra-compact design allows the adapter to stay plugged into your device without blocking adjacent ports or adding bulk, reducing wear and tear on your original USB ports.
  • 12-Month Warranty: Backed by a 12-month manufacturer warranty for peace of mind. Designed to meet strict quality control standards for reliable everyday performance.
Codec Profile Minimum video bitrate Recommended video bitrate
H.264 720p at 30 fps 3 Mbps 8 Mbps
H.264 1080p at 30 fps 5 Mbps 14 Mbps
H.264 1080p at 60 fps 6 Mbps 17 Mbps
H.265/HEVC or AV1 1080p at 30 fps 4 Mbps 10 Mbps
H.265/HEVC or AV1 1080p at 60 fps 4 Mbps 12 Mbps

These are video bitrates; include audio when estimating the total outbound stream rate. Set a rate your connection can sustain with headroom. If 14 Mbps for H.264 1080p30 is not practical on your upload connection, choose a lower resolution or a different supported profile rather than assuming a command can make an unstable connection reliable.

Frame rate, keyframes, and image format

  • Set the target frame rate explicitly so the intended keyframe interval is clear. At 30 fps, a 2-second GOP is 60 frames; at 60 fps, it is 120 frames.
  • Use a 2-second keyframe interval as the target and do not exceed 4 seconds.
  • For SDR, YouTube’s guidance specifies Rec. 709 and 8-bit video. Its advanced recommendations also include square pixels, progressive scan, 2 B-frames, 1 reference frame, and CABAC.
  • For HDR, YouTube recommends H.265; its guidance says AV1 is not supported for HDR.
  • YouTube supports up to 60 fps. Match the source and selected profile instead of asking FFmpeg to create frame rate or detail the source does not contain.

Audio

YouTube accepts AAC or MP3. For stereo audio, its advanced recommendations include 44.1 kHz and 128 kbps. For 5.1 audio over RTMP/RTMPS, AAC is supported, with 48 kHz and 384 kbps recommended. Confirm the source’s channel layout before choosing a target; the stereo settings in the example below are not a 5.1 configuration.

Rank #2
Anker USB-C Hub, 5-in-1 USB Hub for Laptops, 4K HDMI Multiport Adapter
  • 5-in-1 USB-C Hub: Experience comprehensive connectivity featuring a Power Delivery input, two USB-A 2.0 ports, a USB-A 3.0 port, and an HDMI port. (Note: The USB-C power delivery input port is only for connecting an external wall charger to power your laptop and cannot power peripheral devices.)
  • 90W Pass-Through Charging: Achieve optimal charging with 90W pass-through power to your laptop, supported by a total input of 100W, with the hub reserving 10W for operational efficiency. (Note: Wall charger not included.)
  • Quick Data Transfers: Accelerate your productivity with rapid data transfers using a high-speed 5Gbps USB 3.0 port and two 480Mbps USB 2.0 ports.
  • 4K HDMI Display: Enhance your visual experience with a hub capable of delivering 4K resolution at 30Hz in both mirror and extend modes. Please note that this hub is compatible with MacBook (macOS 12 and newer), Windows 10 and 11, ChromeOS, and laptops equipped with DP Alt Mode and Power Delivery. Note: This device is not compatible with Linux.
  • What You Get: Anker USB-C Hub (5-in-1, 4K HDMI), welcome guide, 18-month warranty, and our friendly customer service.

Get the YouTube stream URL and key

  1. In YouTube Live Control Room, create or select the live stream you intend to use.
  2. Copy the stream URL and stream key shown for that event. Use the destination YouTube provides; do not guess or reuse a URL format from an unrelated setup.
  3. Keep the key private, as you would a password. Do not paste a real key into a public post, screenshot, script example, or log shared for troubleshooting.
  4. If the key is exposed, reset it in the live stream settings and update the encoder with the replacement key.

Start the event and encoder early enough to inspect YouTube’s preview and stream health before you begin the intended broadcast. Follow the event’s controls for whether and when to start the public stream.

Run a local-file loop with FFmpeg

FFmpeg options apply to the next input or output, so keep input options such as -re and -stream_loop before -i, and output encoding options after the input and before the destination. The following is an illustrative template for a local 1080p, 30 fps H.264 source and stereo audio. Replace the filename and destination with your own, and validate the settings against your source, FFmpeg build, event, and available upload speed.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #3
Sale
Anker USB C Hub, 7in1 Multi-Port USB Adapter, 4K@60Hz USBC to HDMI Splitter
  • Sleek 7-in-1 USB-C Hub: Features an HDMI port, two USB-A 3.0 ports, and a USB-C data port, each providing 5Gbps transfer speeds. It also includes a USB-C PD input port for charging up to 100W and dual SD and TF card slots, all in a compact design.
  • Flawless 4K@60Hz Video with HDMI: Delivers exceptional clarity and smoothness with its 4K@60Hz HDMI port, making it ideal for high-definition presentations and entertainment. (Note: Only the HDMI port supports video projection; the USB-C port is for data transfer only.)
  • Double Up on Efficiency: The two USB-A 3.0 ports and a USB-C port support a fast 5Gbps data rate, significantly boosting your transfer speeds and improving productivity.
  • Fast and Reliable 85W Charging: Offers high-capacity, speedy charging for laptops up to 85W, so you spend less time tethered to an outlet and more time being productive.
  • What You Get: Anker USB-C Hub (7-in-1), welcome guide, 18-month warranty, and our friendly customer service.
ffmpeg -re -stream_loop -1 -i "input.mp4" 
  -vf "scale=1920:1080:force_original_aspect_ratio=decrease,pad=1920:1080:(ow-iw)/2:(oh-ih)/2" 
  -r 30 -c:v libx264 -preset veryfast -pix_fmt yuv420p 
  -b:v 14M -maxrate 14M -bufsize 28M 
  -g 60 -keyint_min 60 -sc_threshold 0 
  -c:a aac -b:a 128k -ar 44100 -ac 2 
  -f flv "rtmps://YOUTUBE_STREAM_URL/STREAM_KEY"

The video rate shown is YouTube’s recommended H.264 bitrate for 1080p30. It is only an appropriate choice if the source and outbound connection can sustain it. If they cannot, select a lower supported profile and its corresponding YouTube bitrate instead. The scaling filter fits the image within a 1920×1080 frame and pads unused space; check the result for letterboxing, cropping, and aspect ratio before relying on it. Remove or adjust the filter if it does not suit the source. The command assumes the local FFmpeg build includes libx264 and that the RTMPS destination syntax matches the event’s displayed URL and key.

What the input and output options do

  • -re reads the input at its native rate instead of sending a file as fast as possible.
  • -stream_loop -1 loops the input indefinitely. It does not restart FFmpeg or guarantee reconnection after a disconnect.
  • -r 30 sets a 30 fps output target; -g 60 and -keyint_min 60 set a 60-frame GOP, or 2 seconds at 30 fps. For 60 fps, the corresponding 2-second interval is 120 frames; set the output rate and GOP consistently.
  • -b:v, -maxrate, and -bufsize configure the video rate-control target, maximum rate, and buffer. The example uses CBR-style settings; test the resulting stream and confirm YouTube reports healthy ingest.
  • -c:a aac -b:a 128k -ar 44100 -ac 2 encodes stereo AAC at the recommended stereo sample rate and bitrate cited above.
  • -f flv selects the output container used for RTMP/RTMPS transmission.

Do not publish a real stream key in a command example. If you put it directly in a shell command, it may be visible in shell history or process information depending on your environment; use your operating system’s secure secret-handling practices and avoid sharing the command unredacted.

Rank #4
Sale
UGREEN USB to USB C Adapter Combo 4-Pack, 10Gbps USB C Converter Space Gray
  • Dual Converters, Infinite Potential:Includes 2× USB C male to USB A female adapters and 2× USB A male to USB C female adapters. Perfect for a wide range of uses—tablets with Bluetooth keyboards, expand USB ports on macbook, and more. Two different converters for all your daily needs
  • Next-Level 10Gbps & 3A Charging: No more slow 480Mbps, this usb to usb c adapter has a transfer speed of up to 10Gbps, allowing you to do more transferring in less time. This usb adapter fits both USB A and USB C charger, supporting up to 3A fast charging
  • Upgraded Exquisite Craftsmanship: With an aluminum alloy housing and metal connector, the usbc to usb adapter is extremely durable and sturdy. Rigorously tested to withstand more than 10,000 times of plugging and unplugging, ensuring long-lasting performance
  • Broad Compatible: The usb c to usb adapter widely supports all USB C/ USB A devices like laptops, tablets, cellphones, car chargers, and phone chargers. Such as compatible with MacBook Pro/Air 2023/2022, Thunderbolt 4/3 Devices,Apple MagSafe Watch 9/8/7/SE/Ultra, iPad Pro 2022/2021, Samsung Galaxy S23/S20/S10, and iPhone 17/16/15 Pro. Plug and play
  • Please Note: To reach 10Gbps speed, keep the cable under 3.3 ft. For USB A Male to USB C adapters, try flipping the USB C connector. USB C Male to USB A adapters support bidirectional 10Gbps transfer within 3.3 ft

When stream copy might fit

If the source already has compatible video and audio streams, -c copy can avoid re-encoding and reduce CPU use. It cannot change resolution, frame rate, bitrate, codec, or keyframe cadence. Use it only after checking that the file’s stream properties meet the selected YouTube ingest profile and that the output is accepted by the event; otherwise encode the streams instead.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Check upload capacity and test the real route

  • Measure outbound upload capacity, not download speed. YouTube recommends about 20% headroom above the total streaming bitrate. Include audio and any simultaneous primary or backup stream in the total.
  • Allow for other devices and applications sharing the connection; the bandwidth available to the encoder can fall below the connection’s nominal capacity.
  • Prefer a stable wired connection where practical, but do not treat Ethernet as a guarantee of adequate or uninterrupted upload capacity.
  • Run a representative test with motion and audio similar to the actual program. Inspect the Live Control Room preview and stream-health messages, then verify playback on the intended channel or watch page.
  • If using a configured backup encoder, test failover deliberately. YouTube suggests stopping the primary encoder or disconnecting its Ethernet to check the backup behavior. That test validates the configured arrangement; it does not mean one FFmpeg process automatically recovers.

YouTube’s guidance is direct: “Make sure to test before you start your live stream.” For continuous operation, monitor both YouTube’s stream health and FFmpeg’s process and logs. If you record a local archive as well, check that the file continues to grow. An unattended deployment also needs an operating-system-level supervisor or restart policy and alerting; the appropriate setup depends on the system, and the FFmpeg command alone does not provide a universal recovery guarantee.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Best Value
Anker USB C Hub, 5-in-1 USBC to HDMI Splitter with 4K Display
  • 5-in-1 Connectivity: Equipped with a 4K HDMI port, a 5 Gbps USB-C data port, two 5 Gbps USB-A ports, and a USB C 100W PD-IN port. Note: The USB C 100W PD-IN port supports only charging and does not support data transfer devices such as headphones or speakers.
  • Powerful Pass-Through Charging: Supports up to 85W pass-through charging so you can power up your laptop while you use the hub. Note: Pass-through charging requires a charger (not included). Note: To achieve full power for iPad, we recommend using a 45W wall charger.
  • Transfer Files in Seconds: Move files to and from your laptop at speeds of up to 5 Gbps via the USB-C and USB-A data ports. Note: The USB C 5Gbps Data port does not support video output.
  • HD Display: Connect to the HDMI port to stream or mirror content to an external monitor in resolutions of up to 4K@30Hz. Note: The USB-C ports do not support video output.
  • What You Get: Anker 332 USB-C Hub (5-in-1), welcome guide, our worry-free 18-month warranty, and friendly customer service.

Choose latency with the use case in mind

Normal, low, and ultra-low latency involve different trade-offs for audience interaction and viewing delay. Choose based on how quickly viewers need to respond, then check the event’s available options. YouTube says 4K/2160p is not eligible for its low-latency optimization and is set to normal latency.

Troubleshoot the common failure points

Symptom Likely cause What to check or change
YouTube shows no incoming video Incorrect event, stream URL, key, or RTMPS destination Compare the destination with the URL and key in the selected Live Control Room event. Check that the key has not been reset and that the event is ready to receive the encoder.
Stream health is poor or transmission drops Insufficient or fluctuating upload capacity, including shared network use Measure upload speed during realistic network use, account for the full stream bitrate, and preserve roughly 20% headroom. Test on the actual route.
FFmpeg reports an encoder or option error The installed build may not include the chosen encoder, or an option may be in the wrong position Check the build’s available encoders and FFmpeg’s error output. Keep input options before the input they affect and output options before the output destination.
Keyframes do not arrive at the intended interval The GOP frame count and output frame rate do not match Use 60 frames for 2 seconds at 30 fps or 120 frames at 60 fps, and set the frame rate explicitly.
The loop works, but the broadcast stops after a disconnect Input looping does not restart a stopped process or repair a broken network or event Check whether FFmpeg is still running, inspect its logs and YouTube’s health messages, and restore the failed dependency. Configure and test a separate supervisor or backup encoder if unattended recovery is required.
Picture is stretched, cropped, or unexpectedly bordered Source aspect ratio differs from the chosen output frame or the scaling filter does not suit the file Review the source dimensions and output preview. Adjust or remove the scale-and-pad filter to preserve the intended composition.
No audio, wrong channel layout, or poor audio level Unexpected source audio stream, channel layout, or encoding choice Inspect the input’s audio streams and choose stereo or 5.1 settings that match the source and YouTube’s supported profile.

Use video you have the right to stream

Before looping a recording, confirm that you have the necessary rights to its video and audio and that its use complies with YouTube’s rules. Encoding settings do not grant permission to broadcast copyrighted material or determine whether a channel meets YouTube’s monetization policies for reused content. A loop can also make a video repetitive to viewers; consider whether the format serves the audience and clearly describes what is playing.

Or let it run in the cloud

If the goal is an always-on YouTube channel rather than learning to operate a local FFmpeg process, StreamNeo keeps uploaded videos looping from the cloud. The three steps are: upload a recording or build a playlist, add your YouTube stream key once, and go live. Nothing has to stay running on a home computer, and the service automatically recovers if YouTube drops the stream.

Every slot streams the upload as made, at any quality up to 4K 60fps, for one flat price per slot rather than a quality tier. The first day is free with no card. The Monthly price is $9.99 per month. Each slot includes one always-on stream, 10 GB storage per slot pooled across active slots, looping and playlists, automatic recovery, and StreamNeo team support. The same product is included on every plan; only the billing length changes. You can pay for a day, week, month, 6 months, or year and cancel any time. UPI and cards are available in India; card checkout is available worldwide. For 5 or more slots, contact support.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Start your free first day on StreamNeo.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from Patch Notes

Recommended PC Tool
Recommended PC Tool
PC Slower Than It Used to Be?Free scan - under a minute
Crashes, No Sound, or Screen Glitches?Free driver scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.