October 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 NowOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
FFmpeg

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

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.

To run a continuous YouTube stream from a VPS, install FFmpeg, send a supported audio/video input to YouTube over RTMPS, test the picture and sound, then supervise FFmpeg with systemd. For a looping video file, the example below uses -stream_loop -1; for other inputs, adjust the input and reconnect behavior. A systemd restart policy can recover from an FFmpeg process failure, but it cannot prevent or fix every VPS, network, input, or YouTube outage.

What you need before you start

  • An Ubuntu VPS with enough sustained outbound bandwidth for your chosen stream settings. There is no universal CPU or RAM size for this job: transcoding and stream-copying have different resource demands, so test the actual media and settings on the server you plan to use.
  • A video or other FFmpeg-compatible input. The example below assumes a local video file; a live input or generated feed needs input-specific options.
  • A YouTube broadcast and its stream key from Live Control Room. Use the RTMPS ingestion URL, not an unverified default RTMP address.
  • Shell access with permission to install packages and configure a system service.

YouTube recommends RTMPS, which encrypts the stream in transit, and warns that Live Control Room may show the standard RTMP URL by default. Select or retrieve the RTMPS address explicitly. See YouTube’s RTMPS guidance and the YouTube Live Streaming API documentation.

Install FFmpeg on Ubuntu

Ubuntu is used here as an example, not a requirement. Package versions vary by Ubuntu release and CPU architecture, so check the package available for your VPS image.

  1. Update the package index and install FFmpeg:
    sudo apt update
    sudo apt install ffmpeg
    ffmpeg -version
  2. Check that the installed build includes the encoder you intend to use. For the example below, that is libx264. Ubuntu documents APT and package management in its package catalog and server package-management guide.

Create a YouTube broadcast and protect its stream key

  1. Open YouTube Live Control Room and create or select the broadcast you want to run.
  2. Retrieve its stream key and the RTMPS ingestion URL. Confirm the URL is RTMPS rather than assuming the default shown is secure.
  3. Treat the stream key as a password. Do not put a real key in a public tutorial, repository, shell transcript, or support ticket. Store it in a restricted configuration file or a root-readable systemd environment file.

The URL and key are credentials for sending video to your channel. If you believe a key has been exposed, replace it in YouTube’s live settings and update the VPS configuration that uses it.

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.

Build and test an FFmpeg command for a looping file

This example loops a local file indefinitely, transcodes video to H.264 and audio to AAC, and sends the result to an RTMPS endpoint. Replace the file path, endpoint, key, and encoding settings. It is an illustrative starting point, not a tested universal recipe.

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 its native playback rate rather than sending it as fast as possible; -stream_loop -1 requests an indefinite file loop.
  • -c:v libx264, -r 30, and -g 60 set H.264 encoding, 30 frames per second, and a 60-frame GOP, which corresponds to a two-second keyframe interval at 30 fps.
  • -b:v sets the target video bitrate; -maxrate and -bufsize shape rate control. The example’s 5 Mbps is an initial example value, not a guarantee that the VPS or source can sustain it.
  • -c:a aac -b:a 128k -ar 44100 encodes AAC audio at 128 Kbps and 44.1 kHz.
  • -f flv selects the output format commonly used for RTMP/RTMPS ingest. Replace the placeholder with the exact RTMPS address and key provided for the broadcast.

Inspect the input’s audio and video streams before relying on the command. If the source is already compatible and you want to avoid transcoding, stream-copying may reduce encoding work, but the source’s codecs, bitrate, frame rate, and keyframe interval must already suit the intended YouTube stream. FFmpeg options and protocol behavior depend on the input and installed version; see the FFmpeg Protocols Documentation.

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.

For a network feed, generated pattern, or other live input, do not blindly keep -stream_loop -1. Choose input flags and reconnect/timestamp behavior for that source. Check the installed FFmpeg build and validate the command against representative media before putting it under supervision.

Choose bitrate, resolution, and keyframes

YouTube’s encoder guidance recommends constant bitrate (CBR), H.264, H.265, or AV1 video, AAC or MP3 audio, and a two-second keyframe interval that does not exceed four seconds. For stereo audio it recommends a 44.1 kHz sample rate and 128 Kbps. The H.264 video bitrate ranges below are YouTube recommendations, not guarantees of quality or a substitute for testing.

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.
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.
H.264 output YouTube-recommended video bitrate
720p30 3–8 Mbps
1080p30 5–14 Mbps
720p60 3–8 Mbps
1080p60 6–17 Mbps

