DriversRecommendedOutdated drivers can make a good PC feel brokenScan driver issues before chasing fixes manually.Scan NowOctober 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
FFmpeg

How to Run a Prerecorded YouTube Live Stream on a Linux Server with systemd

A practical Linux guide to sending a prerecorded video to YouTube Live with FFmpeg and supervising the encoder with systemd.

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

To stream a prerecorded video to YouTube Live from a Linux server, create or schedule an encoder event in YouTube Studio, test an FFmpeg command in the foreground using the event’s ingest URL and stream key, then run that proven command as a supervised systemd service. Check the YouTube preview and service logs before the event: systemd can restart a failed encoder, but that does not guarantee an uninterrupted broadcast.

Understand the YouTube event and encoder feed

YouTube treats the viewer-facing broadcast and the incoming encoder feed as separate things: its Live Streaming API calls them a liveBroadcast and a liveStream. Your Linux server sends media to the stream feed; YouTube associates it with the broadcast viewers watch. A scheduled broadcast does not begin playback just because it exists: the encoder must connect, and you must review its preview and take the event live in Live Control Room.

Scheduling is useful when you want a shareable upcoming watch page or want viewers to be able to set reminders. YouTube’s instructions for creating and scheduling an encoder stream are at YouTube Help: Create a YouTube live stream with an encoder.

Prepare the YouTube event and protect its stream key

  1. In YouTube Studio, select Create → Go Live. Create or schedule an encoder stream, then set its title, privacy, and event details.
  2. Copy the server URL and stream key shown for the selected stream settings. Use the current values from Studio rather than a sample endpoint from a tutorial. Prior settings may be reusable, but confirm that the URL and key belong to the event or stream you intend to use.
  3. Keep the stream key secret. YouTube says, “Stream keys are like your YouTube stream’s password and address.” Store it in a configuration file readable only by the service account or root, or use an appropriate secret store. Do not put it in a public script, world-readable unit file, screenshot, shell history, or logs. If it is exposed, reset it in YouTube Studio and update the service. See YouTube Help: Manage your live stream settings.

For an ordinary creator setup, the Studio-provided ingest URL and key are the practical source of truth. YouTube’s Live Streaming API can also provide primary and backup ingest addresses and a stream name. If you choose RTMPS, use the secure ingest address and meet YouTube’s TLS requirements, including port 443 and the correct server name for SNI authentication; see YouTube’s RTMPS ingestion guide.

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.

Check FFmpeg and test the video in the foreground

First check that FFmpeg is installed and whether its build supports the protocol you plan to use:

ffmpeg -version
ffmpeg -protocols

RTMPS support depends on the installed FFmpeg build. FFmpeg documents RTMPS separately from plain RTMP, so do not assume an available command supports the channel’s chosen endpoint. YouTube’s RTMPS requirements are described in its RTMPS ingestion guide; FFmpeg documents file streaming and protocol behavior in its protocol documentation and command-line documentation.

Run a foreground test with the actual input file and the current ingest URL and key. FFmpeg’s real-time file-to-RTMP pattern is:

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.
ffmpeg -re -i input.mp4 -f flv 'rtmp://server/app/stream-key'

This is a pattern, not a ready-to-run YouTube command. Replace the sample URL with the one shown in YouTube Studio; for RTMPS, use the channel’s secure ingest address and confirm protocol support first. The -re option reads the file at real-time speed so it behaves like an encoder feed rather than sending the file as fast as the server can process it.

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.

Choose encoding based on the source

Do not add -c copy automatically. Stream copy avoids re-encoding, but whether it is suitable depends on the source codecs, timestamps, frame rate, audio layout, and container compatibility with the ingest feed. If the source needs encoding, choose codecs, resolution, frame rate, and bitrate deliberately for that file and YouTube’s current recommendations. There is no single verified bitrate or universal command here that is correct for every source. Check the resulting preview and stream health in YouTube Studio before relying on the command.

Decide whether the program should end or repeat

A normal finite input ends when FFmpeg reaches the end of the file. If the event is meant to repeat the program, verify the loop option and timestamp behavior for your installed FFmpeg version, then test with the exact media and event setup. Do not treat systemd’s restart policy as a media-loop feature: it responds to process exits, not to your intended program schedule.

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.

Run the tested FFmpeg command under systemd

Use a system service that runs FFmpeg in the foreground. Give it an unprivileged service account, absolute paths, a controlled working directory, and a protected configuration file for credentials. Keep the working command identical to the one you tested, adapting it carefully for the service environment.

# /etc/systemd/system/youtube-live.service
[Unit]
Description=Prerecorded YouTube Live encoder
Wants=network-online.target
After=network-online.target

[Service]
Type=simple
User=youtube-live
Group=youtube-live
EnvironmentFile=/etc/youtube-live/stream.env
WorkingDirectory=/srv/youtube-live
ExecStart=/usr/bin/ffmpeg -re -i /srv/youtube-live/program.mp4 -f flv ${YOUTUBE_INGEST_URL}
Restart=on-failure
RestartSec=5

[Install]
WantedBy=multi-user.target

This is an example skeleton, not a tested universal unit. In particular, systemd’s environment-file parsing and variable handling in unit fields are not shell behavior in every respect. Check the systemd version and configuration on your server, and confirm how the intended URL and secret are parsed. Use a correctly escaped value or a dedicated wrapper with safe argument handling if necessary. Avoid putting a real stream key in the unit file or in process arguments if local users can inspect them.

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

