All posts

Audio to MP3 via CLI

Encode any audio to MP3 with ffmpeg and libmp3lame.

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 192k output.mp3. The same profile works for M4A, AAC, FLAC, and OGG.

ffmpeg
ffmpeg -y -i input.wav -vn -c:a libmp3lame -b:a 192k 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 audio-to-mp3 .
docker run --rm -v "$PWD:/work" -w /work audio-to-mp3 \
  ffmpeg -y -i input.wav -vn -c:a libmp3lame -b:a 192k 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 192k output.mp3
Example 2
ffmpeg -y -i input.m4a -vn -c:a libmp3lame -b:a 192k output.mp3
Example 3
ffmpeg -y -i input.flac -vn -c:a libmp3lame -b:a 192k output.mp3