These are YouTube encoder recommendations on a page whose publication year is not stated; they were verified in 2026. Select a bitrate your VPS can sustain with margin, accounting for other outbound traffic and any provider egress limits. Higher resolution or frame rate can increase bandwidth needs and, when transcoding, encoding work. YouTube’s current guidance is in Choose live encoder settings, bitrates, and resolutions.

Run FFmpeg as a systemd service

Once the command works in a test, a systemd unit can start it at boot and restart it after abnormal process exits. Create /etc/systemd/system/youtube-stream.service and adapt the service user, working directory, paths, endpoint variable, and command to 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=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

In /etc/youtube-stream.env, set YOUTUBE_RTMPS_URL to the combined RTMPS address and stream key. Restrict file access to root and the service account. The unit assumes the environment variable expands as intended for your installed systemd version; check its substitution and escaping rules. A wrapper script with restrictive permissions may be easier for a complex command.

  1. Reload systemd, enable and start the service, then inspect its status:
    sudo systemctl daemon-reload
    sudo systemctl enable --now youtube-stream.service
    sudo systemctl status youtube-stream.service
  2. Follow the service journal while testing:
    sudo journalctl -u youtube-stream.service -f
  3. Confirm both that FFmpeg is running and that YouTube Live Control Room receives a healthy broadcast. Consider how you will be alerted if the service stops; a process that exists is not proof that the stream is reaching viewers.

Restart=on-failure is useful for a long-running service, but systemd also applies start-rate limits, so repeated failures do not necessarily cause endless immediate restarts. An intentional systemctl stop does not trigger the restart policy. See the Ubuntu Noble systemd.service manual for restart and rate-limit behavior.

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.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Test the stream and diagnose common failures

Before depending on an unattended broadcast, test with audio and movement similar to the intended content. Review FFmpeg’s logs and YouTube’s preview and stream-health messages, including audio presence, aspect ratio, and motion. YouTube recommends testing beforehand and monitoring stream health during the event.

Symptom What to check Practical response
YouTube does not receive the stream RTMPS address, key, broadcast selection, and FFmpeg error output. Confirm that the endpoint is the RTMPS URL for the selected broadcast and that the key is current. Check that the server can reach the endpoint.
FFmpeg exits immediately Input path and permissions, encoder availability, malformed options, and logs. Run the command interactively, correct the first reported error, and verify the service user can read the input and configuration files.
Service keeps restarting or stops restarting systemctl status, journal output, and systemd start-rate limiting. Fix the underlying command or input problem before clearing any start limit; avoid treating frequent restarts as a substitute for diagnosing the failure.
Video stutters or stream health degrades Sustained VPS egress capacity, competing traffic, bitrate, and encoder load. Test the real content and lower the output demands if the server cannot sustain them. Check provider bandwidth and egress limits.
Video works but audio is absent or wrong Whether the input contains audio, stream mapping, audio encoder support, and YouTube preview. Inspect the input streams and adjust mapping or audio encoding to match the source.
FFmpeg is healthy but broadcast is unavailable YouTube broadcast status, account restrictions, and Live Control Room health. Check the broadcast and account state in YouTube; systemd cannot repair a disabled broadcast or account restriction.

A restart policy does not recover from every failure: a missing input file, invalid key, provider network outage, expired or disabled broadcast, and account restriction require a separate fix. Plan to verify the actual broadcast periodically rather than relying only on service status.

Or let it run in the cloud

If managing a VPS, FFmpeg, systemd, and failure monitoring is more work than you want, StreamNeo keeps an uploaded video or playlist live on YouTube from the cloud. Upload your recording, add your YouTube stream key once, and go live. Nothing has to stay on at home; the stream plays the uploaded video rather than broadcasting a camera.

  • Any quality up to 4K 60fps at one flat price per slot, streamed as uploaded without re-encoding or quality tiers.
  • Automatic recovery if YouTube drops the stream.
  • The first day is free with no card (one free day per account).
  • Monthly: $9.99 per month.

StreamNeo is for YouTube streams; its slots include looping, playlists, 10 GB of storage per slot pooled across active slots, and support from the StreamNeo team. Start your free 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.

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.