Getting the smallest video with same quality, how to with FFMPEG?
Solution 1:
You can try to encode with libx264 CRF 18. The CRF parameter sets the quality and influences the file size. Lower values mean higher quality, and typical values are from 18 to 28. The default is 23.
CRF 18 is well known for producing a (arguably) "visually lossless" result:
ffmpeg -i input.avi -c:v libx264 -crf 18 -preset veryslow -c:a copy out.mp4
Notice that I used a veryslow
preset which will give you the smallest file possible. You can leave it out if you want to encode faster, but the file size will be larger, too.
Also, I decided to copy the audio track instead of reencoding it (-c:a copy
), mainly because I assume it's already AAC/MP3 stereo in your sample.
If the output is too big for you, try with a higher CRF value (up to 23) but the quality will suffer.
Solution 2:
Getting the smallest video with the least amount of quality lost is more of a challenge than anything else. There are guides scattered among the Web that will recommend you settings to use on FFmpeg for things like game captures, streams, DVD rips, etc.
If you want lossless lossless, try this:
ffmpeg -i input.mp4 -c:v libx264 -crf 0 output.mp4
The important part is the -crf 0
part which sets it to lossless. However, the output file will generally be very large. You could change it to -crf 18
which would give you something that is acceptable in quality and free from most artifacts.
Solution 3:
2021
H265 / HEVC version :
ffmpeg -i input.mp4 -vcodec libx265 -crf 18 -tag:v hvc1 -preset veryslow -an output.mp4