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

Use a system-level systemd service to start FFmpeg at boot and restart it after an unexpected process exit. That keeps the job independent of an SSH session—but it does not fix a bad stream key, an unavailable input file, a network failure, or a YouTube broadcast that has ended. Check both the local service logs and YouTube Live Control Room to confirm the stream is actually healthy.

What this setup does—and what it does not

A systemd service manages FFmpeg as a background process: it can launch the command at boot, apply a restart policy if the process exits, and send output to the system journal. It is useful for a Linux host that should keep sending a file or other input to YouTube without an interactive shell.

It is not an end-to-end guarantee of a live broadcast. systemd sees whether the local process is running; YouTube sees whether it is receiving and accepting a stream. A process can remain active while the input is stalled or the remote broadcast has a configuration or health problem.

Prepare the Linux host and YouTube stream

Confirm the local requirements

  • Install FFmpeg and confirm its path; the example below assumes /usr/bin/ffmpeg.
  • Create a dedicated Linux account for streaming. The examples assume a user and group named stream.
  • Choose a readable input file and a working directory. The example uses /srv/stream.
  • Make sure the host has enough upload capacity for the chosen bitrate and can remain powered and connected to the internet.

These are example values, not universal defaults. Substitute your actual FFmpeg path, account, directory, input, and output settings. The account running FFmpeg must be able to read the input and any required configuration files.

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

Get the current YouTube ingest details

In YouTube Live Control Room, retrieve the RTMPS ingest address and the stream key assigned to the broadcast. Use the current address shown there rather than copying a server URL from an old tutorial. YouTube describes RTMPS as RTMP carried over TLS/SSL and recommends it for encrypted ingestion: Encrypt your stream using RTMPS.

YouTube’s Live Streaming API distinguishes the ingestion address from the stream name/key; a tool may combine them as STREAM_URL/STREAM_NAME. The API also exposes stream and health states, which are separate from whether FFmpeg is running locally: LiveStreams | YouTube Live Streaming API.

Store the stream key outside the service file

Do not place the real key in a broadly readable unit file, a published command, or shell history. Put it in a root-controlled environment file, restrict its permissions, and grant access only to the service that needs it. For example, create /etc/ffmpeg-stream.env as an administrator and set restrictive permissions:

sudo install -o root -g root -m 600 /dev/null /etc/ffmpeg-stream.env
sudoedit /etc/ffmpeg-stream.env

Enter the ingest URL and key as environment variables, without quotes around a simple value:

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.
YOUTUBE_URL=rtmps://CURRENT-URL-FROM-LIVE-CONTROL-ROOM/STREAM-KEY

Replace the example value with the exact current RTMPS URL and key from Live Control Room. Do not paste a real key into logs, screenshots, support posts, or a tutorial. If your FFmpeg command or wrapper expects the URL and key separately, adapt the environment variables and command accordingly.

Create the systemd unit

Create /etc/systemd/system/ffmpeg-youtube.service as root. This representative unit assumes a looping file at /srv/stream/loop.mp4 and an FFmpeg command using an environment variable for the output destination:

Rank #3
CanaKit Raspberry Pi 5 Starter Kit PRO - Turbine Black (128GB Edition) (8GB RAM)
  • Includes Raspberry Pi 5 with 2.4Ghz 64-bit quad-core CPU (8GB RAM)
  • Includes 128GB Micro SD Card pre-loaded with 64-bit Raspberry Pi OS, USB MicroSD Card Reader
  • CanaKit Turbine Black Case for the Raspberry Pi 5
  • CanaKit Low Noise Bearing System Fan
  • Mega Heat Sink - Black Anodized
[Unit]
Description=FFmpeg YouTube live stream
After=network-online.target
Wants=network-online.target

[Service]
Type=simple
User=stream
Group=stream
WorkingDirectory=/srv/stream
EnvironmentFile=/etc/ffmpeg-stream.env
ExecStart=/usr/bin/ffmpeg -re -stream_loop -1 -i /srv/stream/loop.mp4 -c:v libx264 -preset veryfast -b:v 5M -maxrate 5M -bufsize 10M -g 60 -c:a aac -b:a 128k -f flv ${YOUTUBE_URL}
Restart=on-failure
RestartSec=5
TimeoutStopSec=30
KillSignal=SIGINT

[Install]
WantedBy=multi-user.target

This is a starting shape, not a universal encoding recipe. Confirm the file path and permissions, the installed FFmpeg build and codecs, the desired resolution and frame rate, and the current destination URL. The example’s 5 Mbps video setting is not suitable for every resolution, frame rate, codec, or connection. If your media has no audio, or you use a different source or encoding approach, change the arguments to match it.