Make sure the environment file is restricted to the service account or root, and do not commit it to source control. Before enabling the service, verify that the service user can read the input file and access any required configuration. Review the installed systemd documentation for directive semantics on your distribution.

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

Load, start, and inspect the service

  1. Save the unit at /etc/systemd/system/youtube-live.service and verify the paths, service account, command arguments, and secret handling.
  2. Load the unit and start it when you are ready to test against the intended YouTube event:
    sudo systemctl daemon-reload
    sudo systemctl enable --now youtube-live.service
  3. Check the unit state and recent FFmpeg output:
    sudo systemctl status youtube-live.service
    sudo journalctl -u youtube-live.service
  4. Confirm that YouTube receives the feed and displays the expected preview before taking a scheduled broadcast live.

For a one-off scheduled event, decide when the encoder should stop and stop it when the broadcast is over. YouTube’s guidance says to end the event in Live Control Room and stop sending encoder data afterward. YouTube says events under 12 hours are automatically archived; see its encoder streaming guidance.

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

Plan recovery without promising an uninterrupted stream

Restart=on-failure can ask systemd to start FFmpeg again after a process failure, with the delay set by RestartSec. FFmpeg also documents a FIFO output approach with retry and recovery options for temporary network problems. These address different failure modes, and neither proves viewers will see continuous playback. A reconnect can create a gap or interact with the broadcast’s state. Test recovery against the target event and keep Live Control Room available for monitoring.

Choose a restart policy and delay deliberately for the event. Check FFmpeg’s exit status and logs after a failure, and verify what YouTube shows after reconnection. Do not assume that restarting the process resumes the broadcast seamlessly or repeats the input file.

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.

Preflight the server and YouTube event

  • File and permissions: confirm the video exists at the configured path and is readable by the service user, not only by your administrator account.
  • Upload capacity: YouTube recommends leaving 20% headroom over the total stream bitrate, including primary and backup feeds if both are used. Its guidance states: “Have enough bandwidth: The total bitrate you’re streaming cannot exceed the amount of upload bandwidth available. Leave a bit of room (20% recommended).” This is a recommendation, not a guarantee. See YouTube Help: Troubleshoot your live stream.
  • Timing: YouTube suggests preparing at least two hours ahead and starting the encoder at least 15 minutes before the event, leaving time to inspect preview and resolve problems. These are YouTube’s preparation recommendations, not required systemd timings. See its live-stream troubleshooting guidance.
  • Viewer access: check that the watch page is accessible as intended and, where relevant, test it on a mobile device.
  • Audio, video, and health: inspect the preview, sound, picture, and YouTube’s stream-health indications; compare any warnings with FFmpeg’s journal output.
  • Archive: if you are keeping a local recording as well, verify that the file is valid and growing as expected.
  • Rights and policy: use media you have the rights to stream and check YouTube’s current live-stream rules for copyright and content eligibility before scheduling. A technically healthy feed does not establish that you have permission to use its contents.

Troubleshoot common failures

Symptom Likely checks and fixes
No preview in Live Control Room Confirm FFmpeg is still running; verify that the ingest URL and key are the current values for the selected stream settings; check that the service can read the input and credential configuration. Review the YouTube event setup guidance at Create a live stream with an encoder.
TLS or connection errors with RTMPS Check that the URL is the channel’s RTMPS ingest address, the connection uses port 443 and the expected TLS server name/SNI, and the installed FFmpeg build supports the selected protocol. See YouTube’s RTMPS guide and FFmpeg protocol documentation.
Feed connects but buffers or loses health Check available outbound upload capacity, shared network congestion, the chosen bitrate, and YouTube’s health warnings. Compare total bitrate with available capacity and retain YouTube’s recommended 20% headroom.
systemd repeatedly restarts FFmpeg Inspect systemctl status and journalctl -u youtube-live.service for the exit reason. Check file paths, service-user permissions, FFmpeg arguments, protocol support, and how the credential file is parsed.
Stream stops at the end of the video That is expected for a finite input. If the event should repeat, test FFmpeg’s loop and timestamp behavior explicitly. A restart-on-failure setting does not itself loop a successfully completed input.

Choose a server setup that fits the event

FFmpeg on a Linux server is a software-encoder approach. YouTube permits encoder software; it recommends professional hardware encoders for higher-production-value events, but does not make dedicated hardware mandatory. Consider a hardware encoder only if its operational simplicity and controls justify owning and maintaining an appliance.

For a rented VPS rather than a server you control, compare sustained upload capacity, route reliability, server location, egress limits or charges, and CPU capacity if you must transcode. Provider pricing and capabilities vary; choose based on the event’s actual bitrate and duration rather than assuming that any VPS can sustain the feed.

Or let it run in the cloud

If your goal is simply to keep prerecorded video live on YouTube, StreamNeo is a cloud alternative: upload a recording or build a playlist, add your YouTube stream key once, and go live. Nothing has to stay on at home; it streams the uploaded video at its original quality up to 4K 60fps for one flat price per slot, with no re-encode or quality tiers. It automatically recovers if YouTube drops the stream. The first day is free with no card. Monthly is $9.99 per month.

StreamNeo is for prerecorded video streams to YouTube, not camera broadcasts. See StreamNeo or its pricing. Start your free first day on StreamNeo.

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 *

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.