Hardware FixRecommendedDevice not working? Your driver may be the problemCheck updates for common hardware issues.Fix DriversHalloween DealsAmazon USHalloween week deals: useful picks before month-endAmazon US: current deals, useful picks and tech finds.Check DealsClean PCRecommendedOne scan can reveal what keeps slowing WindowsLook for cleanup and repair opportunities.Run Scan×
Skip to content
Mountain View desk5 min

How to Keep an FFmpeg YouTube Stream Alive with systemd Restart Policies

A practical guide to supervising FFmpeg with systemd, handling reconnects at the right layer, and troubleshooting YouTube streams that stop or restart in a loop.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Run FFmpeg as a long-running systemd service with Restart=on-failure and a measured RestartSec= delay. That brings FFmpeg back after an abnormal exit, but it does not fix a bad stream key, a rejected YouTube ingest, or an ongoing network or encoding problem. For stronger recovery, match the retry method to the failure: FFmpeg protocol reconnect options for supported inputs, FIFO muxer recovery for certain output interruptions, and systemd for a process that exits.

What systemd can—and cannot—recover

systemd supervises the FFmpeg process. If FFmpeg exits with a failure, systemd can wait for the configured delay and launch it again. Its service manual recommends Restart=on-failure for long-running services. Restart attempts are still subject to systemd start-rate limits, and repeated launches will not make a persistent error disappear. systemd.service(5)

As an Amazon Associate I earn from qualifying purchases.

Recovery happens at different layers:

  • Input connection: FFmpeg protocol reconnect options may retry a supported input connection.
  • Output connection: FFmpeg’s FIFO muxer has output recovery options for some interruptions.
  • Process exit: systemd can restart FFmpeg after it exits abnormally.

None guarantees uninterrupted playback for viewers. A restart policy cannot repair invalid credentials, a persistent upstream outage, an unsupported option, or a YouTube ingest configuration that rejects the stream.

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

Configure FFmpeg as a systemd service

This illustrative unit shows the main structure. Replace the executable path, input, encoding arguments, and destination with values for your machine and stream. It is a starting point, not a tested drop-in configuration; check your installed systemd and FFmpeg versions and validate option placement against your local FFmpeg build.

#1 Best Overall
CanaKit Raspberry Pi 4 4GB Starter PRO Kit - 4GB RAM
  • Includes Raspberry Pi 4 4GB Model B with 1.5GHz 64-bit quad-core CPU (4GB RAM)
  • Includes Pre-Loaded 32GB EVO+ Micro SD Card (Class 10), USB MicroSD Card Reader
  • CanaKit Premium High-Gloss Raspberry Pi 4 Case with Integrated Fan Mount, CanaKit Low Noise Bearing System Fan
  • CanaKit 3.5A USB-C Raspberry Pi 4 Power Supply (US Plug) with Noise Filter, Set of Heat Sinks, Display Cable - 6 foot (Supports up to 4K60p)
  • CanaKit USB-C PiSwitch (On/Off Power Switch for Raspberry Pi 4)
[Unit]
Description=FFmpeg YouTube stream
Wants=network-online.target
After=network-online.target

[Service]
Type=simple
ExecStart=/usr/bin/ffmpeg -re -i /path/to/input -c:v libx264 -c:a aac -f flv rtmps://example.invalid/live/STREAM_KEY
Restart=on-failure
RestartSec=5

[Install]
WantedBy=multi-user.target

The example uses a placeholder destination. Do not copy it as a working YouTube URL or put a real stream key in a unit file that other users can read. Store credentials using an appropriately protected configuration mechanism, and avoid exposing them in logs or published command output.

Choose a restart policy and delay

  • Restart=on-failure restarts after abnormal failure and is the systemd manual’s recommended choice for long-running services.
  • RestartSec=5 is an example delay, not a universal ideal. Measure a suitable delay for your stream and failure pattern rather than allowing rapid retries.
  • Restart=always is not a substitute for diagnosing exits. Pick a policy deliberately, based on whether a clean exit should also trigger another launch.

The basic loop is: FFmpeg fails, systemd waits for RestartSec, then attempts to start it again. If it fails too often in a short period, systemd’s start-rate limiting can leave the unit failed instead of retrying indefinitely. Understand StartLimitIntervalSec= and StartLimitBurst= as implemented by your systemd version before changing limits; unlimited rapid restarts are not a safe default. systemd.unit(5)

