Hardware FixRecommendedDevice not working? Your driver may be the problemCheck updates for common hardware issues.Fix DriversOctober 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 Scan×
Skip to content
DocumentaryTube
24/7 streaming

How to Run a 24/7 YouTube Music Stream with systemd on Ubuntu

Use FFmpeg with systemd to keep a prerecorded YouTube music stream running on Ubuntu, including boot startup, restart handling, stream-key protection, testing, and copyright checks.

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

Run FFmpeg in the foreground on an Ubuntu machine, and let systemd start it at boot and retry it after an unexpected exit. YouTube Studio supplies the stream destination and key; FFmpeg sends your looping media to YouTube Live. This keeps the process running across reboots, but it does not guarantee YouTube ingest, network, or rights health.

How the setup works

The Ubuntu computer or server must stay powered on and connected to the internet. FFmpeg reads a media file and sends it to YouTube Live; systemd supervises FFmpeg as a service. The option -stream_loop -1 tells FFmpeg to loop its input indefinitely. Keeping FFmpeg in the foreground lets systemd track the process and apply its restart policy if it exits.

YouTube Studio manages live-stream eligibility and provides the ingest URL and stream key. Treat the key like a password: anyone who obtains it may be able to use your stream.

Before you start

  • Your YouTube channel must be verified and must not have had live-streaming restrictions in the previous 90 days. Enabling live streaming for the first time can take up to 24 hours. See YouTube’s live-streaming enablement guidance.
  • An Ubuntu machine with a persistent internet connection, a media file FFmpeg can read, and enough upload capacity for the selected stream settings.
  • Music and any accompanying visuals for which you hold the necessary rights for worldwide use on YouTube. A file being online or available to download does not establish that you may rebroadcast it.

Configure YouTube Live

  1. Open YouTube Studio and enable live streaming if it is not already enabled. Allow up to 24 hours for first-time activation.
  2. Create or schedule a stream in YouTube Studio and select the encoder workflow. Copy the ingest URL and stream key from the stream settings.
  3. Keep the key private. Store it in a protected configuration file on the Ubuntu host, not in a public script or article. If it is exposed, reset it in YouTube Studio. YouTube explains encoder setup in its live-streaming encoder guidance.

Choose and test the media settings

YouTube’s current encoder guidance lists RTMP and RTMPS, H.264, H.265, or AV1 video, and AAC or MP3 audio. It recommends constant bitrate (CBR) and a two-second keyframe interval, which should not exceed four seconds. For H.264 at 1080p30, YouTube lists 5 Mbps as the minimum and 14 Mbps as recommended for video. These are platform recommendations, not a promise that your machine or connection can encode and send the stream reliably.

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.

For prerecorded material, first confirm that FFmpeg can read the file and that its codecs and container are suitable for your chosen workflow. If you copy the audio and video streams rather than re-encode them, the source’s existing codecs and timing must already be acceptable. The example below uses stream copy to avoid adding an unverified encoding preset; it is not suitable for every input. Check YouTube’s recommended live encoder settings.

YouTube recommends testing with representative audio and motion, monitoring stream health, and leaving about 20% upload-bandwidth headroom above the stream bitrate. Test privately or unlisted where appropriate before relying on the broadcast. A service shown as active in Ubuntu is not proof that YouTube is receiving healthy audio and video.

Install FFmpeg and prepare a service account

Install FFmpeg using the package source appropriate to your Ubuntu release. Package details can vary by release; verify the installed executable path with command -v ffmpeg. The example service expects /usr/bin/ffmpeg.

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.

Create a dedicated unprivileged account and a working directory for the media. For example, use a system account named stream and place the input at /srv/youtube-music/loop.mp4. Ensure that the account can read the media and execute FFmpeg, but does not have unnecessary administrative privileges.

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

Store the key and create a wrapper

Systemd does not run ExecStart= through a shell by default, so shell-style variable expansion in that field is not a safe way to insert a key. Use a small executable wrapper that reads a protected environment file and then replaces itself with FFmpeg. This also avoids putting the key directly in the unit file. Avoid printing the key or exposing it in logs.

Create /etc/youtube-music.env as a root-owned file with mode 0600, containing the stream key:

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.
YOUTUBE_STREAM_KEY=replace_with_your_private_key

Because systemd reads the environment file before launching the service, the service account does not need permission to edit it. Create /usr/local/bin/youtube-music-start with the following contents, replacing paths or the ingest URL if your YouTube Studio settings specify a different destination:

#!/bin/sh
set -eu
: "${YOUTUBE_STREAM_KEY:?YOUTUBE_STREAM_KEY is not set}"
exec /usr/bin/ffmpeg -re -stream_loop -1 
  -i /srv/youtube-music/loop.mp4 
  -c:v copy -c:a copy 
  -f flv "rtmp://a.rtmp.youtube.com/live2/${YOUTUBE_STREAM_KEY}"

