October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsPC HealthRecommendedCrashes, freezes, slowdowns? Check your PC nowSpot repairable issues before they interrupt work.Check PCOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
DocumentaryTube
Docker

How to Run an FFmpeg YouTube Stream in Docker and Restart It Automatically

A Docker restart policy can relaunch an exited FFmpeg stream, but it cannot fix the cause. Learn how to configure YouTube RTMPS, restart behavior, output recovery, and monitoring.

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

Run FFmpeg as the Docker container’s foreground process, then set a Docker restart policy for the container. For YouTube, use the RTMPS ingestion URL and stream key from Live Control Room. These are separate safeguards: Docker can relaunch a container after it exits, while FFmpeg has distinct options for attempting to recover from output failures. Neither makes a stream failure-proof or fixes its underlying cause.

How the stream works

The path is input media → FFmpeg → YouTube Live ingestion. Docker packages and runs FFmpeg; it does not encode or repair the media by itself. Your input might be a file inside the container, a host file exposed through a bind mount, or another source FFmpeg supports. Choose the appropriate input and confirm the container can access it before troubleshooting YouTube.

Set up the YouTube ingest details

  1. In YouTube Live Control Room, create or select the live stream and copy its stream key. YouTube may show the ordinary RTMP URL by default; use the control to reveal and copy the RTMPS URL. YouTube recommends RTMPS as a secure extension to RTMP. See YouTube’s RTMPS instructions.

  2. Keep the key private. Do not publish it in a Dockerfile, a public Compose file, a screenshot, or a command copied into a public issue. Supply it at runtime through a protected environment or secret mechanism appropriate to your host, and restrict access to configuration and logs that could expose it.

    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.
  3. Decide whether the source can be stream-copied or needs decoding, filtering, and re-encoding. There is no universal FFmpeg command that suits every file and stream: inspect the source streams, desired output, and installed FFmpeg build and encoder options. If a host file is the input, mount its directory into the container and use the corresponding container path.

Choose compatible encoder settings

Match output settings to the source, the available encoder, and the connection’s upload capacity. YouTube’s current encoder guidance lists H.264, H.265 (HEVC), and AV1 for RTMP/RTMPS; frame rates up to 60 fps; CBR bitrate encoding; and a recommended keyframe interval of 2 seconds, not over 4 seconds. Its bitrate ranges vary by codec, resolution, and frame rate. Examples from the table include:

Output Codec YouTube-listed minimum YouTube-listed recommended bitrate
1080p at 30 fps H.264 5 Mbps 14 Mbps
1080p at 30 fps AV1 or H.265 4 Mbps 10 Mbps
1080p at 60 fps H.264 6 Mbps 17 Mbps
1080p at 60 fps AV1 or H.265 4 Mbps 12 Mbps
720p at 30 fps H.264 3 Mbps 8 Mbps
720p at 30 fps AV1 or H.265 2 Mbps 6 Mbps

These are YouTube’s published technical recommendations, not guarantees of performance. Consult the current table for your exact codec, resolution, and frame rate, and confirm your FFmpeg build supports the selected encoder. A bitrate that exceeds stable upload capacity can cause delivery problems; lowering output bitrate or resolution may help when the connection cannot sustain the target.

Keep FFmpeg in the foreground and configure Docker restarts

Docker can only apply its restart policy when the container’s main process exits. Make FFmpeg that main process: run it directly as the container command or entrypoint, not in the background behind a shell that remains running. That lets Docker observe FFmpeg’s exit and restart the container when the chosen policy calls for it.

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.
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.

Docker documents four policies: no (the default; do not automatically restart), on-failure[:max-retries] (restart after a non-zero exit, optionally limiting retries), always (restart whenever the container stops, including after a daemon restart), and unless-stopped (restart unless the container was explicitly stopped). Choose based on whether an intentional manual stop should stay stopped. Docker’s restart-policy documentation recommends restart policies rather than using process managers to start containers.

For Compose, set the service’s restart policy in its configuration. Running docker compose restart restarts existing services; it does not apply edits to the Compose configuration. After changing the service definition, use the appropriate Compose operation to apply the updated configuration. See the Compose restart command reference.

Docker restart policy vs. FFmpeg output recovery

These mechanisms address different failure layers. A container restart relaunches FFmpeg after its process exits; FFmpeg’s FIFO muxer options can attempt recovery while handling output failures. Configure both only when they fit the failure modes you expect.

Mechanism Trigger or layer What it can do What it cannot guarantee
Docker restart policy Container process exits, or Docker daemon restarts, depending on policy Start the container and its foreground FFmpeg process again under the policy’s rules Repair invalid media, an incorrect key, incompatible settings, or a continuing network failure
FFmpeg FIFO muxer recovery options Output failure handled by FFmpeg while the process remains active Attempt output recovery; documented options include attempt_recovery, recovery_wait_time, and packet-overflow settings Recover from every permanent error or replace Docker’s container restart behavior

The FFmpeg protocol documentation includes an RTMP FIFO example that attempts recovery after temporary network failure and discusses continuing at real-time rate. Treat it as an example, not a ready-made command for every input or RTMPS endpoint. Overflow handling may drop packets, and recovery cannot make a persistent network or configuration problem disappear. Review the FFmpeg documentation and validate the options against your installed version and actual setup.

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.
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.

Test the stream and monitor failures

  1. Start the container and check its logs to confirm FFmpeg opened the intended input and began sending output. If it exits, inspect the exit message rather than relying on repeated restarts to conceal the cause.

  2. In YouTube Live Control Room, verify that the stream arrives and monitor its stream health and messages. YouTube recommends testing with audio and video movement similar to the planned stream before relying on it.

  3. Test the failure behavior deliberately in a controlled session: distinguish a process exit from a temporary output interruption, and confirm which mechanism responds. Then check whether YouTube receives the stream again and whether the recovered feed is usable.

  4. Keep an eye on container and FFmpeg logs during operation. A container that repeatedly restarts may indicate a persistent input, authentication, encoder, or network problem—not a successful recovery.

    Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
    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
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Common problems and what to check

  • The container exits immediately: Check the FFmpeg logs for an inaccessible input path, missing mounted file, unsupported option, or unavailable encoder. Confirm FFmpeg is the foreground process and test the source with the same container image and configuration.

  • YouTube does not receive the stream: Recheck the RTMPS URL and stream key in Live Control Room, and confirm the key has not been changed or mistyped. Keep credentials out of public logs and configuration.

  • The container restarts but streaming still fails: Docker has relaunched the process, not corrected its cause. Inspect the newest exit and FFmpeg output for repeated input, key, codec, or connectivity errors.

  • The stream drops during a network interruption: A restart policy only helps if the container process exits. Consider FFmpeg FIFO output recovery for temporary output failures, with settings validated for the actual stream; persistent connectivity failures still require fixing the network path.

    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.
  • Audio or video is unstable or rejected: Compare the codec, frame rate, bitrate mode, keyframe interval, and resolution with YouTube’s guidance and your encoder’s capabilities. Ensure the configured upload bitrate is sustainable.

  • Compose changes seem ignored: docker compose restart does not apply edits to the service definition. Apply the changed configuration with the appropriate Compose operation, then inspect the resulting service and logs.

Or let it run in the cloud

If you want a pre-recorded YouTube stream without maintaining a Docker host, StreamNeo runs uploaded videos or playlists from the cloud: upload a recording, add your YouTube stream key, and go live. Nothing has to stay on at home; each slot streams your upload as made, up to 4K 60fps, at one price per slot. It can automatically recover if YouTube drops the stream. The first day is free with no card. Monthly pricing is $9.99 per month. Start your free day with 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.

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 *

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

More from the Screening Room

Recommended PC Tool
Recommended PC Tool
Windows Errors? Fix Them Before They SpreadFree repair scan
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.