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
VGSources
Amazon EC2

How to Run a 24/7 YouTube Stream on EC2 with FFmpeg and systemd

A practical guide to looping a prerecorded video to YouTube from EC2 with FFmpeg and systemd—and understanding what the setup will and will not recover from.

By VGSources Team 10 min read

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.

Run FFmpeg in the foreground on a Linux EC2 instance and let systemd supervise it. For a prerecorded video, FFmpeg can loop a local file and publish it to YouTube Live; systemd can restart FFmpeg after a process failure and start it again at boot. This setup does not make a single EC2 instance highly available: it cannot by itself recover from a failed host, bad source file, invalid stream key, blocked network, or a stream that is unhealthy while FFmpeg remains running.

What you need before starting

  • An AWS account with permission to launch and manage an EC2 instance, plus a Linux distribution that uses systemd.
  • A video file stored on the instance, with enough disk space and a format compatible with your chosen FFmpeg output. For a persistent prerecorded stream, the file must remain readable for the life of the service.
  • A YouTube channel that is eligible for YouTube Live and has live streaming enabled. YouTube says first-time enablement may take up to 24 hours.
  • An installed FFmpeg build that supports your selected codecs and RTMPS output. The exact build and protocol support depend on how FFmpeg was packaged.
  • Outbound network access from the EC2 instance to the YouTube ingest endpoint. A normal one-way publishing setup does not need an inbound RTMP port open on EC2.

Allow time for a private or unlisted test before relying on the stream. YouTube recommends preflight testing and monitoring stream health; the commands below are an implementation pattern, not a tested deployment or a promise of uninterrupted service.

Enable YouTube Live and get the ingest details

  1. Open YouTube Live Control Room while signed in to the channel that will broadcast. Complete any verification or live-stream enablement steps YouTube presents; a newly enabled channel may need to wait up to 24 hours.
  2. Create or select a live stream and copy its ingest URL and stream key from the encoder setup. Use the RTMPS URL if your FFmpeg build supports it. RTMPS is RTMP over TLS/SSL; YouTube recommends it for the encrypted connection. Check the actual endpoint displayed in Live Control Room rather than assuming a default RTMP URL is the secure one.
  3. Treat the key like a password. Do not paste a real key into a public script, shared terminal transcript, or world-readable unit file. If you believe it has been exposed, an authorized channel owner or manager can reset it in YouTube.

Keep the full ingest URL and key separate until configuring the host. Do not put either in the article’s command examples or in a repository.

Launch an EC2 host with restrained network access

Choose an instance and network

There is no universal instance size for this job. CPU needs depend on whether FFmpeg copies the source streams or decodes and re-encodes them; memory, disk, and network needs depend on the operating system, file, and chosen profile. If transcoding, choose an instance with enough sustained CPU for the selected resolution and frame rate, then check actual load during a test.

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.

Limit access

  • In the EC2 security group, allow SSH only from the administrator’s IP range if SSH is needed, or use a managed access method instead.
  • Allow outbound traffic needed for DNS and the YouTube ingest connection. Confirm subnet routing, network ACLs, host firewall rules, and any organizational egress policy.
  • Do not add an inbound RTMP rule for a one-way encoder connection. AWS security groups are stateful, so response traffic for an allowed outbound connection is permitted.

These network controls should be checked for the selected subnet and account configuration; a rule that looks correct in the security group cannot compensate for a missing route or a separate egress block.

Install FFmpeg and stage the video

Install FFmpeg using the package manager or approved software source for your Linux distribution, then check the installed build and its protocol support before configuring the service:

ffmpeg -version
ffmpeg -protocols

Confirm that the listed protocols and encoders cover the RTMPS endpoint and codecs you plan to use. Package names and available FFmpeg features vary by distribution and build. Place the source in a stable location such as /srv/youtube-stream/loop.mp4, owned so the service account can read it but not replace it accidentally.

Pick stream copy or transcoding

Approach Use it when Trade-offs
Stream copy The source’s video and audio codecs, pixel format, dimensions, frame rate, and other properties already suit YouTube’s ingest requirements. FFmpeg avoids decoding and encoding, so it is fast and does not add a generation of encode loss. It cannot resize, filter, or correct an unsuitable source profile, and compatibility must be verified.
Transcoding The source needs resizing, filtering, a compatible codec/profile, a controlled bitrate, or another output transformation. It offers output control but requires CPU and can reduce quality. Select an instance capable of sustaining the encode rather than assuming every EC2 size can handle it.

