Hardware FixRecommendedDevice not working? Your driver may be the problemCheck updates for common hardware issues.Fix DriversOctober 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
FFmpeg

How to Encode and Loop Videos for Continuous YouTube Streaming with FFmpeg

Free tools Windows power users keep installed

One-click scans. No signup required.

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 publish to the stream URL and key from YouTube Live Control Room. The command below is a starting template—not an outage-proof system: FFmpeg can repeat the input, but the computer, network, process, file, stream key, and YouTube event must all remain available.

What the setup does—and what it does not

A continuous file-based livestream has three separate jobs:

  • Loop the source: FFmpeg reads the local file repeatedly and at real-time speed.
  • Encode for ingestion: FFmpeg sends a supported video and audio stream at a suitable bitrate and keyframe interval. YouTube then transcodes the incoming live feed for viewers; you do not need to pre-create every viewer playback format.
  • Keep the publishing path healthy: The source file, FFmpeg process, computer, internet connection, stream key, and YouTube live event all need to work. Looping the file alone does not reconnect a failed process or guarantee recovery after a network or YouTube interruption.

This workflow is for streaming a prerecorded local file as a YouTube Live broadcast. It is not a camera-streaming setup.

Choose the YouTube ingest profile first

YouTube’s current encoder settings guidance lists RTMP/RTMPS, H.264, H.265/HEVC, or AV1 video, AAC or MP3 audio, and frame rates up to 60 fps. Use RTMPS when available; YouTube says it encrypts data in transit to and through Google’s servers. The settings below are YouTube recommendations, not guarantees for 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.

Video, bitrate, and keyframes

  • Bitrate mode: CBR.
  • Keyframes: A 2-second interval is recommended; do not exceed 4 seconds. The GOP length in frames must match the chosen frame rate—for example, 60 frames at 30 fps or 120 frames at 60 fps.
  • H.264 bitrate examples: YouTube lists 1080p30 at 5 Mbps minimum and 14 Mbps recommended; 1080p60 at 6 Mbps minimum and 17 Mbps recommended; and 720p30 at 3 Mbps minimum and 8 Mbps recommended.
  • H.265/AV1 comparison: For 1080p30, YouTube lists 4 Mbps minimum and 10 Mbps recommended; for 1080p60, 4 Mbps minimum and 12 Mbps recommended.

Select the bitrate for the codec, resolution, and frame rate you actually intend to send, then check that your upload connection can sustain it with headroom. Do not treat the lowest listed bitrate as the recommended target.

Audio, color, and advanced settings

  • For stereo, YouTube’s advanced recommendations include AAC or MP3, 44.1 kHz, and 128 kbps. For 5.1 over RTMP/RTMPS, YouTube supports AAC and recommends 48 kHz and 384 kbps.
  • For SDR, YouTube recommends Rec. 709 and 8-bit. For HDR, it recommends H.265; its guidance says AV1 is not supported for HDR.
  • Other advanced recommendations include square pixels, progressive scan, 2 B-frames, 1 reference frame, and CABAC. Whether and how to set these depends on the encoder and source.
  • YouTube’s 4K/2160p streams are not eligible for its low-latency optimization and are set to normal latency.

Get the stream URL and key from YouTube

  1. Open YouTube Live Control Room and create or select the live event you plan to use.
  2. Copy the stream URL and stream key shown for that event. Use the exact destination YouTube provides; do not guess or reuse a URL format from an unrelated setup.
  3. Treat the key like a password. Do not post it in public examples, screenshots, logs, or support requests. If it is exposed, reset it in the stream settings and update the FFmpeg command or service that uses it. YouTube describes the stream settings workflow in Manage live stream settings.

Build and run an FFmpeg loop command

FFmpeg options generally apply to the next input or output, so keep input options before -i and output encoding and destination options after it. The FFmpeg documentation defines -stream_loop -1 as infinite input looping and -re as reading at native frame rate. See the FFmpeg documentation for option details.

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.

Template: local MP4, H.264, 1080p30

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,fps=30" 
  -c:v libx264 -preset veryfast -b:v 14M -maxrate 14M -bufsize 28M 
  -g 60 -keyint_min 60 -sc_threshold 0 
  -c:a aac -b:a 128k -ar 44100 
  -f flv "YOUR_RTMPS_URL/YOUR_STREAM_KEY"

This example targets H.264 1080p30 at YouTube’s recommended 14 Mbps video bitrate. Replace the input path and the final destination with your file and the exact RTMPS URL/key from Live Control Room. Keep the key private. The scale-and-pad filter fits the image inside 1920×1080 without stretching it; it can add black bars if the source aspect ratio differs. The audio options are for stereo AAC. Validate the result against your installed FFmpeg build, source file, and chosen event before relying on it unattended.

Adjusting the profile

  • 1080p60 H.264: Set the filter to fps=60, use -g 120 -keyint_min 120, and choose a video bitrate appropriate to YouTube’s 1080p60 H.264 recommendation (17 Mbps) and your upload capacity.
  • 720p30 H.264: Change the scale and pad dimensions to 1280×720, retain 30 fps and a 60-frame GOP, and use a bitrate chosen for the 720p30 recommendation (8 Mbps).
  • H.265 or AV1: Use an encoder available in your FFmpeg build and confirm YouTube’s current codec-specific settings. Do not simply change the bitrate while leaving an incompatible encoder or profile.
  • HDR: Confirm the source, pixel format, bit depth, and codec are appropriate for HDR before sending; YouTube recommends H.265 and does not support AV1 for HDR.

