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 DealsWindows FixRecommendedWindows errors stealing your time? Find the fix fastScan stability, cleanup and performance issues.Fix Now×
Skip to content
DocumentaryTube
FFmpeg

How to Set Up FFmpeg on a VPS for a Continuous YouTube Stream

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.

To keep a prerecorded video streaming to YouTube from a VPS, install FFmpeg, create a YouTube Live broadcast, send the video to YouTube’s RTMPS endpoint, and supervise FFmpeg with systemd. First test the stream and its recovery: systemd can restart a failed process, but it cannot fix an unavailable VPS, broken network, missing input file, or YouTube-side problem.

What you need before you start

  • An Ubuntu VPS with permission to install packages and configure systemd. Ubuntu is the example here, not a requirement for FFmpeg.
  • A video file stored on the VPS, or another input source with its own suitable FFmpeg options. The example below loops a file.
  • A YouTube channel able to create a live broadcast, plus its RTMPS ingestion URL and stream key.
  • Enough sustained outbound capacity for the selected video bitrate, with headroom. Transcoding also uses CPU; there is no universal VPS size established for every source and encoding setup.

Use RTMPS rather than plain RTMP when sending the stream to YouTube. YouTube describes RTMPS as RTMP over TLS/SSL and notes that Live Control Room may show the ordinary RTMP URL by default. Select or retrieve the secure endpoint explicitly: YouTube’s RTMPS guidance and LiveStreams API documentation.

1. Install FFmpeg on Ubuntu

Update APT’s package index, install FFmpeg, and verify that the executable runs:

sudo apt update
sudo apt install ffmpeg
ffmpeg -version

Ubuntu lists FFmpeg in its package catalog and documents APT as its command-line package manager. The available FFmpeg version depends on the Ubuntu release and VPS CPU architecture; check the package for the image you are using rather than assuming every server has the same build. See Ubuntu Packages and Ubuntu Server package management.

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.

2. Create a YouTube Live broadcast and protect its key

  1. Open YouTube Live Control Room and create or select the broadcast you intend to use.
  2. Retrieve the broadcast’s ingestion URL and stream key. Choose the RTMPS address, not an RTMP address shown by default.
  3. Keep the key private. Do not put a real key in a public tutorial, repository, shell transcript, or support ticket. Store it in a file whose permissions limit access to root and the account running the service.

The stream key is a credential: anyone with it may be able to send video to the broadcast. The exact Control Room labels can change, so verify the selected endpoint and broadcast in YouTube before starting FFmpeg.

3. Choose an input and build a test command

Looping a prerecorded file

This example transcodes an MP4 file to H.264 video and AAC audio, then sends it as FLV over RTMPS. Replace the file path and endpoint/key with your own values. Do not publish the real key in a copied command.

ffmpeg -re -stream_loop -1 -i /srv/stream/input.mp4 
  -c:v libx264 -preset veryfast -pix_fmt yuv420p 
  -r 30 -g 60 -b:v 5M -maxrate 5M -bufsize 10M 
  -c:a aac -b:a 128k -ar 44100 
  -f flv "<RTMPS_URL>/<STREAM_KEY>"

-re reads the file at approximately its normal playback rate rather than sending it as fast as possible. -stream_loop -1 requests an indefinite loop of the file. Remove the loop option for a one-pass file or a live input; live sources need flags appropriate to their protocol and timestamp behavior. The bitrate and video settings in this command are examples, not a universal recipe. Confirm that your FFmpeg build includes the selected encoder and inspect the source’s audio and video streams before relying on it.

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.

Transcode or copy the source?

Transcoding lets you set the codec, bitrate, frame rate, and keyframe interval, but uses VPS CPU. Stream-copying can reduce encoding work when the source is already compatible with YouTube and your chosen output, but does not let FFmpeg reshape unsuitable source settings in the same way. Check the source and FFmpeg’s documentation before changing to -c:v copy or -c:a copy; compatibility depends on the actual media and container. See FFmpeg Protocols Documentation.

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

4. Match YouTube’s encoder guidance and test capacity

YouTube recommends RTMP/RTMPS, H.264, H.265, or AV1 video, AAC or MP3 audio, constant bitrate (CBR), and a two-second keyframe interval that does not exceed four seconds. It recommends 44.1 kHz stereo audio and 128 Kbps stereo audio. Recommendations are starting points, not guarantees that a particular VPS or source will work. See YouTube’s encoder settings, bitrates, and resolutions.

H.264 output YouTube-recommended video bitrate range Example FFmpeg frame rate and GOP
1080p30 5–14 Mbps 30 fps; -g 60 gives a two-second GOP
720p30 3–8 Mbps 30 fps; -g 60 gives a two-second GOP
1080p60 6–17 Mbps 60 fps; use a GOP of 120 for two seconds
720p60 3–8 Mbps 60 fps; use a GOP of 120 for two seconds

These are YouTube’s published H.264 video bitrate recommendations; the source page does not state a publication year (verified 2026). Select a bitrate your VPS can sustain with margin for overhead and other traffic. The stream’s total outbound traffic also includes audio and protocol overhead. Do not treat the video bitrate alone as a VPS sizing formula.

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 with the same kind of motion and audio as the planned stream; a static test image does not reveal every encoding or bandwidth issue.
  • Check YouTube Live Control Room’s preview and stream-health messages while testing.
  • Observe CPU use and network throughput on the VPS. A transcode that cannot keep up may drop behind real time; reducing output complexity or using a compatible source may help.
  • Confirm the audio is present, the aspect ratio is correct, and playback continues through at least one file loop if looping is intended.

