You can loop a local video into YouTube Live with FFmpeg and a small Linux shell script. Get the event’s server URL and stream key from YouTube Live Control Room, then send the file as a real-time RTMPS stream. The command below is a starting point: test it with your own FFmpeg build and event settings before relying on it for a long broadcast.
Before you start
- Your YouTube channel must be verified, have no live-streaming restrictions in the previous 90 days, and meet YouTube’s minimum livestreaming age of 16. See YouTube’s live-streaming eligibility guidance.
- A Linux computer or server with FFmpeg installed, a local video file, and a stable upload connection.
- A stream created or selected in YouTube Studio’s Live Control Room, where you can copy its server URL and stream key. YouTube recommends RTMPS for encoder connections. See Create a YouTube live stream with an encoder.
Set up the YouTube event and protect its key
- In YouTube Studio, open Live Control Room and create or select the stream you intend to use.
- Copy the server URL and stream key shown for that stream. Confirm the selected event’s settings and URL format; do not assume every account or ingest endpoint uses the same URL structure.
- Keep the key out of the script file, shell history, and source control. YouTube Help describes stream keys as “your YouTube stream’s password and address.” If a key is exposed, reset it in the stream settings and update your encoder. See Manage live stream settings.
Install FFmpeg and check your build
Install FFmpeg from a trusted source for your Linux distribution, then check that it runs and which encoders are available:
ffmpeg -version
ffmpeg -encoders | grep -E 'libx264| aac'
Builds differ: the example below uses libx264, so it will fail if your FFmpeg build does not include that encoder. Install or choose a build with a suitable H.264 encoder and AAC support, or adjust the command to match the encoders you have. FFmpeg’s online documentation defines -stream_loop -1 for infinite input looping and -re for reading at native media rate: FFmpeg Documentation.
Create a looping shell script
Save this as youtube-loop.sh. It expects the YouTube server URL and key through environment variables rather than embedding them in the file:
The Tool Desk
Outbyte Driver Updater FREEFix the driver behind crashes, sound loss and screen glitchesFind Drivers →Outbyte PC Repair FREEClear out junk files and repair common Windows errorsFree Scan →#1 Best Overall
- 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.
#!/usr/bin/env bash
set -euo pipefail
: "${YOUTUBE_RTMPS_URL:?Set the stream URL from YouTube Live Control Room}"
: "${YOUTUBE_STREAM_KEY:?Set the stream key privately}"
INPUT=${1:-loop.mp4}
exec ffmpeg -re -stream_loop -1 -i "$INPUT"
-c:v libx264 -preset veryfast -pix_fmt yuv420p
-r 30 -g 60 -keyint_min 60 -sc_threshold 0
-b:v 2500k -maxrate 2500k -bufsize 5000k
-c:a aac -b:a 128k -ar 44100
-f flv "${YOUTUBE_RTMPS_URL%/}/${YOUTUBE_STREAM_KEY}"
Make it executable and provide the event URL and key when starting it. Replace the example values with the server URL format shown in Live Control Room; the script appends the key after the URL, so verify that this matches the format YouTube supplies for your selected stream.
chmod +x youtube-loop.sh
YOUTUBE_RTMPS_URL='PASTE_SERVER_URL_HERE'
YOUTUBE_STREAM_KEY='PASTE_STREAM_KEY_HERE'
./youtube-loop.sh /path/to/video.mp4
Do not save a real key in shell history or a shared terminal transcript. For regular use, inject it through a protected environment or secret store with access limited to the account running FFmpeg. The values in this example are an illustrative 720p/30-style starting configuration, not universal YouTube requirements; tune them to the source, connection, and available encoder.
Rank #2
- 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.
Choose encoder settings that fit the source and connection
YouTube’s current encoder guidance recommends H.264 for RTMP/RTMPS, constant bitrate (CBR), a keyframe every two seconds (with four seconds as the maximum), AAC or MP3 audio, and stereo audio at 44.1 kHz and 128 Kbps. See YouTube’s encoder settings, bitrates, and resolutions. The script’s 30 fps and 60-frame GOP target a two-second keyframe interval; its video bitrate is an example, not a platform-wide requirement.
- Choose a resolution and bitrate your source can support and your upload connection can sustain reliably. A bitrate that exceeds available upload capacity can produce dropped frames or an unhealthy stream.
- Keep the frame rate appropriate to the material. If changing
-r, adjust-gand-keyint_minto keep the keyframe interval near two seconds. - The example uses RTMPS over FLV. YouTube recommends RTMPS, which secures the RTMP connection with TLS/SSL. HLS can suit cases such as HDR or codecs unsupported over RTMP, but its segmented delivery has higher latency; use it only where its specific support is needed.
-reis appropriate here because FFmpeg is pacing a local file as a live feed. FFmpeg cautions against using rate limiting on an actual live input, where it can cause packet loss.
Test the stream and start the event
- Use a controlled test event before a public or extended broadcast. Start the script and watch the Live Control Room preview, audio/video quality, and stream health indicators.
- For a scheduled stream, sending media from FFmpeg and making the event live are separate steps unless you have deliberately enabled auto-start. Wait for the preview, then use the Live Control Room’s Go live flow when required by your settings.
- Monitor both FFmpeg output and YouTube’s stream health while the loop runs. YouTube recommends testing and ongoing monitoring; see YouTube live streaming tips.
- To stop, interrupt the FFmpeg process deliberately and end the event in Live Control Room as appropriate. YouTube says streams under 12 hours are automatically archived; that statement does not promise one archive for a longer continuous loop. Plan duration and recording/archive needs accordingly. See YouTube’s encoder setup and archive guidance.
Troubleshooting
| Symptom | Likely cause | What to check |
|---|---|---|
| FFmpeg says the encoder or codec is unavailable | Your installed build lacks libx264 or AAC support. |
Check ffmpeg -encoders; install a distribution build with the needed encoder or change the command to an available compatible encoder. |
| Authentication or connection failure | Wrong server URL/key, a malformed URL-plus-key combination, or a reset key. | Copy fresh values from the selected event, verify its URL format, and update the protected environment variables. |
| FFmpeg transmits, but the scheduled event is not live | The event is waiting for preview or a manual Go live action. | Check Live Control Room and complete its Go live flow, or intentionally configure auto-start. |
| Unstable stream, dropped frames, or poor quality | Upload capacity is insufficient for the chosen bitrate, or source and output settings do not fit. | Check stream health, lower the video bitrate or resolution, and test again on the actual connection. |
| Playback does not loop as expected | The input path is wrong or the source file cannot be read/decoded. | Confirm the file exists and is readable, and inspect FFmpeg’s error output before testing the loop again. |
| The stream does not recover after a connection interruption | A basic FFmpeg invocation may exit or fail when its output connection breaks. | Check the process and YouTube event, then restart deliberately. FFmpeg’s formats documentation includes an RTMP FIFO output example with retry behavior, but recovery adds complexity and cannot guarantee every interruption will recover: FFmpeg Formats Documentation. |
Copyright, reused content, and loop duration
Only stream video and audio you have the rights to use. A video looping successfully through FFmpeg does not establish that you may broadcast its music, footage, or other material on YouTube. Check permissions before starting, and do not assume that repeating a recording makes it original or resolves rights concerns. YouTube’s archive guidance is specifically for streams under 12 hours, so a loop intended to run longer needs a deliberate duration and archive plan.
Recommended Free Tools
Rank #3
- 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.
Or let it run in the cloud
If you want a YouTube loop without maintaining an FFmpeg process on your Linux machine, StreamNeo keeps an uploaded video or playlist live from the cloud. Upload your recording, add your YouTube stream key, and go live. Nothing has to stay on at home; it streams the file as uploaded at any quality up to 4K 60fps for one flat price per slot, with automatic recovery if YouTube drops the stream. The first day is free with no card. Monthly pricing is $9.99 per month. StreamNeo is for uploaded-video YouTube streams, not camera broadcasts. Start a free day at StreamNeo registration.
Quick Recap
Best Value
- 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.
Rank #4
- 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
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.




