October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsClean PCRecommendedOne scan can reveal what keeps slowing WindowsLook for cleanup and repair opportunities.Run ScanOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
VGSources
24/7 streaming

How to Stream a Pre-Recorded 24/7 YouTube Channel with FFmpeg and systemd

A practical Linux workflow for looping a prerecorded file to YouTube Live with FFmpeg and keeping the encoder process supervised by systemd.

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

You can loop a pre-recorded video to YouTube Live with FFmpeg, then use a systemd service to start FFmpeg at boot and restart it if the process exits. These are two separate checks: systemd can report that FFmpeg is running, but only YouTube Live Control Room can confirm that YouTube is receiving a valid stream. The guide below uses RTMP as an example; use the ingest URL and protocol shown for your stream in YouTube Studio.

What you need before you start

  • A Linux machine or server that can remain on and connected to the internet. With self-hosting, you are responsible for its hardware, network, storage, and operating system.
  • A local video file that FFmpeg can read, plus an installed FFmpeg build. Check the documentation for the version installed on your machine; available formats, codecs, and options depend on that build.
  • A YouTube channel with access to Live Control Room, and the ingest URL and stream key provided in the stream settings.
  • A plan for what viewers should see if the process, host, network, or YouTube event stops. Automatic process restarts do not guarantee continuous viewer-facing playback.

Do not publish your stream key in a public unit file, screenshot, repository, or support post. Anyone who obtains it may be able to send video to your stream.

Create a YouTube Live stream and get its ingest details

  1. Open YouTube Studio and create or select a stream in Live Control Room.
  2. Open the stream settings and copy the ingest URL and stream key. Use the protocol and URL YouTube provides for that stream; do not assume that an RTMP URL applies to an HLS stream.
  3. Keep the stream key private. Store it in a protected configuration file on the Linux host rather than embedding it in public documentation or a screenshot.
  4. For a scheduled stream, start the encoder and wait for the preview to appear in Live Control Room before selecting Go live. Confirm the live state there as well as in the viewer-facing watch page.

YouTube’s encoder guidance says streams under 12 hours are automatically archived. A nominal 24/7 event exceeds that duration, and the cited guidance does not guarantee one complete replay for a continuous stream longer than the threshold. Decide whether to use deliberate event/session boundaries and keep a separate source recording if you need a complete copy.

Check the file and FFmpeg before streaming

Confirm that the input path is correct, the file is readable by the account that will run the service, and the media plays through its end locally. Inspect the installed FFmpeg build and the source’s video and audio tracks before choosing stream copy or transcoding. A command that works for one file is not universal: container, codecs, track layout, timestamps, and the selected YouTube ingest protocol all matter.

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 command is an RTMP example for a compatible local file, not a tested recipe for every source. Replace the path and placeholder with your own values; never use the literal placeholder as a real key.

ffmpeg -re -stream_loop -1 -i /srv/video/channel.mp4 
  -c:v copy -c:a aac -b:a 128k -ar 44100 
  -f flv 'rtmp://a.rtmp.youtube.com/live2/REPLACE_WITH_STREAM_KEY'
  • -re reads a file at its natural playback rate rather than sending it as fast as possible.
  • -stream_loop -1 repeats the input indefinitely. It applies to the input, so place it before that input’s -i.
  • -c:v copy copies the video track without re-encoding. It works only when the source track and output combination are compatible. If they are not, transcode and set the video codec, pixel format, bitrate, frame rate, and keyframe interval using YouTube’s current encoder guidance and the settings shown for your stream.
  • -c:a aac -b:a 128k -ar 44100 encodes audio as AAC with the example bitrate and sample rate. These are example command values, not a guarantee that the source or current stream settings are suitable.
  • -f flv selects the output format used by this RTMP example. It is not an HLS command.

If the file has no audio track, this example’s audio options do not create one. Check the source and platform requirements, then choose an appropriate audio plan; generating silence is one possible approach, but it needs a command tailored to the actual input and output.

Test FFmpeg and confirm the YouTube preview

  1. Run the command in a terminal first, using a safe test or the intended event with care. Check the console for file, codec, authentication, or network errors.
  2. Open the stream in Live Control Room. Confirm that YouTube receives a preview and that the preview shows the expected picture and sound.
  3. For a scheduled event, select Go live only after the preview appears. Then check the stream’s live state and the actual watch page from a viewer’s perspective.
  4. Stop the test cleanly and note any changes needed before moving the command into a service.

A process running locally is not evidence that viewers can watch the broadcast. Keep the YouTube check as a separate operational step.

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.

Run FFmpeg under systemd

Run FFmpeg in the foreground so systemd tracks the encoder process. The following example uses an environment file for the key and a system service that starts at boot. Adjust paths, account names, and directives for the Linux distribution and installed systemd version; this is a starting point, not a universal unit.

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

1. Store the stream key in a protected environment file

Create /etc/ffmpeg-youtube.env with the key value, for example:

YOUTUBE_STREAM_KEY=REPLACE_WITH_STREAM_KEY

Restrict access to the file and make sure the service account can read it. For example, an administrator can set ownership to root and a dedicated group used by the service, then grant read access only to that group. Do not put the actual key in a command you plan to share or in a public repository.

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.

2. Create a service unit

Save a unit such as /etc/systemd/system/youtube-loop.service. Replace streamer with a dedicated, least-privilege account that can read the media file and environment file. Replace the input path and use the ingest URL shown in Studio.