5. Run FFmpeg under systemd

A foreground command ends when its shell or session ends. A systemd service can start it at boot and restart it after an abnormal process exit. Create /etc/youtube-stream.env containing the complete RTMPS destination, for example YOUTUBE_RTMPS_URL='rtmps://example.invalid/app/your-secret-key', then restrict access to that file. Replace the illustrative value with the endpoint and key supplied for your broadcast.

sudo install -m 600 /dev/null /etc/youtube-stream.env
sudo nano /etc/youtube-stream.env
sudo chown root:root /etc/youtube-stream.env

Create /etc/systemd/system/youtube-stream.service. Adjust the user, paths, input options, endpoint handling, and encoding settings to match your installation:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
[Unit]
Description=FFmpeg YouTube live stream
Wants=network-online.target
After=network-online.target

[Service]
Type=simple
User=stream
WorkingDirectory=/srv/stream
EnvironmentFile=/etc/youtube-stream.env
ExecStart=/usr/bin/ffmpeg -re -stream_loop -1 -i /srv/stream/input.mp4 -c:v libx264 -preset veryfast -pix_fmt yuv420p -r 30 -g 60 -b:v 5M -maxrate 5M -bufsize 10M -c:a aac -b:a 128k -ar 44100 -f flv ${YOUTUBE_RTMPS_URL}
Restart=on-failure
RestartSec=5

[Install]
WantedBy=multi-user.target

This unit assumes the environment variable supplies the complete RTMPS destination, including the key. Test systemd’s environment-variable substitution and escaping behavior on your installed version. For complex commands, use a wrapper script with restrictive permissions rather than placing sensitive values in broadly readable command text. Ensure the stream account can read the media file and access any needed directories.

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 the unit, enable it at boot, start it, and inspect status and logs:

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

Ubuntu’s systemd service guidance describes Restart=on-failure for long-running services and documents start-rate limiting. Repeated failures can hit those limits rather than restarting forever; choose cooldown and rate-limit behavior deliberately. An intentional systemctl stop does not trigger the restart policy. See Ubuntu Noble systemd.service manual.

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

6. Verify what “continuous” means and monitor it

There are two distinct checks: whether the FFmpeg process is running and whether YouTube is receiving a healthy, viewable broadcast. A running process alone does not prove the stream is live. Check FFmpeg’s journal and YouTube’s preview and health notices, then periodically confirm the broadcast is still receiving the expected picture and sound.

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.

systemd can recover from some process failures, but it cannot restore a missing input file, correct a wrong or revoked stream key, recreate an expired or disabled broadcast, overcome a VPS provider outage, repair a broken route to YouTube, or resolve a YouTube account restriction. Plan alerting and a human check for failures that a local restart cannot remedy. YouTube recommends testing before a live event and reviewing stream health while it is underway.

Common problems and fixes

Symptom Likely cause What to check
YouTube receives no stream Wrong endpoint, key, or broadcast state Verify the RTMPS URL and key in Live Control Room, confirm the intended broadcast is active, and inspect FFmpeg’s connection error in journalctl.
FFmpeg exits immediately Invalid path, unreadable file, unsupported codec, or malformed options Run the command interactively with the same input and inspect the first FFmpeg error. Confirm the service account can read the input.
Service starts and then stops repeatedly Persistent command error or systemd start-rate limiting Read recent service logs and inspect the unit’s restart and rate-limit settings. Fix the underlying error before clearing or relaxing limits.
Video is choppy or falls behind Insufficient egress capacity, CPU contention during transcoding, or difficult source media Compare measured VPS CPU/network use with the selected output. Test a lower recommended bitrate or less demanding output; consider stream-copy only if the source is already compatible.
Video works but audio is absent or distorted Missing, unsupported, or incorrectly mapped source audio Inspect the input streams, check FFmpeg’s audio mapping and encode logs, and verify audible playback in YouTube’s preview.
The process is active but the broadcast is not healthy Local process status does not reflect YouTube ingestion or playback health Check Live Control Room health notices and the preview. Investigate endpoint errors, bitrate stability, and source timestamps rather than relying on systemctl status alone.

Cost and operational trade-offs

A VPS requires an always-on server and outbound data capacity; the bill and applicable egress limits depend on the provider and plan. Transcoding also requires CPU, while copying an already suitable source can reduce that work. The sources do not establish a universal VPS price, bandwidth allowance, or CPU/RAM requirement, so estimate from the intended bitrate and test the real media on the proposed server before committing.

Or let it run in the cloud

If you are streaming uploaded videos to YouTube and do not want to maintain a VPS and systemd service, StreamNeo is a cloud option. Upload a recording or build a playlist, add your YouTube stream key once, and go live. Nothing has to stay on at home; it plays uploaded video rather than going live from a camera. Every quality up to 4K 60fps is streamed as uploaded at one flat price per slot, with automatic recovery if YouTube drops the stream. The first day is free with no card. Monthly pricing is $9.99 per month. For Indian users, UPI works. Start the free day at StreamNeo registration.

Frequently Asked Questions

Can systemd guarantee a 24/7 YouTube broadcast?

No. It can restart FFmpeg after certain process failures, but cannot guarantee VPS, network, source-file, or YouTube availability.

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

Can I use a live camera input with this setup?

The command shown is for a prerecorded file. A camera or other live input needs source-specific FFmpeg input and reconnect settings.

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.

Read next

Recommended PC Tool
Recommended PC Tool
PC Slower Than It Used to Be?Free scan - under a minute
Outdated Drivers Are Slowing You DownFree scan - exact matches

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.