Skip to content
streamneo.
Setup Guides13 min read

How to Build a 24/7 YouTube Livestream with Docker and FFmpeg

A practical guide to running a 24/7 YouTube livestream with Docker and FFmpeg, covering YouTube settings, security, testing and recovery.

sn.
StreamNeoPublished 4 October 2026
Worth sharing?

A 24/7 YouTube livestream with Docker and FFmpeg is built from three separate parts: YouTube Studio handles the broadcast, FFmpeg handles media and transmission, and Docker handles the process that runs them. Keeping those responsibilities separate makes failures easier to diagnose.

You can loop a prerecorded video from a remote machine without leaving your own computer switched on, but no container image, restart policy or FFmpeg command should be treated as universally tested. Validate each part against your operating system, Docker installation, FFmpeg build, network and YouTube account before relying on it overnight.

Understand the three system layers

Think of the setup as a chain rather than one command.

YouTube Studio creates or configures the live stream. It provides the server URL and stream key, shows the preview, reports stream health and controls whether the broadcast is public, private or unlisted. YouTube also decides how the stream is archived and what viewers can rewind.

FFmpeg reads the source. That source might be a devotional video, a lofi visual, a local news loop or a generated live feed. FFmpeg decodes the input, optionally loops or transforms it, encodes video and audio, and sends the output to YouTube using RTMP or RTMPS. Its settings determine bitrate, frame rate, keyframes, audio and output format.

Docker packages the process and gives you a repeatable way to start it. A container can hold FFmpeg and its configuration, while Docker controls how the process is launched, what files are mounted and what happens when the process exits. Docker does not repair a bad video file, an invalid stream key or an incompatible FFmpeg setting.

This distinction matters when something goes wrong. If YouTube reports an invalid key, changing the container image is unlikely to help. If the preview shows stuttering video, inspect the input, encoder and available upload capacity before changing a restart policy. If the container exits immediately, inspect its logs and command independently of YouTube.

A local computer can run the same arrangement, but it must remain powered, connected and available. A remote host removes the need to keep your home computer running, but introduces hosting costs, access controls and another environment to maintain. A VPS or cloud machine is therefore an operating choice, not a requirement of FFmpeg.

For a simpler file-based starting point, compare the stages in this guide with streaming a local video file to YouTube Live with FFmpeg. The media command may be similar, while the container lifecycle introduces additional decisions.

Prepare YouTube Studio ingest

Before writing a Docker file, create or select the stream in YouTube Studio. Follow YouTube's current encoder setup instructions for your account, because live-stream access and the Studio interface can change. Initial live-stream enablement may take time, so do not leave this step until the moment you want to go live.

In Live Control Room, identify the current server URL and stream key. Treat both as configuration data supplied by YouTube, not as values to copy from an old tutorial. YouTube recommends RTMPS for ordinary content. Its documented RTMPS connection uses a valid YouTube endpoint and application path over port 443, with the protocol written as rtmps.

The exact endpoint belongs in the FFmpeg output URL, and the key belongs at the end of that URL or in the mechanism you use to provide it. Do not publish either value in a repository, Dockerfile, public issue, screenshot, tutorial, image layer or ordinary log output. If a key is exposed, revoke or rotate it in YouTube Studio and update the running configuration.

Start with a private or unlisted broadcast while you check the pipeline. Confirm that the preview receives both picture and sound before making the stream public. The preview is useful because it separates an FFmpeg output problem from a viewer-facing problem, but it is not a substitute for a longer test.

You should also decide what the stream is meant to be. A single uninterrupted event may suit a radio-style channel, but YouTube says streams longer than 12 hours may not be captured at all. Very long streams may also have limited or unavailable DVR rewind. If a complete replay matters, plan a local archive rather than assuming YouTube will preserve the entire event. YouTube's archive guidance describes this limitation and recommends keeping a local backup.

Choose compatible FFmpeg media settings

The source file and the output settings need to agree. A 25-frame-per-second source can be converted to another frame rate, but conversion adds work and may create repeated or discarded frames. If the source already has a suitable resolution, frame rate and audio track, avoid unnecessary transformations.

YouTube's current encoder guidance lists RTMP or RTMPS, H.264, H.265 or AV1 video, AAC or MP3 audio, constant bitrate and frame rates up to 60 fps. It recommends a two-second keyframe interval and says the interval should not exceed four seconds. Check the current YouTube encoder settings and bitrate table before selecting a profile, because these recommendations can change.

For H.264, the listed recommended video bitrates are as follows:

Target Frame rate YouTube recommended H.264 video bitrate
1080p 60 fps 12 Mbps
1080p 30 fps 10 Mbps
720p 60 fps 6 Mbps
240p–720p 30 fps 4 Mbps

