Use FFmpeg’s machine-readable -progress output as a heartbeat, and have a supervisor detect when complete progress updates stop arriving. Treat that as evidence about FFmpeg’s activity—not proof that YouTube is receiving a healthy stream. Check YouTube’s Live Control Room separately for ingest status and inspect playback for viewer-facing audio and video quality.
What a watchdog can—and cannot—tell you
A YouTube streaming setup has several distinct signals. No single one establishes that the stream is healthy from encoder to viewer:
- FFmpeg progress updates: indicate that FFmpeg is reporting encoding progress. A stale feed may mean the process is hung, blocked, or otherwise not producing updates.
- Process exit status and stderr: indicate whether FFmpeg terminated and may give diagnostic context for an error.
- YouTube Live Control Room: reports the status and health of the stream YouTube is receiving, including specific error messages. See YouTube’s live stream metrics guidance.
- Playback inspection: helps catch viewer-facing problems such as missing audio, frozen video, or poor quality that a running encoder does not rule out.
Pair the watchdog with YouTube’s dashboard and, where possible, a separate playback check. YouTube advises monitoring stream health and reviewing messages during an event, as well as monitoring continuous audio and video quality in its encoder settings guidance and live streaming tips.
How FFmpeg’s progress output works
FFmpeg’s -progress option emits machine-readable key=value lines. Each complete update ends with a progress key whose value is continue or end. Use -stats_period to choose the reporting interval; the FFmpeg documentation gives a default of 0.5 seconds. A one-second interval is a reasonable illustrative choice for a watchdog, not a required or universally optimal setting. See the FFmpeg CLI documentation.
Recommended Free Tools
#1 Best Overall
- 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.
Count an update only when its terminating progress line arrives. If you refresh the heartbeat for every line, a partial record could make a stalled encoder look active. Keep progress output separate from human-readable diagnostics: send it to stdout with -progress pipe:1, and capture stderr separately.
Set up the YouTube destination safely
- Get the ingest URL and stream key. In YouTube Live Control Room, create or select the live stream and copy its server URL and stream key. YouTube’s RTMPS instructions explain that RTMPS is RTMP over TLS/SSL and describe finding the URL and key in the Control Room.
- Prefer RTMPS where available. YouTube documents RTMP and RTMPS for encoder streaming and recommends RTMPS. Keep the key out of public scripts, source control, command transcripts, and logs. Restrict access to any environment file or secret store that contains it.
- Choose encoding settings for the actual output. YouTube documents H.264, H.265/HEVC, and AV1, frame rates up to 60 fps, and a recommended two-second keyframe interval that should not exceed four seconds. Bitrate recommendations vary by codec, resolution, and frame rate; consult the current table in YouTube’s encoder settings guidance for the combination you will send.
- Confirm the stream in Live Control Room. A successful FFmpeg launch does not establish that YouTube has accepted the stream or that its audio and video are suitable for viewers.
A watchdog pattern for POSIX systems
The following Python 3 example supervises FFmpeg on POSIX-like systems. It reads progress records without blocking the timeout check, writes stderr to a separate log, notices process exits, terminates the child process group on shutdown or stale progress, and limits retries with exponential backoff. It is a starting point, not a tested deployment for every host or FFmpeg build; validate it with your input, service manager, and signal-handling requirements before an event.
Rank #2
- 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.
Save as watch_ffmpeg.py. Set INPUT to a valid FFmpeg input and provide the YouTube RTMPS URL and key through protected environment variables. The script deliberately does not print the output URL or key.
#!/usr/bin/env python3
import os
import selectors
import signal
import subprocess
import sys
import time
INPUT = os.environ.get("INPUT", "input.mp4")
RTMPS_URL = os.environ["YOUTUBE_RTMPS_URL"]
STREAM_KEY = os.environ["YOUTUBE_STREAM_KEY"]
OUTPUT = f"{RTMPS_URL.rstrip('/')}/{STREAM_KEY}"
STALE_SECONDS = float(os.environ.get("STALE_SECONDS", "30"))
MAX_RESTARTS = int(os.environ.get("MAX_RESTARTS", "5"))
BACKOFF_SECONDS = float(os.environ.get("BACKOFF_SECONDS", "2"))
LOG_PATH = os.environ.get("FFMPEG_LOG", "ffmpeg-stderr.log")
STOP = False
def request_stop(signum, frame):
global STOP
STOP = True
signal.signal(signal.SIGINT, request_stop)
signal.signal(signal.SIGTERM, request_stop)
def run_once():
cmd = [
"ffmpeg", "-nostdin", "-re", "-i", INPUT,
"-c:v", "libx264", "-c:a", "aac",
"-f", "flv",
"-stats_period", "1", "-progress", "pipe:1",
OUTPUT,
]
with open(LOG_PATH, "ab", buffering=0) as errlog:
proc = subprocess.Popen(
cmd, stdin=subprocess.DEVNULL, stdout=subprocess.PIPE,
stderr=errlog, start_new_session=True,
)
sel = selectors.DefaultSelector()
sel.register(proc.stdout, selectors.EVENT_READ)
last_update = time.monotonic()
record = {}
reason = "process exited"
try:
while not STOP:
if proc.poll() is not None:
return proc.returncode, "process exited"
events = sel.select(timeout=1)
for key, _ in events:
line = key.fileobj.readline()
if not line:
continue
text = line.decode("utf-8", errors="replace").strip()
if "=" not in text:
continue
name, value = text.split("=", 1)
record[name] = value
if name == "progress":
last_update = time.monotonic()
ended = value == "end"
record.clear()
if ended:
return proc.wait(), "progress=end"
if time.monotonic() - last_update > STALE_SECONDS:
reason = f"no complete progress update for {STALE_SECONDS:g} seconds"
return None, reason
return None, "shutdown requested"
finally:
sel.close()
if proc.poll() is None:
try:
os.killpg(proc.pid, signal.SIGTERM)
proc.wait(timeout=10)
except subprocess.TimeoutExpired:
os.killpg(proc.pid, signal.SIGKILL)
proc.wait()
proc.stdout.close()
restarts = 0
while not STOP:
code, reason = run_once()
print(f"{time.strftime('%Y-%m-%dT%H:%M:%SZ', time.gmtime())} {reason}; exit={code}", file=sys.stderr, flush=True)
if STOP or reason == "progress=end":
break
if restarts >= MAX_RESTARTS:
print("restart limit reached; stopping", file=sys.stderr, flush=True)
sys.exit(code if code is not None else 1)
delay = BACKOFF_SECONDS * (2 ** restarts)
restarts += 1
time.sleep(delay)
Example environment variables (store them in a file readable only by the service account, or inject them using your secret manager):
Quick wins for a faster PC:
Scan for outdated or missing drivers - takes under a minuteDriver Scan →Clear out junk files and repair common Windows errorsFree Scan →Rank #3
- 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.
INPUT=/srv/video/program.mp4
YOUTUBE_RTMPS_URL=rtmps://YOUR_INGEST_HOST/YOUR_PATH
YOUTUBE_STREAM_KEY=YOUR_PRIVATE_STREAM_KEY
STALE_SECONDS=30
MAX_RESTARTS=5
BACKOFF_SECONDS=2
FFMPEG_LOG=/var/log/ffmpeg-stderr.log
Replace the ingest host and path with the exact URL shown in Live Control Room. The example uses -re for a file input so it is read at its native rate; for a live capture or another real-time source, adapt the input options rather than copying that flag blindly. The sample encoding choices are illustrative; use YouTube’s current settings table for your chosen codec, resolution, and frame rate.
Choose and validate the stale timeout
STALE_SECONDS is an operator-selected threshold, not an FFmpeg or YouTube standard. Give ordinary network interruptions, irregular sources, and host load enough room that routine pauses do not trigger restarts. A short threshold can cause unnecessary disconnects; an overly long one delays recovery. Test with the real source and host, then adjust. The script counts restarts per run and stops at the configured limit rather than retrying forever.
Rank #4
- 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
Read the outcomes correctly
- Progress is stale while the PID remains alive: the watchdog stops the FFmpeg process group and retries within its limit. Inspect the timestamped supervisor output and stderr log to diagnose the cause.
- FFmpeg exits: the supervisor records the exit status and retries within its limit. An exit is distinct from a live process with a stale progress feed.
- FFmpeg reports
progress=end: the example treats this as normal completion and does not restart. For a finite file that is intended to loop, configure the FFmpeg input or playlist for looping rather than treating normal completion as a hang. - The process reports progress but YouTube shows an error: investigate the ingest status and message in Live Control Room; the local heartbeat cannot diagnose YouTube’s receiving state.
The sample appends FFmpeg stderr to a log but does not rotate it; set up log rotation and access controls appropriate to your host. If you manage FFmpeg with systemd, a container orchestrator, or another supervisor, avoid stacking independent unlimited restart loops. Choose one layer to own retries, and keep the other’s policy bounded and observable.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Test recovery before relying on it
Test the primary and backup path before an event, and confirm that viewers actually see the intended result. YouTube’s live streaming tips recommend testing a backup encoder by stopping the primary encoder or disconnecting its Ethernet, then checking that the player rolls over to the backup. Also test how your watchdog responds to a stopped FFmpeg process, a deliberately stalled source, and a rejected or unavailable ingest destination. Confirm that a recovery does not expose the stream key in logs.
Do these 3 things before closing this tab:
1Scan for outdated or missing drivers - takes under a minute2Clear out junk files and repair common Windows errors3Fix the driver behind crashes, sound loss and screen glitchesBest Value
- 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.
Or let it run in the cloud
If your goal is to keep uploaded videos playing as a 24/7 YouTube stream rather than to supervise your own FFmpeg host, StreamNeo runs the loop in the cloud: upload a recording or build a playlist, add your YouTube stream key, and go live. Nothing has to stay on at home. Every slot streams the upload as made, up to 4K 60fps, at one price per slot; StreamNeo automatically recovers if YouTube drops the stream. The first day is free with no card, one free day per account. Monthly billing is $9.99 per month.
Quick Recap
Start your 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.




