Video Archiving with FFmpeg
I keep most of my photos and videos on Photoprism, a great open-source Google Photos alternative with features like facial recognition and viewing photos by location.
I also have a cheap action camera, the Apeman Trawo A100, which supports recording video at 4K 50fps. However, the generated files are extremely large (with bitrates of 50,000kbps, so 1min of video is around ~500MB).
I needed a solution to compress my video files as much as possible, while still preserving (most) of the quality.
AV1
Luckily, there exists the AV1 video codec, which is supported by Chrome desktop/mobile and Firefox (at the time of this writing). The AV1 codec is advertised as the open (and royalty-free) equivalent of the H.265 codec, a proprietary codec designed as the successor to the H.264 (AVC) codec which is used widely.
AV1 is at least as good, and as fast, or even faster, than H.265 (and therefore H.264). For example, compared to x2651 , SVT-AV12 is better or equivalent (as measured by VMAF, a new video quality benchmark from Netflix).
FFmpeg
FFmpeg is a popular, open source suite of libraries and programs for working with multimedia files. FFmpeg supports encoding AV1 via several encoders: libaom
(the reference encoder), SVT-AV1 and rav1e
. SVT-AV1 1.7.0
improves encoding speed by up to 50% for several presets, and as of the time of this writing, it is probably the best encoder to use.
To use ffmpeg
to transcode by videos, I use the following command:
ffmpeg -i input-file -c:a copy -c:v libsvtav1 -crf 47 -preset 6 -vf scale=out_range=pc -map_metadata 0 output-file
Explanation of parameters:
crf 47
: This sets the quality level for each frame, with lower values indicating higher quality and larger file size. The default is 50.preset 6
: Presets control how many efficiency features are used during the encoding process, with lower presets using more features and being smaller but slower. Presets range from 0 - 12, and the default is 8. Home enthusiasts generally use values between 4 - 6.vf scale=out_range=pc
: The Apeman A100 uses theyuvj420
pixel format, which is deprecated, resulting in washed out contrast when playing on a non-aware video player (e.g. VLC). This fixes that issue.map_metadata 0
: Some encoders store video metadata such ascreation_time
, and this preserves it in the output.
Results
After using the parameters above, my library of 4K videos was compressed from 24GB to 3.7GB (a 15x reduction).