Using ffmpeg, you can easily re-encode a video to reduce its file size.
Command
Do it like this:
ffmpeg -i input.mp4 -c:v libx264 -crf 23 -preset slow -c:a copy -movflags +faststart output.mp4
Arguments
-
-i input.mp4
specifies your input file -
-c:v libx264
specifies H.264 encoding.- Use
-c:v libx265
for H.265/HEVC. It's an excellent modern encoding standard that is fairly widely supported, but not on older devices.
- Use
-
-crf 23
specifies the Constant Rate Factor, i.e. video quality.- Lower values mean higher quality.
- 23 produces some compression artifacts but is often good enough. Choose 20 if you want better quality with still reasonably small video files.
- When using H.265/HEVC, you may use higher numbers since HEVC offers better overall compression.
-
-preset slow
for good compression with reasonably quick encoding duration. -
-c:a copy
will copy the audio stream without re-encoding. It's usually not worth to re-encode at a lower audio quality. -
-movflags +faststart
allows starting playback without downloading the entire file. -
output.mp4
specifies your output file
Posted by Arne Hartherz to makandra dev (2025-01-31 14:22)