How I Built a Stable 24/7 YouTube Livestream on a VPS Using FFmpeg (No SaaS Required)

Published: (December 28, 2025 at 02:38 PM EST)
1 min read
Source: Dev.to

Source: Dev.to

Challenge

The stream worked at first, but YouTube repeatedly showed “Not receiving enough video”. Viewers experienced freezes, and it initially looked like a network problem—but it wasn’t.

Root Cause

On the VPS, FFmpeg was using ~98–100 % CPU constantly. At 100 % CPU:

  • encoding slows
  • timestamps drift
  • bitrate becomes unstable
  • sometimes YouTube receives 0 kbps

The stream was CPU‑bound, not bandwidth‑bound.

Technical Fix

The goal was to keep CPU safely below ~60 %. I tuned FFmpeg as follows:

  • Use a faster preset
    -preset superfast
  • Apply predictable bitrate control
    -b:v 2000k -maxrate 2000k -bufsize 4000k
  • Keyframe interval for 30 fps
    -g 60 -keyint_min 60
  • Scale when needed
    -vf scale=1280:-2

Final Working Command (Simplified)

ffmpeg -re -stream_loop -1 -i video.mp4 \
  -vf scale=1280:-2 \
  -c:v libx264 -preset superfast -profile:v high \
  -b:v 2000k -maxrate 2000k -bufsize 4000k \
  -g 60 -keyint_min 60 -r 30 -pix_fmt yuv420p \
  -c:a aac -b:a 128k -ar 44100 \
  -f flv rtmp://a.rtmp.youtube.com/live2/STREAM_KEY

CPU usage dropped to ~50–60 %, and the stream stabilized to Excellent Health.

Key Takeaways

  • CPU load directly affects live‑streaming stability.

Why I Built This

I wanted a reliable 24/7 stream without SaaS cost limitations. Since I already maintain servers, building it myself made sense—and it turned into a great engineering exercise across streaming, DevOps, and system reliability.

Back to Blog

Related posts

Read more »