[Unit]
Description=FFmpeg YouTube prerecorded video loop
Wants=network-online.target
After=network-online.target

[Service]
User=streamer
EnvironmentFile=/etc/ffmpeg-youtube.env
ExecStart=/usr/bin/ffmpeg -re -stream_loop -1 -i /srv/video/channel.mp4 -c:v copy -c:a aac -b:a 128k -ar 44100 -f flv rtmp://a.rtmp.youtube.com/live2/${YOUTUBE_STREAM_KEY}
Restart=on-failure
RestartSec=10s

[Install]
WantedBy=multi-user.target

Verify the FFmpeg path with command -v ffmpeg and substitute the result if it is not /usr/bin/ffmpeg. systemd is not a shell: do not rely on shell features such as pipes or command substitution in ExecStart. Review your systemd version’s handling of environment-variable expansion and protect the key from exposure through unit listings or process diagnostics on your host. If your setup cannot keep it private that way, use a protected wrapper or another secret-handling method appropriate to the system.

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

3. Enable, start, and inspect the service

sudo systemctl daemon-reload
sudo systemctl enable --now youtube-loop.service
sudo systemctl status youtube-loop.service
sudo journalctl -u youtube-loop.service -f

enable --now configures startup at boot and starts the service immediately. status shows the service state; journalctl shows its logs. After deployment, verify both the journal and YouTube’s incoming preview. To stop the service, use sudo systemctl stop youtube-loop.service; to start it again, use sudo systemctl start youtube-loop.service.

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

Understand restart behavior and monitoring

Restart=on-failure asks systemd to restart FFmpeg after a failure. The delay helps avoid an immediate retry loop, but an appropriate policy and delay depend on the host and failure modes. A restart cannot fix a missing file, unsupported media, bad key, repeated authentication failure, exhausted disk, unavailable network, or an event state that requires action in YouTube Studio.

After a restart, inspect systemctl status and journalctl -u youtube-loop.service, then check the incoming preview and live state in Studio. If unattended availability matters, add an external check or alert that tests viewer-facing playback; local service state alone cannot prove that the broadcast is reaching viewers.

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

Use the protocol YouTube selected

RTMP

The command above is specifically an RTMP/FLV example. Use the RTMP ingest URL from the selected stream’s settings, and confirm that the source’s tracks are compatible with the output or transcode them to meet the current encoder guidance.

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.

HLS

Do not reuse the RTMP command unchanged for HLS. YouTube’s HLS setup guidance specifies an HTTPS ingest URL and higher latency than RTMP because HLS sends segments. It requires TS segments of 1–4 seconds, a rolling playlist with no more than five outstanding segments, and HTTPS POST/PUT ingest. Its HLS-specific codec guidance includes HEVC as well as H.264. Follow the settings and protocol shown for the selected stream.

Looping multiple videos

For a sequence of videos, prepare and validate a playlist or combined media input before putting it into production. Concatenating clips before looping is one possible strategy, but there is no single playlist method established here for clips with different codecs, durations, or audio layouts. Test transitions locally and check timestamp continuity; otherwise a transition can introduce playback or timestamp problems that are difficult to diagnose after going live.

Common problems and what to check

Symptom Likely area Checks and next step
FFmpeg exits immediately Path, permissions, options, or media support Read the service journal, verify the file exists and is readable by the service account, check the installed FFmpeg build, and test the command interactively.
systemd says the service is active, but YouTube has no preview Ingest details or stream health Check the URL and key in the selected Studio stream, FFmpeg’s output, and network connectivity. Confirm reception in Live Control Room rather than relying on process state.
The stream repeatedly restarts Persistent failure being retried Inspect the journal for the underlying error before changing the restart delay. Correct issues such as a bad key, missing file, unsupported codec, or network failure rather than letting the service retry rapidly.
Video works but audio is missing or fails Source audio track or audio encoding Inspect the source’s audio tracks. The example expects audio for its AAC options; a source without audio needs a deliberate audio plan.
Playback breaks at clip boundaries Playlist or timestamp continuity Test the playlist or combined input locally, including transitions, and check that timestamps remain continuous before using it for a public stream.
The live event ends or its replay is incomplete Event boundary and archive expectations Plan session boundaries for a channel that runs beyond YouTube’s under-12-hour automatic archive threshold, and retain a separate source recording if a complete copy is needed.

Choose self-hosting when you want control—and can operate the host

FFmpeg with systemd gives you control over the input, encoding, and Linux service. In return, you maintain the machine, network, storage, media compatibility, and monitoring. A spare Linux computer or rented VPS are possible host categories, but this guide does not establish the compatibility or sustained operating conditions of any specific device or provider. Check the workload and source before choosing hardware or hosting.

Or let it run in the cloud

StreamNeo is a cloud service for keeping a YouTube channel live from uploaded videos: upload a recording or build a playlist, add your YouTube stream key, and go live. Nothing has to stay on at home; StreamNeo loops from the cloud, supports any uploaded quality up to 4K 60fps at one price per slot, and automatically recovers if YouTube drops the stream. The first day is free with no card. The monthly option is $9.99 per month. See StreamNeo for details. Start the free first day with StreamNeo.

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.

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 *

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
Outdated Drivers Are Slowing You DownFree scan - exact matches
PC Slower Than It Used to Be?Free scan - under a minute

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.