ten-second guide to video compression
modified January 10, 2021.compression generally requires sacrificing quality, since most video codecs are plenty good at compressing.
this is my default:
ffmpeg -i in.mp4 -map_metadata -1 -vf scale=800:-1 -crf 28 -c:a copy out.mp4
more details
you generally want to set a higher crf
(bitrate). default is 23
, below 17
is visually non-lossy, every +6
is half the bitrate. the -c:a copy
copies audio stream.
ffmpeg -i in.mp4 -crf 28 -c:a copy out.mp4
also consider removing all metadata
ffmpeg -i in.mp4 -map_metadata -1 -c:v copy -c:a copy out.mp4
also consider scaling down the video (-1
means “whatever value keeps it proportional”)
ffmpeg -i in.mp4 -vf scale=800:-1 -c:a copy out.mp4
also consider changing the encoding speed to compression ratio. from low compression to high compression, you have: ultrafast
, superfast
, veryfast
, faster
, fast
, medium
(default), slow
, slower
, veryslow
ffmpeg -i in.mp4 -preset slow -c:a copy out.mp4
also consider changing to a newer codec, though this sacrifices compatability with many players (default is -c:v libx264
)
ffmpeg -i in.mp4 -c:v libx265 -c:a copy out.mp4
and here’s the do-everything command:
ffmpeg -i in.mp4 -crf 28 -map_metadata -1 -vf scale=800:-1 -preset slow -c:v libx265 -c:a copy out.mp4ten-second guide to video compression (permalink) (tweet)
the no-JavaScript necronomicon