All posts
Trim audio via CLI
ffmpeg: cut a section of MP3, WAV, or AAC by start and end time.
Open online converterPackages to install
Only ffmpeg is required. Re-encode so the cut lands on the exact timestamps.
ffmpeg
sudo apt-get update
sudo apt-get install -y ffmpegHow to run the command
Put -ss start and -to end before -i, then -vn and a codec: libmp3lame for MP3, pcm_s16le for WAV, aac for AAC.
ffmpeg -y -ss 5 -to 20 -i input.mp3 -vn -c:a libmp3lame -b:a 192k output.mp3Dockerfile example
Build a minimal Ubuntu image with the required packages and run the conversion inside the container.
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 -t trim-audio .
docker run --rm -v "$PWD:/work" -w /work trim-audio \
ffmpeg -y -ss 5 -to 20 -i input.mp3 -vn -c:a libmp3lame -b:a 192k output.mp3Example commands
Run these locally after installing the packages, or inside the container from the Dockerfile.
ffmpeg -y -ss 5 -to 20 -i input.mp3 -vn -c:a libmp3lame -b:a 192k output.mp3ffmpeg -y -ss 10 -to 30 -i input.wav -vn -c:a pcm_s16le output.wavffmpeg -y -ss 3 -to 15 -i input.aac -vn -c:a aac -b:a 192k output.aac