Driver FixRecommendedSound, Wi-Fi or graphics acting up? Check drivers firstFind missing or outdated drivers fast.Check 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
VGSources
Docker

How to Run a YouTube Live Video Loop with Docker and FFmpeg

Use FFmpeg’s infinite input loop in a Docker container to send a prerecorded video to YouTube Live, with careful setup, encoder settings, and monitoring.

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

To loop a prerecorded video to YouTube Live, run FFmpeg in a Docker container, place -stream_loop -1 before the input file’s -i, and send the encoded output to the stream URL and key shown in YouTube Studio. Docker packages the runtime; it does not by itself keep a broadcast healthy. Test the full path, check YouTube’s preview and stream health, and protect the stream key as a credential.

Before you start

  • A YouTube channel eligible for live streaming. YouTube’s encoder setup guidance requires a verified channel without live-streaming restrictions during the prior 90 days. See YouTube’s encoder setup guidance.
  • A prerecorded video file accessible to the Docker container, an installed Docker runtime, and an FFmpeg build with the required input, encoder, and muxer support.
  • A stable internet connection with enough upload capacity for the selected stream bitrate plus headroom.
  • A stream URL and key from the intended stream in YouTube Studio. Keep the key private; anyone who obtains it may be able to broadcast to that stream.

There is no single Docker image, Compose file, or restart configuration established here as a universal, tested deployment. Choose an FFmpeg image and container settings suitable for your host, then verify paths, permissions, available encoders, and secret handling in that environment.

Create the YouTube encoder stream

  1. Open YouTube Studio and go to Create > Go live to open Live Control Room. Create or select the stream you intend to use.
  2. In the stream’s settings, copy its Stream URL and Stream key. Use the exact server URL and protocol YouTube provides for that stream; YouTube recommends RTMPS for the standard RTMP workflow.
  3. Store the key in a secret mechanism appropriate to your Docker host or deployment platform. Do not commit a real key to source control, put it in a public example, or leave it in a command likely to be saved in shell history. If it is exposed, reset it in Live Control Room.
  4. Before the public event, start an encoder test and wait for the incoming video to appear in Live Control Room’s preview. YouTube recommends setting up early and checking the preview before selecting Go live.

For current protocol, codec, and encoder requirements, consult YouTube’s live encoder settings because recommendations can change.

Set the loop and output in FFmpeg

FFmpeg’s -stream_loop is an input option: put it before the -i for the file it should repeat. A value of -1 means infinite repetition; 0 means no looping. See the FFmpeg command-line documentation.

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.

The following shows the shape of a command, not a verified end-to-end Docker recipe. Replace the placeholders privately and adapt codecs, output format, bitrate, resolution, and frame rate to the file, the selected YouTube protocol, the FFmpeg build, available compute, and current YouTube guidance:

ffmpeg -re -stream_loop -1 -i /media/video.mp4 
  -c:v libx264 -pix_fmt yuv420p -preset veryfast 
  -c:a aac -b:a 128k 
  -f flv "$YOUTUBE_INGEST_URL/$YOUTUBE_STREAM_KEY"

In this illustrative command, -re reads the file at its native rate for live output, while -stream_loop -1 repeats it. The example uses H.264 video, AAC audio, and an FLV output, a conventional combination for an RTMP-style output; it is not a guarantee that these settings or URL construction will work unchanged for every YouTube stream, media file, or FFmpeg build. Follow the ingest URL format YouTube supplies and test the actual output.

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.

Make the container see the video

Mount the directory containing the video into the container and point FFmpeg at the path as seen inside the container. Confirm that the container’s user can read the file. A host path such as /home/me/video.mp4 will not automatically exist at that same path inside a container unless you mount it there.

Check the FFmpeg build and output

The sample specifies libx264; the chosen image must include that encoder if you keep this option. Confirm available encoders and muxers in the image you select, and inspect FFmpeg’s output for input, codec, authentication, or connection errors. If you use a protocol other than the illustrated RTMP-style path, check that both YouTube and the encoder support the required protocol and format.

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.

Handle credentials and container lifecycle

Pass the URL and key through your deployment’s secret mechanism rather than baking them into an image or committing them in a Compose file. Be aware that environment variables can be exposed through some host or container inspection tools, so use the strongest practical secret handling for your environment. Docker restart policies or an external supervisor can restart an exited process, but they do not prove that the stream is healthy or that the host and network will remain available.

Choose settings that match YouTube’s guidance

For RTMP/RTMPS, YouTube lists H.264, H.265/HEVC, and AV1 video, frame rates up to 60 fps, AAC or MP3 audio, and CBR bitrate encoding. It recommends a two-second keyframe interval, which should not exceed four seconds. Select a codec and protocol combination supported by both the encoder and the stream; do not assume every option in the list works in every setup.

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
Target or setting YouTube guidance Practical use
1080p at 30 fps, H.264 5 Mbps minimum; 14 Mbps recommended Use the recommendation as a target for H.264 ingestion, not a universal bandwidth guarantee.
720p at 30 fps, H.264 3 Mbps minimum; 8 Mbps recommended A lower target can suit a connection or host that cannot reliably sustain a higher bitrate.
Keyframe interval 2 seconds recommended; no more than 4 seconds Set the encoder’s keyframe interval to meet this guidance where the encoder exposes the setting.
Stereo audio 44.1 kHz sample rate; 128 kbps Check the output audio format and listen to the preview rather than assuming the source is suitable.
5.1 audio 48 kHz sample rate; 384 kbps; AAC required over RTMP/RTMPS Use only when the source and full encoding path support multichannel output.

These figures are YouTube’s listed encoder recommendations, not a promise that a particular connection or file will behave well. For additional resolutions and frame rates, use the current YouTube bitrate and resolution table.

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

Test, start, and monitor the stream

  1. Start the container with a short, private test or with the intended event configured in YouTube Studio. Confirm FFmpeg can read the file and connect to the ingest server.
  2. In Live Control Room, wait for the preview and check that both picture and audio are present. Check the stream-health indicators and correct any reported issues before going live.
  3. Check the outgoing resolution, frame rate, bitrate, audio, and keyframe interval against your target. Make sure the host has enough processing capacity to encode continuously if encoding rather than stream-copying.
  4. When ready, select Go live in Live Control Room. Continue monitoring the encoder process, connection, preview, and audio/video during the stream.
  5. When ending the event, end it in YouTube and stop the encoder. YouTube says streams under 12 hours are automatically archived; do not assume a longer continuous stream will be archived in the same way. See YouTube’s live-stream archive guidance.

YouTube recommends leaving upload bandwidth headroom: its streaming tips say to leave about 20% above the total stream bitrate. Account for audio and any other traffic sharing the connection, and test under realistic conditions. See YouTube’s streaming tips.

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.

Troubleshoot common failures

Symptom Likely cause What to check
FFmpeg says the input file cannot be opened The host file was not mounted, the in-container path is wrong, or the container user lacks read permission. Inspect the container’s mounts and permissions, then use the path visible inside the container.
FFmpeg reports an unknown encoder or muxer The selected image’s FFmpeg build lacks the requested component. Check that build’s available encoders and muxers, or choose settings supported by that build.
YouTube receives no stream or rejects the connection The stream URL, protocol, key, or output format may not match the selected stream. Copy the URL and key again from that stream’s settings, verify the protocol YouTube provides, and review FFmpeg’s connection output. Reset the key if it may have been exposed.
Preview is missing, delayed, or reports poor stream health The encoder may not be sending correctly, the upload may be constrained, or the stream settings may be unsuitable. Check FFmpeg logs, connection stability, bitrate, and YouTube’s preview and health information. Retest with a lower resolution or bitrate if necessary.
Video plays but audio is absent or wrong The source may lack an audio stream, or the selected output codec and audio settings may not be appropriate. Inspect the source and output audio streams and listen to the YouTube preview; adjust the audio codec, sample rate, and bitrate to the intended format.
The loop stops unexpectedly FFmpeg exited, the container or host stopped, or the network connection failed. Check process and Docker logs, host availability, and network stability. A restart policy can relaunch a process but cannot confirm YouTube is receiving a healthy stream.

Copyright, reused content, and continuous streams

Only stream material you have the rights to broadcast, including music, video, and any third-party material embedded in the file. A technically successful loop does not establish that the content complies with YouTube’s copyright rules or monetization policies. Review the rules that apply to your channel and location in YouTube Studio and YouTube Help before broadcasting. The cited setup and encoder pages do not establish that indefinite prerecorded live streaming is permitted for every account, content type, or jurisdiction, so do not treat this workflow as blanket approval for a 24/7 stream.

Or let it run in the cloud

If your goal is to keep a prerecorded YouTube channel live without leaving a home computer on, StreamNeo is an alternative to managing Docker and FFmpeg on your own host. Upload a recording or build a playlist, add your YouTube stream key once, and go live; StreamNeo loops the uploaded video from the cloud. It streams to YouTube, not from a camera or to other platforms.

  • Nothing has to stay on at home.
  • Uploaded video streams as made, up to 4K 60fps, at one flat price per slot.
  • StreamNeo automatically recovers if YouTube drops the stream.
  • The first day is free with no card, one free day per account.

Monthly: $9.99 per month. See StreamNeo for details, then start your free 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.

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

Leave a Reply

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

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

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
Crashes, No Sound, or Screen Glitches?Free driver scan
Windows Errors? Fix Them Before They SpreadFree repair 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.