Run FFmpeg as a foreground process on a Linux EC2 instance and let systemd start it at boot and restart it after process failures. You will need a YouTube channel enabled for live streaming, a media source, an FFmpeg build with the required codecs and protocol support, and secure handling of your YouTube stream key. This setup can recover from an FFmpeg crash; a single EC2 instance does not guarantee an uninterrupted stream.
How the EC2-to-YouTube setup works
The host reads a local video file, FFmpeg sends the resulting stream to YouTube’s ingest endpoint, and systemd supervises FFmpeg as a long-running service:
- EC2 Linux instance: supplies compute, storage, and network access.
- Media source: a local file or another input FFmpeg can read.
- FFmpeg: copies compatible streams or encodes the source into a format and bitrate suited to YouTube Live.
- YouTube Live: receives the encoder connection at the stream URL using the stream key as a publishing credential.
- systemd: starts FFmpeg at boot and can restart it when the process exits abnormally.
“24/7” describes the intended operation, not a guarantee: this arrangement still depends on the instance, source file, network path, credentials, and YouTube accepting the stream.
What you need before configuring FFmpeg
Enable YouTube Live and retrieve the ingest details
- Confirm that live streaming is enabled for your YouTube channel. YouTube says first-time enablement may take up to 24 hours.
- In YouTube Live Control Room, create or select a stream and copy the ingest URL and stream key shown for the encoder.
- Prefer the RTMPS endpoint where your FFmpeg build supports it. YouTube recommends RTMPS; it is RTMP carried over TLS/SSL. Do not assume that a displayed default RTMP address is the encrypted endpoint.
- Treat the stream key like a password. Do not put a real key in a public script, shell command you plan to share, or world-readable unit file. If a key is compromised, an authorized channel owner or manager can reset it.
Check that the stream URL and key match the selected YouTube stream. A valid FFmpeg process cannot publish if the account is restricted, the key is invalid, or the endpoint is wrong.
#1 Best Overall
- 【Ryzen 5 3500U Processor】KAMRUI Essenx E2 Mini PC is equipped with AMD Ryzen 5 3500U (4-cores/8-threads, up to 3.7GHz) with integrated Radeon Vega 8 Graphics(1200MHz, 8 Core). The 3500U CPU operates at a base frequency of 2.1 GHz and a Boost frequency of 3.7 GHz. This DDR supports upgradable up to 32GB, SSD supports up to 2TB.(NOT INCLUED), KAMRUI E2 3500U Mini PC is ideal for light office work and home entertainment. KAMRUI E2 3500U is more than 35% more powerful and smoother in operation than the Intel N150, 33% faster than Intel N95, 28% performance boost over Intel i3-10110U, and 42% stronger processing power than AMD Ryzen 3 3200U.
- 【16GB DDR4 & 256GB SSD】The KAMRUI E2 mini computers is equipped with 16GB DDR4(Expandable up to 32GB) for faster multitasking and smooth application switching. 256GB M.2 SSD ensures fast startup times,fast file transfers and plenty of storage space,eliminating slow loading times and ensuring fast responsiveness.Storage space can RAM supports up to 32 GB, SSD supports up to 2TB (Not included)make file storage easier.
- 【4K Dual Display & USB 3.2 Type-A Port】KAMRUI E2 3500U mini desktop pc is equipped with an HDMI 2.0+DP 1.4 interfaces for faster transmission, Support Dual 4K@60Hz Display, E2 mini desktop computers is ideal for visual home entertainment, home office, conference rooms, etc. USB3.2 Gen1 Type-A Port×2 with a transfer speed of up to 5Gbps (10 times faster than USB 2.0) for efficient data transfer. The RJ45 1000M Gigabit Ethernet Port ensures a stable network connection.
- 【WiFi+Bluetooth stable connection】The Kamrui E2 micro pc have reliable and stable wireless connection, open websites in seconds, watch movies without buffering and download files smoothly, connect your monitor from WiFi or Ethernet, use a wireless keyboard and mouse through bluetooth, which will be powerful workstation for you.
- 【Versatile Ports】This KAMRUI E2 Small pc is equipped with HDMI 2.0×1(4K@60Hz)、DP1.4×1(4K@60Hz)、Gigabit Ethernet Port (RJ45, 10/100/1000Mbps) ×1、USB3.2 Gen1 Type-A Port×2(5Gbps)、USB2.0 Type-A Port×2、3.5mm Audio Jack ×1、DC In ×1、Power Button ×1
Prepare the EC2 host and network
- Choose the EC2 Region, instance type, operating system, storage, and network design for the source and encoding load. There is no universally suitable instance size established for every media file and encoding profile.
- Install an FFmpeg build that supports the codecs and output protocol you intend to use. Build capabilities vary; verify the installed build rather than assuming RTMPS or a particular encoder is available.
- Keep inbound access to a minimum. Restrict SSH to an administrator’s IP range or use a managed access method. A normal outbound encoder connection does not require opening an inbound RTMP port on the instance.
- Verify outbound access, DNS resolution, subnet routing, and any network ACL or host firewall rules needed to reach YouTube. AWS security groups are stateful, so return traffic for an allowed outbound connection is permitted.
Choose compatible video and audio settings
YouTube’s current encoder guidance lists RTMP/RTMPS, H.264, H.265, and AV1 video, constant bitrate (CBR), and frame rates up to 60 fps for conventional SDR live streaming. It recommends a two-second keyframe interval and says the interval should not exceed four seconds. Match the bitrate to the codec, resolution, and frame rate you actually send; do not treat a figure for one profile as universal.
| H.264 profile in YouTube’s published recommendations | Recommended video bitrate | Audio guidance |
|---|---|---|
| 1080p at 30 fps | 5 Mbps | Stereo: 128 Kbps; sample rate: 44.1 kHz |
| 1080p at 60 fps | 17 Mbps | |
| 720p at 30 fps | 8 Mbps | Stereo: 128 Kbps; sample rate: 44.1 kHz |
| 720p at 60 fps | 8 Mbps |
These are YouTube Help recommendations, checked 2026-10-03; that access date is not a claimed publication date. YouTube’s table distinguishes minimum and recommended values and varies by codec, so consult the row and column for the chosen profile. YouTube advises choosing a quality your connection can sustain, testing before going live, and watching stream health.
Stream copy or transcode?
| Choice | Use it when | Trade-off |
|---|---|---|
Stream copy (-c copy) |
The source codecs and properties already suit YouTube’s ingest requirements and you do not need filters or resizing. | Avoids decoding and re-encoding, so it is fast and does not introduce another generation of encoding loss. It cannot fix an incompatible codec, resolution, frame rate, or other source property. |
| Transcode | You need to change codec, resize, apply filters, control output bitrate, or make an incompatible source suitable for the chosen profile. | Uses more CPU and can reduce quality through lossy encoding. Confirm that the instance can sustain the chosen encode settings. |
FFmpeg’s options apply according to their position relative to inputs and outputs. Put input-specific options before the input they affect, and output options before the output they affect. Test the exact source, FFmpeg build, and YouTube preview before relying on the service.
Rank #2
- 【Great power in a small computer】Get fast performance from the AMD Ryzen 5 3500U CPU (2.1GHz-3.7GHz, 4 Cores 8 Threads) inside this mini pc, TDP 15W up to 25W. It's perfect for all your home office and business use, like daily computing, web browsing, and smooth media streaming. This small desktop computer handles everyday tasks easily and quietly.
- 【Work on many things at once with lots of storage】This mini PC comes with 16GB of fast DDR4 RAM (expandable up to 32GB), allowing you to smoothly run multiple programs, dozens of browser tabs, and large files all at once. It also features a spacious 512GB NVMe SSD that provides ample storage and delivers dramatically faster boot-ups, app launches, and file transfers compared to a traditional hard drive.
- 【See everything clearly on one or two 4K screens】Connect one or two monitors for more space to work or play. Dual HDMI ports on this mini pc support super sharp 4K Ultra HD video. It's great for doubling your work area for business or watching movies in high definition.
- 【Fast modern connections in a tiny box】Enjoy a better and more stable internet connection with the latest WiFi 6. Use Bluetooth 5.3 to connect wireless headphones, keyboards, and mice without wires. This small pc is very compact to save desk space and has extra USB ports (USB 2.0×2, USB 3.0×2, Type-c 2.0×1, Type-c 3.2 full featured×1, HDMI×2) for your printer, webcam, or other computer accessories.
- 【Reliable Warranty and Support】We provides 1 year warranty for each Mini computers. So you don't need to worry about any product problems. If you have any questions about the product, please contact our customer service, we will provide 24-hour professional technical support and serve you at any time.
Make a local file repeat as a live input
For a prerecorded file, FFmpeg can read at native playback speed, loop the input, and send it to the publish URL. The following is a command template, not a tested deployment command. Replace the placeholders with the paths and full publish URL from your YouTube encoder setup; never substitute a real key into a command saved in shell history.
Do these 3 things before closing this tab:
1Fix the driver behind crashes, sound loss and screen glitches2Repair Windows errors before they cause bigger problems3Scan for outdated or missing drivers - takes under a minuteffmpeg -re -stream_loop -1 -i "/srv/stream/video.mp4" -c copy -f flv "<FULL_YOUTUBE_PUBLISH_URL>"
-re reads the file at its intended rate rather than sending it as fast as storage can be read; -stream_loop -1 repeats the input indefinitely. This copy example works only if the source streams are compatible with YouTube ingest. FFmpeg’s FLV muxer is shown as a conventional RTMP-family output container; check the installed FFmpeg build and selected endpoint for actual support.
Example H.264 transcode for 1080p30
If the source needs encoding, an example H.264 output targeting YouTube’s 1080p30 recommended bitrate is:
Rank #3
- 【AMD Ryzen 3 5300U CPU: Outperforms N150 & 3500U】 BOSGAME E5 mini PC is powered by the TSMC 7nm FinFET architecture AMD Ryzen 3 5300U processor (4 Cores, 8 Threads, up to 3.8GHz boost, 6MB total cache). Compared to low-end Intel N150 or 3500U chips which only have 4 single threads and throttle under load, the 5300U delivers over 30% faster multi-core speed. Run 30+ browser tabs, large Excel sheets, and Zoom meetings simultaneously without system lag.
- 【8GB DDR4 RAM & 256GB NVMe SSD Storage】 Installed with high-speed 8GB DDR4 dual-channel memory and a fast 256GB M.2 2280 SSD, eliminating slow boot times and application loading delays. To accommodate growing data requirements, the upgradeable hardware design features dual SODIMM slots that allow you to expand memory up to 64GB RAM, ensuring smooth operation during heavy multitasking.
- 【High-Capacity Dual M.2 SSD Storage Expansion】 Never worry about running out of space for your business files. In addition to the pre-installed 256GB system drive, the motherboard houses an extra empty internal M.2 2280 NVMe PCIe 3.0 slot. This allows you to easily add a second solid-state drive for up to an additional 2TB of storage capacity (upgrades not included) without needing to remove or reinstall the original operating system.
- 【Radeon 6-Core Graphics & Triple 4K Displays】 Integrated with official AMD Radeon Graphics (6 Graphics Cores, 1500 MHz frequency) for casual gaming, photo editing, and crisp 4K media decoding. Featuring 1x HDMI 2.0 port, 1x DisplayPort, and 1x Full-Function Type-C port, the E5 outputs true 4K@60Hz resolution to three monitors at once. This multi-screen setup eliminates constant window-switching for traders, programmers, and office workers.
- 【Dual 2.5GbE LAN Ports for Advanced Networking】 Experience fast wired network transmission speeds up to 2500Mbps without lagging or buffering. The integration of dual 2.5 Gigabit Ethernet ports (powered by Realtek RTL8125 controller) makes this compact computer an exceptional hardware choice for tech enthusiasts. Easily configure it into software routers, hardware firewalls (pfSense, OpnSense), home NAS servers, or local homelabs.
ffmpeg -re -stream_loop -1 -i "/srv/stream/video.mp4"
-c:v libx264 -preset veryfast -r 30 -g 60 -keyint_min 60 -sc_threshold 0
-b:v 5M -minrate 5M -maxrate 5M -bufsize 10M
-c:a aac -b:a 128k -ar 44100 -ac 2
-f flv "<FULL_YOUTUBE_PUBLISH_URL>"
This illustrates a two-second GOP at 30 fps and a CBR-style bitrate target; the 5 Mbps video and 128 Kbps stereo audio values correspond to YouTube’s 1080p30 H.264 recommendation and stereo audio guidance. The libx264 encoder must exist in your FFmpeg build. The veryfast preset is an example starting point, not a universal performance recommendation. Confirm CPU headroom, visual quality, audio, output protocol support, and YouTube stream health with a private or unlisted test before using this profile live. For another resolution, frame rate, or codec, choose settings for that profile rather than reusing these values unchanged.
Keep the stream key out of the unit file
A publish URL commonly contains the key, so protect the complete URL just as carefully as the key itself. Avoid storing it in a publicly readable script or directly in ExecStart=. One practical pattern is to use a restricted systemd credential and a small root-owned wrapper that reads it at launch, constructs the publish URL in memory according to the exact URL/key format shown in Live Control Room, and then runs FFmpeg in the foreground. Adapt the mechanism to the systemd and operating-system versions on your host.
Recommended Free Tools
- Create a dedicated service account and a protected credential file accessible only to administrators. Do not put the key in shell history or enable shell tracing in the wrapper.
- Have the wrapper read the credential from the systemd-provided credential directory, construct the full publish URL without printing it, and execute FFmpeg with the input and output options appropriate for your source. Keep the wrapper readable only by administrators and ensure it does not log the secret.
- Restrict access to the EC2 host: the final publishing URL must be passed to FFmpeg for it to connect, so users with sufficient access to inspect the process or host may be able to discover it. Limit administrative access and rotate the key if exposure is suspected.
The snippets below show the supervision shape; they are not a drop-in unit or wrapper. Set the actual credential source path and wrapper path for your distribution, and ensure the wrapper runs the FFmpeg process directly in the foreground rather than detaching it.
Rank #4
- Office Gaming Mini PC - UPGRADED GMKtec Nucbox M5 Ultra Series is equipped with the powerful AMD Ryzen 7 7730U processor, 8 Cores/16 Threads, Base 2.00GHz (Power Saving Quiet Mode) with Turbo Boost up to 4.50GHz (Performance Mode) in BIOS settings, Based on the ZEN 3+ architecture, this small but powerful mini pc delivers satisfying results in productivity, office work, and gaming. 35% Performance increase over AMD Ryzen 5 7430U/ Ryzen 7 5700U, 5600U, 5560U, 5500U.
- 16GB DDR4 RAM & 256GB PCIe SSD - Installed with DDR4 16GB RAM (1x16GB), the Nucbox M5 Ultra mini pc support expansion to 64GB RAM. Featured with 256GB M.2 2280 PCIe 3.0 SSD, support dual slot expansion to 4TB SSD. (Upgrades not included)
- DUAL NIC LAN 2.5G RJ45 - Fast Network Speeds: Enjoy up to 2500Mbps data transmission speed without worrying about lagging. Ideal for working, gaming, and surfing the internet. Great for Untangle, Pfsense or as a server office PC.
- Mini Desktop Computer with 4K Triple Screen Display - Nucbox M5 Ultra integrates AMD Radeon Graphics 8 Cores 2000 MHz GPU to deliver powerful graphics processing power to easily handle the demands of complex design software, 4K@60Hz UHD video editing, and playback. It can connect to 3 display screens simultaneously.
- Fast Internet WiFi 6E + BT5.2 Connection - GMKtec Mini PC with WiFi-6E Wireless, have 2.5G/5G/6G triple band, more faster and lower latency. Bluetooth 5.2 allowing you more quickly to connect other wireless devices (headset, mouse, keyboard, etc.) Interface features 2*USB3.2 ports, 2*USB2.0 ports, 1*HDMI 2.0 port(4K@60Hz), 1*USB-C port(PD/DP/DATA), 1*DP Port, 1*Audio 3.5mm (HP&MIC), 1*DC Power Port.
[Unit]
Description=YouTube live stream via FFmpeg
Wants=network-online.target
After=network-online.target
[Service]
Type=exec
User=streamer
LoadCredential=stream-key:/etc/streamer/stream-key
ExecStart=/usr/local/bin/youtube-stream-wrapper
Restart=on-failure
RestartSec=10
[Install]
WantedBy=multi-user.target
Type=exec lets systemd track the service process after successful execution setup. Restart=on-failure asks systemd to restart FFmpeg when it exits abnormally; RestartSec=10 is an example delay, not a measured or universally correct value. Confirm that your systemd version supports the chosen directives and follow the distribution’s unit conventions. Use least privilege for the service account and credential file permissions.
Install, enable, and test the service
- Save the unit under the distribution’s system service directory, commonly
/etc/systemd/system/youtube-stream.service. Save the wrapper at the path used byExecStart=, then set restrictive ownership and permissions on the credential and wrapper. - Reload unit definitions:
sudo systemctl daemon-reload. - Start the service for an initial test:
sudo systemctl start youtube-stream.service. - Check whether FFmpeg is running and inspect the latest service logs:
sudo systemctl status youtube-stream.serviceandsudo journalctl -u youtube-stream.service -n 100 --no-pager. - In YouTube Live Control Room, check the preview and stream-health indicators; verify both audio and video. YouTube recommends a preflight test and monitoring.
- After a successful controlled test, enable it at boot:
sudo systemctl enable youtube-stream.service. For a real recovery test, stop FFmpeg deliberately and confirm that the service restarts and reconnects as expected; do not assume a successful process restart proves YouTube playback is healthy.
Starting a service after a host reboot still depends on the instance booting, the network becoming usable, the source being available, and credentials remaining valid. network-online.target provides ordering against the operating system’s network-online mechanism; it does not prove that YouTube is reachable.
What systemd restart can and cannot recover
| Failure | What to expect | What to add or check |
|---|---|---|
| FFmpeg exits with an error while systemd and the host are working | Restart=on-failure can start another process after the configured delay. |
Read the journal to identify and fix the cause; repeated failures can create a restart loop. |
| FFmpeg is alive but playback is stalled or unhealthy | A restart policy may do nothing because the process has not exited. | Monitor YouTube stream health and add separate process or stream-health monitoring and alerting. |
| Source file is missing or unreadable, stream key is invalid/reset, or egress is blocked | Restarting alone cannot repair the underlying condition. | Check file permissions and path, credential validity, DNS, routes, firewall rules, and the YouTube account or stream state. |
| CPU is insufficient, EC2 host fails, or a wider regional/network event occurs | A single instance and its systemd service do not provide host or region redundancy. | Measure resource use and design a separately monitored, tested failover approach if the availability requirement justifies it. |
Troubleshoot common startup and playback failures
- The service repeatedly exits: inspect
journalctl -u youtube-stream.servicefor FFmpeg’s error output. Check the source path, file read permissions, FFmpeg arguments, installed codecs, and whether the chosen output protocol is supported by the build. - YouTube does not receive the stream: verify the stream URL and key from the selected Live Control Room stream, confirm that outbound network access and DNS work, and ensure the account can currently go live. Do not open an inbound RTMP port as a substitute for outbound reachability.
- The service starts but YouTube reports poor stream health: check that sustained upload capacity exceeds the chosen output bitrate with room for network variation, confirm the correct codec and profile, use CBR, and maintain a two-second keyframe interval (not over four seconds). Lower the output demand or choose a suitable profile if the path cannot sustain it.
- The video or audio is incompatible or missing: inspect the input streams and compare them with the selected ingest profile. Use stream copy only when compatible; otherwise transcode and verify audio codec, stereo settings, sample rate, frame rate, and resolution.
- The service does not restart: check
systemctl status, unit syntax, whether the process is actually exiting, and the configured restart policy. Restart directives do not repair a process that remains alive but frozen or a stream YouTube considers unhealthy. - Playback stops after a reboot: confirm the unit is enabled, the source and credential are present at boot, networking is available, and the stream reconnects successfully. Check both systemd logs and YouTube’s live preview; a running service alone is not proof of a healthy live stream.
Plan for live duration and archiving separately
YouTube’s encoder setup guidance says streams under 12 hours are automatically archived. That statement does not establish what happens to a stream that exceeds 12 hours. If you need a durable recording, plan and validate a separate recording or segmentation workflow and check YouTube’s current limits rather than assuming an indefinite live stream will become a complete archive.
Best Value
- WHY CHOOSE CORE I3-10110U - Better single-core performance: The Core i3-10110U has a higher peak boost clock (4.1 GHz) compared to the Ryzen 3 4300U and the Intel Alder Lake N150 series, making it better for tasks that rely on fast single-core performance (e.g., web browsing, office apps). Better multi-thread performance via Hyper-Threading: the Core i3-10110U offers better performance in multi-threaded workloads compared to the Ryzen 3 4300U, especially for light productivity work and multitasking.
- 16GB RAM MEMORY & 512GB SSD STORAGE - GMKtec Nucbox G3 PRO mini pc is prebuilt with 16GB DDR4 RAM SO-DIMM DUAL CHANNEL, you will enjoy a speedier experience with Built-in 512GB M.2 Hard Drive. Our mini desktop pc boots up in seconds, work on multiple browser tabs, software applications and quickly transfers files. There is a primary slot and secondary expansion storage. Primary slot is M.2 2280 PCIE/SATA and secondary slot is M.2 2242 SATA .
- RICH INTERFACE - Nucbox core i3 mini computer is equipped with USB 3.2*4,up to 5Gbps/S, HDMI(4K@60Hz)×2, 3.5mm Audio Jack. Supports WiFi 6, and Gigabit Ethernet RJ45 2.5GbE network connectivity, Bluetooth 5.2. This Mini PC supports multiple device connection and can be used with servers, monitoring equipment, office equipment, displays, projectors, televisions, etc.
- 4K DUAL SCREEN DISPLAY - Mini desktop computer is equipped with upgraded Intel Graphics(max 1000MHz), supports 4K video playback and AV1 decoding, connect the pc with a projector as a home theatre, enjoy a variety of entertainments. Two HDMI 2.0 ports allows you to multi-task efficiently on two 4K@60Hz displays.
- UPGRADED COOLING FAN - The G3 PLUS has upgraded the cooling fan to reduce fan noise and thermals. We are using an upgraded thermal paste as well to help reduce heat on the CPU.
Estimate EC2 cost from your actual configuration
A continuously running instance incurs ongoing compute usage, and outbound data transfer may add cost. The total depends on the AWS Region, instance family and size, operating system, storage, and the amount of data sent at your selected bitrate; there is no defensible universal monthly total for a 24/7 stream without those assumptions. AWS pricing and any transfer allowance depend on current pricing, eligibility, and geography. Use AWS’s current pricing information or calculator with your own deployment choices before estimating a bill.
Or let it run in the cloud
If you want the YouTube stream without maintaining an EC2 host, StreamNeo is a managed alternative: upload a recording, add your YouTube stream key, and go live. It loops uploaded videos from the cloud; it does not stream from a camera.
- Your computer and home connection do not have to stay on.
- One price per slot covers any uploaded quality up to 4K 60fps, without re-encoding or quality tiers.
- It automatically recovers if YouTube drops the stream.
- The first day is free with no card required.
Monthly: $9.99 per month. StreamNeo streams to YouTube only. See StreamNeo or plan details, then start the free day.
Quick Recap
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.
The Tool Desk
Outbyte Driver Updater FREEScan for outdated or missing drivers - takes under a minuteDriver Scan →Outbyte PC Repair FREERepair Windows errors before they cause bigger problemsFix Now →