Rank #2
Raspberry SC15184 Pi 4 Model B 2019 Quad Core 64 Bit WiFi Bluetooth (2GB)
  • Broadcom BCM2711, quad-core Cortex-A72 (ARM v8) 64-bit SoC @ 1. 5GHz
  • 2. 4 GHz and 5. 0 GHz IEEE 802. 11b/g/n/ac wireless LAN, Bluetooth 5. 0, BLE
  • 2 × USB 3. 0 ports, 2 x USB 2. 0 Ports
  • 2 × micro HDMI ports supproting up to 4Kp60 video resolution
  • Micro SD card slot for loading operating system and data storage

Enable and inspect the service

Save the unit under a suitable system service name, then reload systemd’s unit definitions and enable/start the service using the appropriate systemctl commands for your unit. Confirm that the unit is active and inspect its logs before relying on it for a scheduled broadcast. The exact unit name and service-file location depend on your installation.

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

Use FFmpeg reconnect options only for supported inputs

FFmpeg’s protocol options distinguish conditions such as a disconnected connection, network connection errors, streamed inputs, retry limits, and end-of-file. Options such as reconnect, reconnect_on_network_error, reconnect_streamed, and reconnect_at_eof apply according to the input protocol’s support and behavior; they are not interchangeable universal switches. Consult the protocol documentation for the protocol you actually use and place options correctly for your FFmpeg build. FFmpeg Protocols Documentation

Rank #3
Raspberry Pi 4 Model B (2GB)
  • Broadcom BCM2711, Quad core Cortex-A72 (ARM v8) 64-bit SoC @ 1.5GHz
  • 1GB, 2GB, 4GB or 8GB LPDDR4-3200 SDRAM (depending on model)
  • 2.4 GHz and 5.0 GHz IEEE 802.11ac wireless, Bluetooth 5.0, BLE Gigabit Ethernet
  • 2 USB 3.0 ports; 2 USB 2.0 ports.
  • Raspberry Pi standard 40 pin GPIO header (fully backwards compatible with previous boards)

In particular, do not assume these input-side flags will reconnect an outgoing RTMP or RTMPS YouTube publisher. An input reconnect can help when a supported source disconnects; it does not supervise FFmpeg after the process exits, and it does not itself repair output-side publishing failures.

Consider FIFO muxer recovery for output interruptions

If FFmpeg remains alive but the output connection is interrupted, the FIFO muxer offers a different recovery layer. Its options include attempt_recovery and recovery_wait_time; its documented example uses -f fifo, -fifo_format flv, and recovery parameters for a generic RTMP destination. This is an output-side technique, distinct from systemd restarting the entire process. The example is generic RTMP guidance, not YouTube-specific validation, so check the current FFmpeg documentation and test your actual build and destination before depending on it. FFmpeg Formats Documentation: fifo

Rank #4
Vilros Raspberry Pi 4 Complete Starter Kit- Includes Raspberry Pi 4 Board, Fan Cooled Case, 64GB Preloaded Micro SD Card and More (4GB, Clear Transparent Case)
  • Vilros Complete Starter Kit for Pi 4 Includes Raspberry Pi 4 Model B Board and all the accessories you need to get started.
  • 9-PART KIT WILL HAVE YOU READY TO GET UP AND RUNNING: Kit Includes 1. Raspberry Pi 4 Model B Board 2. Case With Easy to connect Built-in fan 3. 64GB Micro SD card Preloaded with RP OS 4. Vilros Pi 4 Compatible Power Supply with Inline on/off switch (power supply color may vary white/black) 5. Micro HDMI to Standard HDMI cable (5ft) 6. Micro SD to USB adapter to reflash card if desired 7. Neoprene Storage Bag to store all parts when not in use 8. Set of 4 Heatsinks 9. Vilros QuickStart Guide instruction booklet for Pi 4
  • PASSIVE & ACTIVE COOLING: The included case is well-vented and the kit also includes a set of heatsinks with thermal stickers for easy application and a pre-installed fan to keep the board cool in any use.
  • CONVENIENT ACCESSORIES: The power supply features an inline on/off switch neoprene bag that holds and protects all the parts when not in use and the QuickStart guide is updated and written for Raspberry Pi 4.
  • IMPORTANT: Kit does NOT include Keyboard, Mouse or Monitor
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Check YouTube ingest and encoder settings

A service can restart successfully while YouTube continues to reject or drop its output. YouTube recommends RTMPS for Live ingest. Its encoder guidance specifies constant bitrate (CBR), recommends a 2-second keyframe frequency, and says the interval must not exceed 4 seconds. Supported video codecs listed in the guidance include H.264, H.265 (HEVC), and AV1; audio options include AAC and MP3. Choose a bitrate from YouTube’s current resolution- and frame-rate-specific table rather than treating one number as universal. YouTube Help: Choose live encoder settings, bitrates, and resolutions

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