FFmpeg’s documentation describes stream copy as avoiding decode/encode; it is appropriate only when the source is compatible with the destination. For a conventional SDR stream, YouTube currently lists RTMP/RTMPS and H.264, H.265, and AV1, with constant bitrate (CBR) and frame rates up to 60 fps. The recommended keyframe interval is two seconds and must not exceed four seconds. These YouTube settings were checked on 2026-10-03; bitrate recommendations vary by codec, resolution, and frame rate.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
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.

Example: copy compatible source streams

Replace the placeholders with your endpoint and key. This schematic loops the file, reads it at its normal rate, and copies its audio and video streams without re-encoding:

ffmpeg -re -stream_loop -1 -i /srv/youtube-stream/loop.mp4 
  -c:v copy -c:a copy 
  -f flv "<RTMPS_URL>/<STREAM_KEY>"

Use the complete URL and key format shown by YouTube for your stream. Some sources need timestamp or container handling that this simple example does not address; validate loop boundaries and playback in a private or unlisted test.

Example: transcode to H.264 and AAC

For a 1080p, 30 fps H.264 stream, YouTube’s current published table recommends 5 Mbps; for 1080p at 60 fps it recommends 17 Mbps. Its table also lists 8 Mbps for both 720p at 30 fps and 720p at 60 fps. These are YouTube recommendations, not universal minimums or a guarantee of quality. Choose the matching row and codec column for your actual profile, and ensure the EC2 network can sustain the output.

For the 1080p30 example only, a two-second keyframe interval corresponds to a 60-frame GOP. Adjust -g for the output frame rate (for example, 120 frames at 60 fps). YouTube lists stereo audio at 128 Kbps and 44.1 kHz. Example:

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.
ffmpeg -re -stream_loop -1 -i /srv/youtube-stream/loop.mp4 
  -vf "scale=1920:1080,fps=30" -c:v libx264 -pix_fmt yuv420p 
  -b:v 5M -minrate 5M -maxrate 5M -bufsize 10M 
  -g 60 -keyint_min 60 -sc_threshold 0 
  -c:a aac -b:a 128k -ar 44100 -ac 2 
  -f flv "<RTMPS_URL>/<STREAM_KEY>"

This is a starting example, not an assertion that every FFmpeg build accepts every option or that every source can be scaled this way. Check FFmpeg’s output for errors, confirm the encoder is present, and validate video and audio in YouTube’s preview. The bitrate above applies only to the cited 1080p30 H.264 recommendation; do not copy it unchanged for a different profile.

Keep the stream key out of the unit file

A simple EnvironmentFile can keep a key out of the unit text, but environment-based secrets still require restrictive permissions and careful access control. For systems that support it, systemd’s credential mechanism is preferable to putting a secret in a public script or unit. Confirm the exact syntax and behavior for your distribution and systemd version.

One practical pattern is a root-owned, restricted environment file readable by the dedicated service account. For example, create /etc/youtube-stream/stream.env containing:

RTMPS_URL=<full-RTMPS-ingest-URL>
STREAM_KEY=<YouTube-stream-key>

Restrict the file to its intended owner and service group (for example, root ownership and mode 0640 with a dedicated group), and ensure parent directories cannot be modified by untrusted users. Do not use a real secret in shell history or a command typed directly into a shared session. An environment file does not hide the key from privileged local administrators, and a publishing URL may be visible in process arguments to users with sufficient local access. Protect the host accordingly and rotate the key if exposed.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
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

For a wrapper approach, keep a root-controlled executable readable by the service account. The wrapper can load the restricted file and invoke FFmpeg in the foreground; shell expansion is needed for the variables, so do not embed the key as a literal in the script:

#!/bin/sh
set -eu
. /etc/youtube-stream/stream.env
exec /usr/bin/ffmpeg -re -stream_loop -1 
  -i /srv/youtube-stream/loop.mp4 
  -c:v copy -c:a copy -f flv 
  "${RTMPS_URL}/${STREAM_KEY}"

Use the transcoding options instead of -c:v copy -c:a copy when the source is not ingest-compatible. Ensure the wrapper cannot be edited by the service account if that account should not control its publishing credentials.

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

Have systemd supervise FFmpeg

Run FFmpeg as the service’s main foreground process; do not detach it into an unmanaged background shell. Create /etc/systemd/system/youtube-loop.service and adapt paths, user, group, dependencies, and the wrapper to your distribution:

[Unit]
Description=YouTube prerecorded live stream
Wants=network-online.target
After=network-online.target

[Service]
Type=exec
User=youtube-stream
Group=youtube-stream
ExecStart=/usr/local/sbin/youtube-loop
Restart=on-failure
RestartSec=10