These are platform recommendations, not guarantees that your connection or machine can sustain them. Add audio to the total upload requirement and leave room for normal network variation. If your connection is marginal, a lower resolution and bitrate that remain stable are more useful than a nominally sharper stream that repeatedly buffers.

YouTube's audio guidance lists 128 Kbps for stereo and 384 Kbps for 5.1. Choose the channel layout deliberately. A stereo devotional recording sent as a 5.1 output does not become better quality, and an audio mismatch can create unnecessary processing.

Use FFmpeg's -re option when reading a file intended for real-time transmission. The FFmpeg documentation includes a generic file-to-RTMP example in its protocol documentation, but that example uses a generic server and is not a verified YouTube command. Replace the endpoint only with the current values from YouTube Studio, then validate the complete command against your installed FFmpeg build and selected protocol.

Looping deserves its own test. A file loop can restart at its beginning, but you should not assume that it will resume at the previous position after a network failure. Check how your chosen FFmpeg options behave when the output disconnects, when the input reaches its end and when the container receives a termination signal.

There is also a content question. A looped video is still a publication of that video and its audio. Use material you own or have licensed, including music, visual backgrounds, news footage and voice recordings. YouTube's livestream terms require compliance with its rules and the necessary rights; repetition does not create a licence.

Plan the container configuration

Begin with a small, understandable container design. The container needs an FFmpeg executable, access to the source media and a way to receive configuration without hard-coding secrets into the image. Keep the media outside the image where practical, so replacing a video does not require rebuilding the whole environment.

The image choice is an important validation point. A public image may contain a different FFmpeg version, codecs or default behaviour from the one you expect. An image can also change after publication. Before using one, inspect its documentation, source, release history and available binary. Confirm that the codecs and protocols required by your media are present.

Do not present a particular image as tested or definitive for every reader. Build or select an image that you can inspect, pin and reproduce in your own environment. Record the image reference and FFmpeg version used in your notes, then retest when either changes.

The container command should have one clear foreground process where possible. Docker can only observe and restart the process it is managing. If a shell script starts FFmpeg in the background and then exits, the container may appear healthy while the actual encoder has stopped. Conversely, a wrapper can be useful if it has explicit handling for exit codes, signals and retry delays. That behaviour must be tested rather than assumed.

A restart policy is similarly environment-specific. Docker provides restart-policy options, but the right choice depends on whether FFmpeg exits on an input error, whether repeated failures should be retried, and how the host behaves after a reboot. A policy that immediately retries a bad key can create noisy logs without fixing anything. A policy that never retries leaves a short network interruption for manual recovery.

Do not copy a restart policy into production simply because it appears in a sample. Check the current Docker documentation for the syntax available in your installation, then test normal exit, invalid configuration, lost network access, host restart and manual stop. Confirm that a deliberate stop does not cause an unwanted restart.

Mount source media read-only where your workflow permits it. Keep temporary files and any local archive in locations with enough storage, and check file permissions from inside the container. A source path that works on a laptop may not exist on a remote host, and a file owned by one host user may not be readable by the container user.

Resource limits also need measurement. Encoding a high-resolution stream can use substantial CPU, while decoding a difficult source or writing an archive adds work. Watch CPU, memory, disk growth and network traffic during a representative test. Do not infer capacity from the fact that the container starts.

Handle the stream key securely

The stream key is a credential. Anyone who obtains it may be able to send content to your broadcast, so handle it like a password rather than like an ordinary video setting.

Keep it out of the Dockerfile, shell history, source repository and public compose file. Be careful with commands that print their complete arguments, because process inspection and logs may expose a key embedded directly in a URL. Also check error output before sharing it in a support request.

Docker supports several ways to provide configuration, but the safest method for your environment depends on your host, deployment process and access controls. An environment variable may be convenient, but it can be visible through inspection tools or diagnostic output. A mounted file may reduce command-line exposure, but its permissions and backups require care. A dedicated secret facility may be appropriate in a larger deployment, but you must verify how it is supported by the exact Docker mode and tooling you use.

This is an area where examples are easy to overstate. Do not treat an unverified secret-injection method as a tested recipe. Confirm where the value is stored, who can read it, whether it appears in logs and what remains after the container is removed. Test rotation by changing the key in YouTube Studio, updating the protected value and restarting the process.

If you accidentally expose the key, stop treating it as private. Revoke it in YouTube Studio, generate or obtain the replacement according to the current Studio flow, and remove the exposed copy from places where it should not remain. Deleting a repository file does not necessarily remove it from its history or from backups.

Test startup and failure behaviour

A successful first launch proves very little. Test the complete sequence in stages and record what you observe.

