I had a pretty good experience with the h265 codec.
The output videos were between 2-8x smaller in size, without any noticeable loss in quality.
ffmpeg -i input.mkv -c:v libx265 -vtag hvc1 -c:a copy output.mkv
If you want to further reduce the filesize, x265 supports CRF and two different target bitrate algorithms:
Similar to x264, the x265 encoder has multiple rate control
- 1-pass target bitrate (by setting -b:v)
- 2-pass target bitrate
- Constant Rate Factor (CRF)
While the bitrate is variable with CRF, the quality is pretty much the same from frame to frame.
The CRF can be any value between 0 and 51, where lower values would result in higher quality. What you want to do would be to set a relatively high CRF. This of course makes the quality worse.
Choose a CRF. CRF affects the quality. The default is 28, and it
should visually correspond to libx264 video at CRF 23, but result in
about half the file size. CRF works just like in x264, so choose the
highest value that provides an acceptable quality.
Choose a preset. The default is medium. The preset determines
compression efficiency and therefore affects encoding speed. Valid
presets are ultrafast, superfast, veryfast, faster, fast, medium,
slow, slower, veryslow, and placebo. Use the slowest preset you have
patience for. Ignore placebo as it provides insignificant returns for
a significant increase in encoding time.
Choose a tune (optional). By default, this is disabled, and it is
generally not required to set a tune option. x265 supports the
following -tune options: psnr, ssim, grain, zerolatency, fastdecode.
They are explained in the H.264 guide.
ffmpeg -i input -c:v libx265 -crf 28 -preset slower -c:a copy output.mp4
Note that in the example we simply copy the audio stream. You could also transcode the audio stream to save an additional few MBs.