All posts

Compress audio via CLI

Re-encode any audio to MP3 at a lower bitrate with ffmpeg.

Open online converter

Packages to install

Only ffmpeg is required. libmp3lame encodes MP3 at a constant bitrate.

ffmpeg
apt install
sudo apt-get update
sudo apt-get install -y ffmpeg

How to run the command

ffmpeg -i input.wav -vn -c:a libmp3lame -b:a 128k output.mp3. 192k is gentler; 96k shrinks more. The same profile works for M4A, AAC, FLAC, and MP3.

ffmpeg
ffmpeg -y -i input.wav -vn -c:a libmp3lame -b:a 128k output.mp3

Dockerfile example

Build a minimal Ubuntu image with the required packages and run the conversion inside the container.

Dockerfile
FROM ubuntu:24.04

RUN apt-get update && \
    apt-get install -y --no-install-recommends \
        ffmpeg && \
    rm -rf /var/lib/apt/lists/*

WORKDIR /work
docker build && docker run
docker build -t compress-audio .
docker run --rm -v "$PWD:/work" -w /work compress-audio \
  ffmpeg -y -i input.wav -vn -c:a libmp3lame -b:a 128k output.mp3

Example commands

Run these locally after installing the packages, or inside the container from the Dockerfile.

Example 1
ffmpeg -y -i input.wav -vn -c:a libmp3lame -b:a 128k output.mp3
Example 2
ffmpeg -y -i input.m4a -vn -c:a libmp3lame -b:a 96k output.mp3
Example 3
ffmpeg -y -i input.mp3 -vn -c:a libmp3lame -b:a 128k output.mp3