First, run FFmpeg against the chosen source without involving Docker if that is practical. Confirm that the file decodes, the expected audio stream exists and the output settings are accepted by your installed build. Then run the same media path inside the candidate image. This helps distinguish a source or FFmpeg problem from a container problem.

Next, use an unlisted YouTube stream and watch the Studio preview. Check the image, motion, audio level, aspect ratio, keyframe behaviour and reported bitrate. Confirm that the watch page is accessible from another connection. If the stream is intended for viewers in India or elsewhere with variable connections, observe it from the likely audience conditions rather than from the host alone.

Test the input reaching its end. Does FFmpeg loop as intended, exit, or wait? Test a missing input file. Test an invalid stream key. Test a temporary loss of outbound connectivity. Test a full or nearly full archive disk. Test a host reboot and a deliberate container stop. For each case, write down whether the process exits, whether Docker retries it and whether YouTube receives a clean reconnection.

Do not assume reconnection means continuation from the same timestamp. A new connection may start at the beginning of the loop or fail until the process is restarted. The viewer may see a gap, a new live session or an unavailable preview. Decide whether that behaviour is acceptable for your channel before calling the setup ready.

A burn-in test is more useful than a quick launch. Let the actual source, output profile and archive path run for a meaningful period, then inspect the logs and output files. The length of that test is your operational decision, not a guarantee of future uptime. A setup that survives one night can still fail after a source change, host update, key rotation or network outage.

For process recovery specifically, separate the container question from the FFmpeg question. How 24/7 live-stream auto-restart should work is useful when deciding which failures should be retried and which should stop for attention. A restart loop cannot correct a malformed command or expired credential.

Monitor a continuous stream

A 24/7 stream needs an operating routine, even when the process is automated. Check the YouTube preview or live dashboard for picture, sound, stream health and viewer access. YouTube's live-streaming tips recommend previewing, monitoring quality and checking that local archive files are growing.

Monitor four separate areas:

  • Media: frozen frames, black video, missing audio, desynchronised sound, unexpected cropping or an input that has ended.
  • Transport: dropped frames, unstable upload, repeated disconnects, authentication errors or a stream that is no longer visible in Studio.
  • Container: process exit, restart count, log growth, CPU and memory use, and whether the container is still reading the expected file.
  • Host: available disk space, host reboots, time synchronisation, network changes and access to the machine running Docker.

Keep logs useful but restrained. An FFmpeg command that prints excessive diagnostic output can fill a disk over several days. At the same time, discarding every message makes it hard to identify the first failure. Set a retention approach and test that you can retrieve the relevant period without exposing the stream key.

If you need a local archive, monitor its size and open a sample after the test. A file that grows is not necessarily playable, complete or stored on a disk that will remain available. YouTube's archive behaviour and DVR options are separate from your own recording, so document which outcome your channel depends on.

For a machine that is inconvenient to maintain, a managed workflow can remove the need to leave Docker, FFmpeg and the host running on your desk. StreamNeo removes that specific operational burden by letting you upload the video once, provide the YouTube stream key and have the broadcast run while your computer is off, with monitoring and automatic restart for drops. It remains YouTube-only, and you should still validate the media, rights and YouTube settings before publishing.

If your main concern is a home computer losing its session rather than container management, compare that problem with keeping an FFmpeg YouTube stream running after an SSH disconnect. If network capacity is the concern, the bitrate settings for dropped frames on Jio 5G provide a more focused comparison of upload headroom and output quality.

Before committing, compare the operating options on the pricing page. When the file and channel are ready, start free — 24-hour trial, no card.

FAQ

Can Docker alone keep a YouTube livestream running forever?

No. Docker can manage a process according to the configuration you provide, but it cannot fix an invalid key, incompatible media, a full disk or a broken network. Test the container, FFmpeg command and YouTube connection separately, then test how they behave together.

Should I use RTMP or RTMPS?

Use the current YouTube-recommended secure ingest method, RTMPS, when your setup supports it. Confirm the endpoint, application path and port from YouTube's current documentation rather than copying an old URL.

Is a restart policy enough for a 24/7 channel?

No. A restart policy may bring a process back after an exit, but it does not prove that the new process can read the source, authenticate or reconnect correctly. Test deliberate failures and monitor the resulting logs and YouTube preview.

Will YouTube save a complete replay of a 24/7 stream?

Do not assume that it will. YouTube says streams longer than 12 hours may not be captured, and DVR rewind may be limited on very long broadcasts. If a complete replay matters, keep and verify a local archive as part of the design.

YOU’VE REACHED THE END

Keep the ideas coming.

More guides, useful tools and a little help for your next broadcast.

Back to the journal ↗
YOUR NEXT READ

A little more to explore.

More Setup Guides guides ↗ · All topics ↗