Set the wrapper executable and restrict its ownership so it cannot be modified by the service account. The stream key will be passed as part of the FFmpeg destination argument; host administrators may be able to inspect process details, so protect access to the machine as well as the environment file. Use the ingest URL YouTube provides if it differs from the example.

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

Create the systemd unit

Save this as /etc/systemd/system/youtube-music.service. Confirm the paths, account name, wrapper, and input file match your 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
[Unit]
Description=YouTube music stream
Wants=network-online.target
After=network-online.target

[Service]
Type=simple
User=stream
WorkingDirectory=/srv/youtube-music
EnvironmentFile=/etc/youtube-music.env
ExecStart=/usr/local/bin/youtube-music-start
Restart=on-failure
RestartSec=15

[Install]
WantedBy=multi-user.target

Restart=on-failure asks systemd to restart FFmpeg after an unsuccessful exit; RestartSec=15 waits 15 seconds before a retry. These settings do not recover every failure. Systemd applies start-rate limiting, so repeated rapid failures can leave the unit failed until the limit is cleared or its configuration is changed. The Ubuntu Noble systemd.service manual documents restart behavior and rate limiting.

Enable, start, and verify the stream

  1. Reload systemd’s unit definitions: sudo systemctl daemon-reload.
  2. Enable the service at boot and start it now: sudo systemctl enable --now youtube-music.service.
  3. Check whether the process is running: systemctl status youtube-music.service.
  4. Follow the service logs for FFmpeg errors: journalctl -u youtube-music.service -f. Do not treat an active status alone as confirmation of a healthy broadcast.
  5. Open the stream in YouTube Live Control Room. Check the preview and stream-health indicators, then confirm that viewers can hear the audio on a separate device. Keep monitoring after the initial test.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Troubleshoot failures at both ends

Symptom Likely area to check What to do
Service fails immediately or repeatedly restarts Unit paths, permissions, missing executable, or FFmpeg input/codec errors Read systemctl status and journalctl; verify the wrapper path, executable permissions, input path, and that the service account can read the media.
Service is active, but YouTube shows no incoming stream Ingest URL, key, network access, or YouTube stream setup Check that the key and destination match the current Studio stream, confirm the channel is enabled for live streaming, and inspect YouTube’s stream-health panel.
Video arrives but audio is missing or incorrect Source file streams or copied codecs Inspect the input with FFmpeg and test representative playback before going live. Stream copy preserves source streams; it does not repair unsuitable audio.
Health is unstable or viewers see buffering Upload capacity, competing traffic, or host/network reliability Measure available upload bandwidth during representative use, retain YouTube’s recommended 20% headroom, and check for sustained network interruptions.
Retries stop and the unit is failed Repeated exits may have hit systemd start-rate limiting Fix the underlying error first, then inspect systemctl status and the journal. After correcting it, reset the failed state with sudo systemctl reset-failed youtube-music.service and start the service again.
YouTube interrupts or terminates the live stream Copyright detection or a rights issue Review the claim and your permissions. A systemd restart cannot resolve a rights restriction or make unlicensed content lawful.

Understand what restarts do—and do not—recover

FFmpeg’s -stream_loop -1 repeats the input while that FFmpeg process runs. If systemd restarts the process after an exit, playback may begin from the start of the input; this setup does not implement resume-from-position behavior. A restart policy can recover from some process exits, but it cannot fix invalid media, a compromised or rejected key, a persistent network outage, YouTube ingest problems, rights claims, or systemd’s exhausted start limit. The FFmpeg documentation describes the infinite-loop option.

Copyright and YouTube live-stream rules

YouTube scans live streams for third-party content. It may replace the picture, temporarily interrupt the broadcast, or terminate it when it identifies material that violates its rules. Even licensed content may be interrupted unless the rights holder allowlists the channel. You need the necessary rights for the music and any other content used; YouTube’s livestream terms state that creators must have the rights needed to exploit live content on Google services, including music licensing rights.

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.

Or let it run in the cloud

If you do not want to maintain an always-on Ubuntu machine, 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 once, and go live. StreamNeo loops the uploaded material in the cloud, so nothing has to stay on at home. It is for prerecorded videos, not camera input, and streams to YouTube only.

  • Any quality up to 4K 60fps as uploaded, at one flat price per slot; no re-encode or quality tiers.
  • Automatic recovery if YouTube drops the stream.
  • The first day is free with no card, one free day per account.
  • One always-on stream per slot, 10 GB storage per slot pooled across active slots, looping and playlists, and StreamNeo team support.

Monthly service: $9.99 per month. UPI and cards are accepted in India; card checkout is available worldwide. See StreamNeo for details, then start the free first 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.

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.