The example uses explicit frame-rate filtering so its 60-frame GOP corresponds to two seconds. If you remove or change the frame-rate filter, recalculate the GOP length; setting -g 60 by itself does not guarantee a two-second keyframe interval.

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.

Can you stream-copy instead of re-encoding?

Possibly, if the source already has compatible codecs and its properties meet the selected YouTube ingest profile. FFmpeg’s -c copy avoids re-encoding and can reduce CPU use, but it cannot change the source resolution, frame rate, bitrate, keyframe cadence, or unsupported codec details. Check the file and YouTube requirements first; stream copy is not a safe default merely because the file plays locally.

Check upload capacity and test before going live

YouTube’s encoder guidance says, “Make sure to test before you start your live stream.” Its streaming tips say to allow approximately 20% upload headroom above total streaming bitrate. Use measured outbound upload capacity, not download speed. Shared Wi-Fi, office traffic, or other streams can reduce the bandwidth available to this encoder. If you send primary and backup streams, include both in the bandwidth calculation.

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
  1. Prepare the live event in advance and start FFmpeg early enough to inspect the incoming preview.
  2. Test a representative section with the same motion and audio characteristics as the real program. Check the Live Control Room preview, stream health, and any warnings.
  3. Confirm the broadcast appears on the intended channel/watch page and that audio and video are synchronized and intelligible.
  4. For a long-running setup, monitor both YouTube stream health and FFmpeg process/log output. If recording a local archive too, verify that the archive file continues to grow.
  5. If the production has a configured backup encoder or failover path, test it deliberately. YouTube suggests stopping the primary encoder or disconnecting its Ethernet connection to test configured failover behavior; that validates the backup setup, not automatic recovery by a single FFmpeg command.

Plan for unattended operation

-stream_loop -1 repeats the input only while FFmpeg keeps running and can read the file. A dropped connection, terminated process, full disk, changed key, or ended/misconfigured live event can still interrupt the broadcast. The FFmpeg options above do not supply a universal reconnect, restart, monitoring, or alerting policy.

  • Keep the source file at a stable path and ensure the account running FFmpeg can read it.
  • Use a stable wired connection where practical; Ethernet may avoid some Wi-Fi variability, but it does not guarantee sufficient upload capacity or an uninterrupted route.
  • For unattended use, configure a supervisor or restart policy and alerts appropriate to your operating system and deployment. Test what happens after a process exit and a network interruption rather than assuming it recovers.
  • Keep a private copy of the event’s destination details and a safe method to update them if you rotate the stream key.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Troubleshooting common failures

Symptom Likely cause What to check or do
YouTube does not show an incoming preview Wrong event URL or key, FFmpeg output error, or connection failure Confirm the selected event, copy its current URL and key again, inspect FFmpeg’s error output, and verify outbound connectivity. Do not share the key while asking for help.
Stream health warns about bitrate or unstable connection Insufficient upload headroom, competing network traffic, or an inconsistent route Measure upload bandwidth during realistic use, account for all concurrent streams, reduce the chosen output bitrate or resolution if needed, and test on the intended network.
Video is black, stretched, or the wrong size Source dimensions/aspect ratio do not match the target or the filter is unsuitable Inspect the source properties and adjust scale/pad behavior while preserving aspect ratio. Confirm the chosen output dimensions and frame rate in the preview.
Keyframes are too far apart GOP frame count does not match the output frame rate Use a GOP of 2 × the frame rate: 60 frames at 30 fps or 120 at 60 fps, and confirm the output frame rate is what you intended.
Audio is missing, distorted, or out of sync Unsupported source audio, unsuitable audio settings, or a file-specific timing issue Check the input audio stream and FFmpeg logs, use a supported AAC or MP3 output profile, and test a representative segment in the YouTube preview before the public start.
Broadcast stops when the file reaches its end Loop option is absent, misplaced, or the input is not the expected file Put -stream_loop -1 before the relevant -i, confirm the path is correct, and verify the command continues reading after one full pass.
Broadcast stops after a process or network failure Looping does not restart an exited process or restore the network Inspect the process and logs, restore the connection or event destination as needed, then restart using a tested supervisor/failover procedure. Do not assume the sample command reconnects automatically.

Copyright and channel policy still apply

Encoding a file does not grant permission to broadcast it. Use content you own or are authorized to stream, including its music and other embedded material, and check YouTube’s live-stream rules and any restrictions that apply to your channel. Repeating a video does not by itself establish that a channel complies with YouTube monetization or reused-content policies; assess the content and applicable policy separately.

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.

Or let it run in the cloud

If you want a prerecorded YouTube stream without leaving a computer and FFmpeg process running at home, StreamNeo runs uploaded videos from the cloud. Upload a recording or build a playlist, add your YouTube stream key once, and go live. It plays uploaded videos to YouTube, not a camera feed.

  • Nothing has to stay on at home for the stream to keep running.
  • Videos stream as uploaded, up to 4K 60fps, at one flat price per slot with no re-encode or quality tiers.
  • StreamNeo automatically recovers if YouTube drops the stream.
  • The first day is free with no card; one free day is available per account.
  • The monthly option is $9.99 per month.

Start your free StreamNeo day.

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.

Read next

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.