Skip to content

Saving Space

Tip

Some procedures described on this page can be automatically applied using the optimizelibrary.py Python script.

Danger

Proper precautions should be taken before performing operations on a library:

  • Keep a restorable backup copy of the library.
  • Run operations on a test copy of the library first.
  • Run operations in batches. (e.g. depending on the library structure, per letter or genre folder)

Optimizing audio

There is generally no reason to store music in uncompressed formats such as WAV or AIFF, as lossless audio codecs save disk space and do not incur quality loss. The only reasons for ignoring this advice include accessibility when working in music production and compatibility when working with DJ equipment.

FLAC (Free Lossless Audio Codec) is an efficient, lossless, well documented, well supported, free and open source audio codec, an excellent all-rounder. When using FLAC, audio data will not degrade and will sound exactly the same as the source.

The speed of decoding FLAC files does effectively not depend on the compression level used when encoding.1 While encoding with higher compression levels does take more time, it is a one time endeavour and worth the saved space.

1. Encode with libFLAC

All lossless audio should be encoded with the latest version of libFLAC at the highest compression level, level 8. Since version 1.4.0, libFLAC, the reference FLAC implementation, has much improved compression ratio compared to earlier versions.

1
flac -8 -V -f "$path"

2. Remove embedded images

Warning

Will decrease compatibility with hardware players.

In most cases album covers are identical for all tracks in the release and will be duplicated if stored embedded in the audio files, therefore taking more space for no content gained.

Removing embedded covers allows storing a single high quality cover file in the release folder with the overall size of the release ending up smaller or similar, compared to when the covers were embedded.

1
metaflac --dont-use-padding --remove --block-type=PICTURE "$path"

3. Remove excess padding

Tip

Add a column to Mp3tag with $div(%_tag_size_appended%,1024) KiB as the value to see the padding size in KiB.

Padding is used to make editing metadata faster. It is added to the beginning of the file, after the existing metadata and before the audio data. When metadata is changed, the padding will be overwritten instead of the file being rewritten entirely.2 This is especially important when editing files over a network share.

Some metadata editors (including Mp3tag) replace removed embedded images with padding instead of trimming the file. This leaves megabytes of unnecessary padding, which will likely never be used unless embedding other images later, which should not be done anyway.

The recommended amount of padding is 8KiB, which is generally enough for standard metadata.3

1
2
metaflac --dont-use-padding --remove --block-type=PADDING "$path"
metaflac --add-padding=8192 "$path"

Optimizing images

1. Encode with PNG or JPEG XL

ALl lossless images should be encoded with either PNG or JPEG XL. PNG offers excellent compatibility while JPEG XL offers excellent compression ratio.4 Furthermore, JPEG images can also be losslessly compressed with JPEG XL.

Using JPEG XL one can expect ~30% space savings over PNG and ~15% over JPEG.

PNG files should be losslessly optimized with oxipng.

1
oxipng "$path"

Warning

JPEG XL is not compatible with most music players and web browsers, therefore it is unsuitable for album covers and unsuitable for scans if they also need to be viewed in a music player or a web browser.

Good use cases for JPEG XL include archival storage, tape storage, raw scans or when viewing images in image viewers and the file explorer only.

Tip

JPEG XL software support is documented on the Supported Software page. Windows users will most likely want to install jxl-winthumb for File Explorer support.

Tip

JPEG XL sourced from JPEG can be detected by "JPEG bitstream reconstruction data" being present in the file.

1
jxlinfo "$path"

All lossless image files should be converted to lossless JPEG XL.

1
cjxl -q 100 "$inpath" "$outpath"

All JPEG files should be losslessly recompressed to JPEG XL. As JPEG XL supports lossless JPEG reconstruction, the resulting file will be smaller than the original with no degradation of data.

1
cjxl -q 100 "$inpath" "$outpath"

2. Remove alpha channel

Scans are digitized images of physical surfaces and should not have digital transparency. If an alpha channel is present, it can be removed to save storage space. The alpha channel may be inadvertently added when working on scans in image editing software. The same also applies to release covers.

Optimizing others

Releases shared online may come with additional miscellaneous files. Some of these are only useful in the act of sharing and receiving. Keeping them in storage offers no additional value as the information they provide can be obtained on demand based on other files in the release folder.

1. Remove spectrogram images

A spectrogram is a visual representation of audio data used to assess the quality of an encode. Sometimes these are pregenerated and shared as image files along with the release. These files are not needed as spectrograms can be generated on demand with Spek Alternative or FFmpeg.

1
rm "$path"

2. Remove dynamic range logs

foo_dr.txt files contain information about dynamic range. Dynamic range is the ratio between the loudest and quietest peak in audio, used to assess the quality of a recording. These files are not needed as dynamic range can be computed on demand with foo_dr_meter or drmeter.

1
rm "foo_dr.txt"

3. Remove transcode logs

Lossless Audio Checker.log files contain guesses about whether the audio files are lossy transcodes. These files are not needed as the information is often inaccurate, a more reliable assessment can be made by manually examining spectrograms.

1
rm "Lossless Audio Checker.log"


Salty • Created 2021-10-02 • Updated 2024-12-06