How to re-encode videos as H.265 & opus using ffmpeg for archival

When you don’t want your video archive to eat up too much space, I recommend encoding them as H.265 and OPUS as these codecs provide excellent quality with typically less than half the bitrate of older formats.

I also tried VP9 and AV1 which should result in even lower file size at the same quality. However, these are painfully slow, running at 0.0046x speed (libaom-av1) and 0.076x speed (libvpx-vp9) compared to 1.5x speed for libx265 for a test video since these encoders seem not to be highly optimized yet.

CRF means constant rate factor, higher values mean better quality but larger file size.

My recommendation is to use CRF 30 for lower-quality videos like analog grainy-ish videos, CRF 23 where you want to preserve the utmost quality, and CRF 26 for everything else.

For non-interlaced videos

ffmpeg -i input.mpg -c:v libx265 -crf 30 -c:a libopus -b:a 56k -frame_duration 60 output.mkv

For interlaced videos

UseĀ -vf yadif=1 as interlace filter to prevent interlacing artifacts:

ffmpeg -i input.mpg -vf yadif=1 -c:v libx265 -crf 30 -c:a libopus -b:a 56k -frame_duration 60 output.mkv