FFmpeg documents real-time pacing for file input with -re and an FLV output to an RTMP destination. Its example is ffmpeg -re -i myfile -f flv rtmp://myserver/live/mystream; adapt it to YouTube’s current RTMPS destination and your stream settings: FFmpeg Protocols Documentation.

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

Choose encoding settings for the actual stream

YouTube’s current encoder guidance lists RTMP/RTMPS; H.264, H.265/HEVC, or AV1; up to 60 fps; constant bitrate (CBR); and AAC or MP3 audio. It recommends a two-second keyframe interval and says not to exceed four seconds. The following H.264 examples are YouTube recommendations accessed in 2026, not independent performance measurements:

Rank #4
Raspberry Pi 4 Computer Model B 8GB Single Board Computer Suitable for Building Mini PC/Smart Robot/Game Console/Workstation/Media Center/Etc.
  • powful cputhe cpu of the raspberry pi 4 model b adopts the latest arm cortex-a72 architecture, which is also used in high-performance smartphones, and has evolved into a real pc.the operating clock has been changed from pi3's 1.2ghz to 1.5ghz, and the speed has become a different dimension with the updated architecture.
  • video output/gputhe on-board gpu of the raspberry pi 4 supports 4kp@60 and newly supports h.265 decoding, opengl es 3.0, etc.as for the video output, two micro hdmis with smaller connectors are installed, and the raspberry pi 4 also supports dual screen output.
  • usb 3.0with a new soc, the speed of the raspberry pi 4 around i/o has been improved, and finally usb 3.0 is supported.usb boot is faster and more convenient.
  • network&bluetoothgigabit ethernet (wired lan) has also been significantly speeded up from 300mbps of pi 3b + to 1000mbps (logical value).in addition, bluetooth supported version has been upgraded to 5.0, and the transfer speed of pi 4 has been doubled.
  • power input connectorthe power input connector of the raspberry pi 4 has been changed to usb type c. it is easier to use than micro usb and can supply a larger current reliably.the power requirement of raspberry pi 4 model b is 5v 3.0a, which is higher than the previous model.
Output example YouTube-listed minimum bitrate YouTube-listed recommended bitrate
1080p at 30 fps, H.264 5 Mbps 14 Mbps
720p at 30 fps, H.264 3 Mbps 8 Mbps

YouTube also recommends 128 Kbps stereo audio. Match the keyframe interval to the output frame rate: for example, 60 frames at 30 fps is two seconds, while a 60 fps stream needs a different frame count for the same interval. Set a bitrate the host’s upload connection can sustain, and test with similar audio and motion before relying on the stream. Consult YouTube’s current table for other codecs, resolutions, and frame rates: Choose live encoder settings, bitrates, and resolutions.

Load, enable, and start the service

  1. Check the unit and permissions. Confirm that the service account can read the input file and that the environment file is protected and available to the service.
  2. Reload systemd’s unit files: sudo systemctl daemon-reload.
  3. Enable the service at boot and start it now: sudo systemctl enable --now ffmpeg-youtube.service.
  4. Inspect the local service state: sudo systemctl status ffmpeg-youtube.service.
  5. Inspect recent FFmpeg output: sudo journalctl -u ffmpeg-youtube.service -n 100 --no-pager. To follow new output as it arrives, use sudo journalctl -u ffmpeg-youtube.service -f.
  6. Check the remote broadcast. Open YouTube Live Control Room and verify the preview and stream-health messages. Do not treat an active systemd process alone as proof that viewers can see a healthy stream.

Understand restart behavior and failure boundaries

Restart=on-failure asks systemd to restart the service when FFmpeg exits unsuccessfully. RestartSec=5 inserts a delay before the restart. This helps with an unexpected process exit, but a recurring configuration or dependency failure can create a repeating failure loop rather than a working broadcast.

  • FFmpeg exits immediately: inspect the journal for an invalid option, missing file, permission error, unavailable encoder, or malformed destination.
  • FFmpeg runs but YouTube reports an error: verify the current RTMPS address and key, output format, and encoder settings in Live Control Room.
  • The input or network is unavailable: systemd may restart FFmpeg, but it cannot make a missing file readable or restore a broken network path.
  • The broadcast has ended or been rejected: restarting the local process does not necessarily restore the YouTube broadcast. Check its state and start or configure a valid broadcast in Live Control Room as needed.

