All posts

Extract audio from video via CLI

ffmpeg: drop the video track and encode MP3, WAV, or AAC.

Open online converter

Packages to install

Only ffmpeg is required. libmp3lame writes MP3, pcm_s16le writes WAV, and aac writes ADTS AAC.

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

How to run the command

Use -vn to skip video and -map 0:a:0 for the first audio stream. Then pick a codec: libmp3lame, pcm_s16le, or aac.

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