YouTube’s instruction is direct: “Make sure to test before you start your live stream.” Test the full path to YouTube before the scheduled broadcast, including the stream key, protocol, codec, bitrate, keyframe interval, and the point at which the stream is meant to be live.

Best Value
CanaKit Raspberry Pi 4 4GB Basic Kit with PiSwitch (4GB RAM)
  • Includes Raspberry Pi 4 4GB Model B with 1.5GHz 64-bit quad-core CPU (4GB RAM)
  • CanaKit 3.5A USB-C Power Supply with Noise Filter (UL Listed) specially designed for the Raspberry Pi 4 (5-foot cable)
  • CanaKit USB-C PiSwitch (On/Off Power Switch)
  • Set of 3 Aluminum Heat Sinks for the Raspberry Pi 4

Troubleshoot repeated stops and restart loops

Symptom Likely layer What to check
The source disappears, but FFmpeg is still running Input Confirm that the input protocol supports the reconnect option you chose; inspect the input-specific error and retry behavior in FFmpeg’s protocol documentation.
The publishing connection fails while FFmpeg remains alive Output Inspect FFmpeg’s output error and YouTube’s stream status. Consider FIFO muxer recovery only if it fits the output failure and is supported by your FFmpeg build.
FFmpeg exits after an error Process Check the service journal and FFmpeg error output, then confirm the unit uses the intended restart policy and delay.
The service rapidly restarts, then stays failed systemd start-rate limiting or recurring failure Inspect the unit’s journal, identify the original FFmpeg error, and review your systemd version’s start-limit settings. Do not mask a persistent error by simply increasing retry frequency.
FFmpeg runs, but YouTube does not accept the stream Credentials, ingest, or encoding Verify the current stream key and dashboard status, then validate RTMPS, codec, CBR bitrate, and keyframe settings against YouTube’s current guidance.

Use journalctl -u <unit> to inspect the service journal, replacing <unit> with the actual service name. Check FFmpeg’s own logs as well: systemd explains whether the process was restarted, while FFmpeg’s error output is needed to identify why it stopped or lost output. Keep stream keys out of copied logs.

Or let it run in the cloud

If maintaining FFmpeg, systemd, and a host is more work than you want, StreamNeo keeps a YouTube channel live 24/7 from uploaded videos: upload a recording or make a playlist, add your YouTube stream key, and go live. Nothing has to stay on at home; it streams the uploaded video as made, up to 4K 60fps, at one price per slot for any quality; and it automatically recovers if YouTube drops the stream. The first day is free with no card. Monthly pricing is $9.99 per month. See StreamNeo or its plans. Start your free day with StreamNeo.

Quick Recap

Bestseller No. 1
CanaKit Raspberry Pi 4 4GB Starter PRO Kit - 4GB RAM
CanaKit Raspberry Pi 4 4GB Starter PRO Kit - 4GB RAM
Includes Raspberry Pi 4 4GB Model B with 1.5GHz 64-bit quad-core CPU (4GB RAM); Includes Pre-Loaded 32GB EVO+ Micro SD Card (Class 10), USB MicroSD Card Reader
$159.99
Bestseller No. 2
Raspberry SC15184 Pi 4 Model B 2019 Quad Core 64 Bit WiFi Bluetooth (2GB)
Raspberry SC15184 Pi 4 Model B 2019 Quad Core 64 Bit WiFi Bluetooth (2GB)
Broadcom BCM2711, quad-core Cortex-A72 (ARM v8) 64-bit SoC @ 1. 5GHz; 2. 4 GHz and 5. 0 GHz IEEE 802. 11b/g/n/ac wireless LAN, Bluetooth 5. 0, BLE
$92.97
Bestseller No. 3
Raspberry Pi 4 Model B (2GB)
Raspberry Pi 4 Model B (2GB)
Broadcom BCM2711, Quad core Cortex-A72 (ARM v8) 64-bit SoC @ 1.5GHz; 1GB, 2GB, 4GB or 8GB LPDDR4-3200 SDRAM (depending on model)
$83.00
Bestseller No. 5
CanaKit Raspberry Pi 4 4GB Basic Kit with PiSwitch (4GB RAM)
CanaKit Raspberry Pi 4 4GB Basic Kit with PiSwitch (4GB RAM)
Includes Raspberry Pi 4 4GB Model B with 1.5GHz 64-bit quad-core CPU (4GB RAM); CanaKit USB-C PiSwitch (On/Off Power Switch)
$139.99

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 *

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

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
PC Slower Than It Used to Be?Free scan - under a minute
Crashes, No Sound, or Screen Glitches?Free driver 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.