YouTube’s API documents states such as active, ready, inactive, and error, as well as health states and configuration issues. These remote indicators answer a different question from systemctl status.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Best Value
SANOOV Raspberry Pi 5 4GB Kit, 4GB RAM Single Board Computer with Active Cooler and ABS Case, Complete Raspberry Pi 5 Starter Kit for IoT Robotics Retro Gaming
  • All-in-One Complete Kit: This SANOOV RPi 5 bundle comes with Raspberry Pi 5 4GB RAM single board, active cooler, durable ABS case and screwdriver. No extra parts needed, ready to use right out of the box for beginners and hobbyists
  • Powerful Single Board Computer: Equipped with 4GB RAM and high-performance processor, delivers fast running speed for 4K playback, AI projects, programming and daily computing tasks. SANOOV for raspberry pi 5 4GB is equipped with broadcom 64 quad-core Arm Cortex A76 processor with gigabit ethernet and upgraded with IEEE 802.11ac Wi-Fi, Bluetooth 5.0 dual-band 2.4Ghz and 5Ghz and Power Over Ethernet (POE). Upgrading delivers 2-3 x speed vs Pi 4, redefining the experience
  • Efficient Active Cooler: Effectively lowers operating temperature and prevents performance throttling. Runs quietly even under long-time heavy load, ensures stable operation all day long. SANOOV RPi 5 4GB kit offer an active cooler, which combines an aluminium heatsink with a high-performance PWM fan. Active cooler is fully compatible with the Pi OS, which can effectively reduce the temperature of RPi5 and ensure its good performance during long-term high load operation
  • Sturdy ABS Protective Case: Well-fitted for Raspberry Pi 5 board, can be secured with 4 screws to effectively protect the Pi 5 motherboard from damage, reserves full access to all ports and buttons. SANOOV uses ABS material to produce the case, which has a softer texture and feel. Meanwhile, SANOOV case adopts a layered design for easy disassembly and installation. (Tip: The Case cannot install M.2 HAT Add on Board and Solid State Drive!)
  • Wide Application & Full Compatibility: Seamlessly compatible with official OS and mainstream peripheral accessories for Raspberry Pi 5. Whether you are a beginner, student, electronics hobbyist or professional developer, this all-in-one kit meets your diverse needs. It excels in IoT projects, robotics design, retro gaming devices, home media servers and other DIY creations. Backed by a large global community, you can easily find guides, technical support and shared projects online
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Troubleshoot common problems

Service fails to start

  • Run sudo systemctl status ffmpeg-youtube.service and sudo journalctl -u ffmpeg-youtube.service -n 100 --no-pager.
  • Check that /usr/bin/ffmpeg exists and that the unit’s input path is correct.
  • Confirm that the stream account can read the input file and traverse its parent directories.
  • After editing a unit file, run sudo systemctl daemon-reload before restarting it.

FFmpeg cannot connect or YouTube shows no healthy stream

  • Copy the current RTMPS URL and key from Live Control Room; do not rely on a hard-coded address from an old example.
  • Check that the protocol and server are both rtmps. YouTube’s troubleshooting guidance suggests trying port 443 for some SSL errors and checking whether the encoder build supports RTMPS: YouTube RTMPS guidance.
  • Inspect FFmpeg’s journal output for connection, TLS, authentication, or encoding errors, then separately check YouTube’s preview and health information.

The service restarts repeatedly

Use the journal to identify the first error rather than treating each restart as a separate fix. If the cause is a revoked key, unsupported option, missing media, or unreachable network, correct that cause before starting the service again. To stop a restart loop while investigating, run sudo systemctl stop ffmpeg-youtube.service.

Who should run this on their own host?

A systemd setup offers direct control over files, FFmpeg arguments, and the Linux environment. In return, you maintain the host, storage, power, operating system, network connection, and troubleshooting. If the host loses power or internet access, a local restart policy cannot keep the YouTube ingest going from that machine.

For a continuous stream, test the full path—including file playback, encoding, network upload, and YouTube health—before depending on it. A separate speed test can help assess upload capacity, but the usable rate should leave room for variation rather than sit at the connection’s limit.

Or let it run in the cloud

StreamNeo is an alternative if you want a YouTube stream to keep running without maintaining a Linux host: upload a recording or build a playlist, add your YouTube stream key, and go live. Nothing has to stay on at home; the uploaded video loops from the cloud. It streams the uploaded video to YouTube, not from a live camera.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  • Any quality up to 4K 60fps as uploaded, at one flat price per slot; no re-encode or quality tiers.
  • Automatic recovery if YouTube drops the stream.
  • The first day is free with no card, one free day per account.

The monthly option is $9.99 per month. See StreamNeo for service details, or start your free day.

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. 3
CanaKit Raspberry Pi 5 Starter Kit PRO - Turbine Black (128GB Edition) (8GB RAM)
CanaKit Raspberry Pi 5 Starter Kit PRO - Turbine Black (128GB Edition) (8GB RAM)
Includes Raspberry Pi 5 with 2.4Ghz 64-bit quad-core CPU (8GB RAM); CanaKit Turbine Black Case for the Raspberry Pi 5
$259.95

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.