[Install]
WantedBy=multi-user.target

Type=exec tracks successful execution setup and is recommended by the systemd service manual for long-running services. Restart=on-failure asks systemd to restart the process after an abnormal failure while systemd and the host are operating; the ten-second delay is an example to tune after observing startup and recovery behavior, not a universal value. Use a dedicated least-privilege account that can read the video and wrapper but cannot rewrite system files.

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.

Reload the unit definitions, enable startup on boot, and start the service:

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

To inspect logs, use sudo journalctl -u youtube-loop.service; for recent entries and follow mode, use sudo journalctl -u youtube-loop.service -n 100 -f. To stop the service deliberately, use sudo systemctl stop youtube-loop.service. After a unit or wrapper change, reload as appropriate and restart the service.

Test the stream and verify recovery

  1. Start with a private or unlisted test in YouTube Live Control Room. Confirm that the preview receives both video and audio, and inspect the stream-health status.
  2. Check the instance’s CPU, memory, disk space, outbound connectivity, and journal while the stream is running. A transcoder that cannot keep up can fail to deliver a stable output even when FFmpeg stays alive.
  3. In a controlled test, stop the FFmpeg service process and verify that systemd restarts it and that the stream reconnects. Do not use a public production event for this test.
  4. Reboot the EC2 instance during a planned test window and confirm the enabled service starts after boot, the source is mounted and readable, and YouTube receives the new connection.
  5. Monitor the YouTube stream-health view as well as systemd. A process can remain alive while the stream is stalled or unhealthy.

YouTube’s encoder setup guidance says streams under 12 hours are automatically archived. That statement does not establish what happens to archives for streams exceeding 12 hours. If an archive matters, plan and validate a separate recording or segmentation workflow and check YouTube’s current limits.

What systemd can and cannot recover

Failure or condition What to do
FFmpeg exits abnormally while the host and systemd are working Restart=on-failure can relaunch the process after the configured delay. Check the journal to find why it exited.
The process remains alive but video or audio is stalled, or YouTube reports poor stream health Use independent monitoring and alerting for process and stream health. A process restart policy does not detect every unhealthy-but-running condition.
Source file is missing, unreadable, or corrupted Restore or repair the file and its permissions, then restart and verify the stream.
Stream key was reset, credentials are invalid, or the channel is restricted Correct the credential or channel issue in YouTube and update the protected host configuration. Check the stream-health view.
Outbound connection is blocked or DNS/routing fails Check egress policy, DNS, subnet routes, network ACLs, and host firewall. Restarting FFmpeg alone does not repair network access.
Instance lacks CPU capacity during encoding, or a process hangs without exiting Review resource and stream-health monitoring. Adjust the encode workload or capacity, and define a tested way to detect and recover from hangs.
EC2 host, availability zone, or region becomes unavailable A single instance cannot restart itself on a failed host. Higher availability requires separate monitoring and a tested failover design.

Do not describe one EC2 VM plus systemd as an uninterrupted or high-availability service. Process supervision covers one failure class; alerting, host monitoring, and independent failover address different ones.

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

Estimate the recurring EC2 cost

There is no defensible one-size monthly price for a 24/7 stream without the AWS Region, instance family and size, operating system, storage, and expected outbound data transfer. On-Demand compute charges accrue while the instance runs, and outbound data transfer can be an additional cost. AWS’s published data-transfer allowance has eligibility and geographic exclusions, and prices can change. Use AWS’s current pricing page or calculator with your actual region, instance, disk, and bitrate assumptions before deployment.

Bitrate affects data transfer directly: a higher sustained output sends more data over time. Transcoding can also require a larger instance than stream copy, changing compute cost. Include monitoring, storage, and any separate failover resources in the estimate rather than pricing only the smallest single host.

Or let it run in the cloud

If your goal is simply to keep uploaded prerecorded videos live on YouTube, StreamNeo is a managed alternative to operating EC2 and FFmpeg. Upload a recording or build a playlist, add your YouTube stream key once, and go live. StreamNeo loops the uploaded video from its cloud service, so nothing has to stay on at home. It is YouTube-only and does not stream from a camera.

  • Any uploaded quality up to 4K 60fps streams as made, at one flat price per slot, with no re-encode or quality tiers.
  • Automatic recovery is included if YouTube drops the stream.
  • The first day is free with no card; it is one free day per account.
  • Monthly: $9.99 per month. UPI and cards are supported in India; card checkout is available worldwide.

Start the free StreamNeo 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.

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

Leave a Reply

Your email address will not be published. Required fields are marked *

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.

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.