sodcalculator

10 Tech How-To

24/7 Ambient Stream: Lower CPU with FFmpeg

Guide 10-29155 · Updated · Step by step

Running a 24/7 ambient stream with FFmpeg can quietly eat a full CPU core if you encode with default settings. This guide shows you how to reconfigure FFmpeg to dramatically reduce CPU usage while keeping your stream stable and visually acceptable. You’ll learn the key flags, why they work, and how to avoid common pitfalls that cause buffering or stream drops.

What You’ll Need

  • A computer that will run the stream 24/7 (a small VPS or an old PC works)
  • FFmpeg installed (version 4.x or newer recommended)
  • Your ambient video loop file (MP4, MKV, or similar)
  • An audio track (optional but typical for ambient streams)
  • Streaming credentials (RTMP URL and stream key) from your platform

Step-by-Step

  1. Start with a simple, efficient command. The biggest CPU hog is encoding with the default x264 preset. Use the ultrafast preset and tune zerolatency to reduce encoding effort. Example:
    ffmpeg -re -stream_loop -1 -i input.mp4 -c:v libx264 -preset ultrafast -tune zerolatency -c:a aac -b:a 128k -f flv rtmp://your.rtmp.url/stream

    This alone can cut CPU usage by 30-50% compared to the default medium preset.

  2. Lower the resolution and framerate. Ambient streams don’t need 1080p60. Scale to 720p or even 480p and set a framerate of 24 or 30 fps. Add these filters before encoding:
    -vf "scale=1280:720,fps=24"

    This reduces the number of pixels to encode per second, directly lowering CPU load.

  3. Use a hardware encoder if available. If your CPU has Intel Quick Sync (QSV), NVIDIA NVENC, or AMD AMF, use it. For example, with NVENC:
    -c:v h264_nvenc -preset p5 -tune ll

    For QSV: -c:v h264_qsv. Hardware encoders offload the work from the CPU entirely, often dropping CPU usage to under 10%.

  4. Use a lower bitrate. High bitrate means more data to compress, which increases CPU usage. For 720p, a bitrate of 1500-2500 kbps is usually sufficient for ambient visuals. Add -b:v 2000k and -maxrate 2500k -bufsize 4000k to control the output.
  5. Optimize the audio encoding. AAC encoding is light, but you can also use a lower sample rate (44100 instead of 48000) to save a bit. Use -ar 44100.
  6. Use the -re flag correctly. -re reads the input at native speed, which is necessary for live streaming. However, if your input is a loop, you might not need -re if you use -stream_loop -1 without it—but that can cause the stream to send data too fast. Keep -re to avoid buffering issues.
  7. Consider using a lower CPU usage preset for x264. If you must use software encoding, ultrafast is the fastest, but you can also try superfast or veryfast if quality is a concern. Test each to see the CPU impact.
  8. Run FFmpeg with nice to lower priority. On Linux, use nice -n 19 ffmpeg ... to ensure the stream doesn’t interfere with other processes. On Windows, you can set the process priority to “Below Normal” in Task Manager.
  9. Monitor CPU usage. Use top (Linux) or Task Manager (Windows) to see the actual CPU usage. Adjust settings until it’s acceptable (usually under 50% of one core).

Common Mistakes

  • Using the default x264 preset. Forgetting to add -preset ultrafast is the most common mistake. The default medium preset is CPU-hungry.
  • Encoding at too high a resolution. Streaming 1080p when 720p looks nearly identical on a phone screen wastes CPU.
  • Not using -re. Without it, FFmpeg will try to encode as fast as possible, causing high CPU spikes and buffering on the viewer side.
  • Ignoring the bitrate. Setting a crazy high bitrate (like 8000k) for a simple ambient loop is unnecessary and increases CPU load.
  • Using a complex filter chain. Filters like scale and fps are cheap, but adding noise reduction or other heavy filters will increase CPU usage.

Tips

  • Use a loop input. To loop a video file, use -stream_loop -1. This avoids re-encoding the file repeatedly from disk, which saves I/O and CPU.
  • Test with a short duration. Run your command with -t 60 to stream for 60 seconds and check CPU usage before committing to 24/7.
  • Consider using a lower resolution like 480p. For a calm ambient stream, 480p at 24fps is often enough and uses very little CPU.
  • Use the -threads flag. You can limit FFmpeg’s threads with -threads 2 to prevent it from using all cores, but this may increase latency. Test it.
  • Keep your FFmpeg up to date. Newer versions have optimizations that reduce CPU usage.

Troubleshooting

  • Stream drops or buffers: If the stream is unstable, try increasing the bitrate or lowering the resolution. Also check your upload bandwidth. If CPU usage is low but the stream still buffers, it’s likely a network issue.
  • CPU usage is still high: If you’re using a hardware encoder and CPU is still high, you might have a filter that’s CPU-intensive. Remove all filters and test. Also, ensure the hardware encoder is actually being used (check FFmpeg logs for “Using hardware acceleration”).
  • FFmpeg crashes on startup: This often happens with hardware encoder flags. Check that your FFmpeg build includes the encoder (e.g., ffmpeg -encoders | grep nvenc). If not, fall back to x264.
  • Audio/video out of sync: This can happen if the input file has a variable frame rate. Use -fps_mode cfr (or -vsync cfr in older versions) to force constant frame rate.
  • Stream shows a black screen: Make sure your input video is actually decodable. Test with a simple ffplay input.mp4. If it plays, the issue is with the filter chain—try removing filters.

Frequently Asked Questions

Can I use a Raspberry Pi for this?

Yes, but the Pi’s CPU is limited. Use a hardware encoder like h264_omx (on older Pis) or h264_v4l2m2m (on newer ones) to keep CPU usage low.

Will lowering the bitrate affect quality?

For ambient streams with slow-moving visuals, a lower bitrate (1500-2500kbps) is usually fine. If you see artifacts, increase it slightly.

What’s the best resolution for a 24/7 stream?

720p is a good balance between quality and CPU usage. If CPU is still a concern, drop to 480p.

Do I need to use -re?

Yes, for live streaming, -re ensures the stream is sent at the correct real-time speed. Without it, the stream will be too fast and viewers will buffer.

Can I use a GPU to encode?

Yes, if your system has a supported GPU, use NVENC (NVIDIA), QSV (Intel), or AMF (AMD). This offloads encoding from the CPU.

How do I check my CPU usage?

On Linux, use top or htop. On Windows, open Task Manager and look at the Performance tab. You want to see the FFmpeg process’s CPU usage.

Related

General steps for current mainstream versions; menus can differ by device and version. See the disclaimer or report an error.

More in this bed

The whole Tech How-To bed →