Skip to content

Instantly share code, notes, and snippets.

@nd3w
Last active April 21, 2026 00:22
Show Gist options
  • Select an option

  • Save nd3w/d4ac894002e2c36a2a37accb07ee5cab to your computer and use it in GitHub Desktop.

Select an option

Save nd3w/d4ac894002e2c36a2a37accb07ee5cab to your computer and use it in GitHub Desktop.
Downscale An MP4 File Using FFMPEG and CPULimit

A Processor Friendly to Downscale MP4 File Using FFmpeg, cpulimit and nice

Install FFmpeg

sudo apt update && sudo apt install ffmpeg

Downscaling

Basic Conversion to 480p

ffmpeg -i input.mp4 -vf scale=-2:480 -c:v libx264 -crf 23 -c:a copy output.mp4

With CPU Usage Limiting

ffmpeg -i input.mp4 -vf scale=-2:480 -c:v libx264 -crf 23 -threads 2 -c:a copy output.mp4

Even gentler on the CPU

ffmpeg -i input.mp4 -vf scale=-2:480 -c:v libx264 -crf 23 -preset slower -threads 2 -c:a copy output.mp4
Option Meaning
-vf scale=-2:480 Resize to 480p height, auto-width (keeps aspect ratio)
-c:v libx264 H.264 video codec (widely compatible)
-crf 23 Quality level — lower = better quality, larger file (range: 0–51)
-preset slower Slower encoding = less CPU spike + better compression
-threads 2 Limit to 2 CPU threads
-c:a copy Copy audio as-is without re-encoding

Combine with nice

For a background job that won't compete with your other tasks, you can also combine it with nice

nice -n 19 ffmpeg -i input.mp4 -vf scale=-2:480 -c:v libx264 -crf 23 -threads 2 -c:a copy output.mp4

Using cpulimit for a processor-friendly process

Install cpulimit

sudo apt install cpulimit

Run FFmpeg Under cpulimit

cpulimit -l 50 -- ffmpeg -i input.mp4 -vf scale=-2:480 -c:v libx264 -crf 23 -c:a copy output.mp4

Replace 50 with your desired CPU percentage cap.

How cpulimit Counts Persentage

  • 100 = 100% of one core
  • 200 = 100% of two cores
  • So on a 4-core CPU, 400 would be full usage, 50 would be ~12.5% of total capacity

This means if you want to cap FFmpeg to, say, 30% of your total CPU on a 4-core machine, you'd use -l 120 (4 cores × 100 × 0.30).

Combine with nice

For a background job that won't compete with your other tasks, you can also combine it with nice

nice -n 19 cpulimit -l 50 -- ffmpeg -i input.mp4 -vf scale=-2:480 -c:v libx264 -crf 23 -c:a copy output.mp4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment