MP3 Trimming: The `ffmpeg` Way

Alright, you want to trim an MP3. Classic. You’ve got a file, you need a specific segment. Don’t overcomplicate it. This is a basic operation, like breathing, if you’re a software developer.

You’re going to use ffmpeg. It’s the standard. If you don’t have it, get it.

sudo apt update
sudo apt install ffmpeg

Once ffmpeg is installed, the command to trim your MP3 is straightforward. You want to start at 0:00 and end at 1:55.

Here’s the command:

ffmpeg -i input.mp3 -ss 00:00:00 -to 00:01:55 -c copy output_trimmed.mp3

Let’s break it down, because I know some of you are still figuring out ls -l.

  • -i input.mp3: This specifies your input file. Replace input.mp3 with the actual name of your file.
  • -ss 00:00:00: This is your start time. In this case, it’s the very beginning. The format is HH:MM:SS.
  • -to 00:01:55: This is your end time. The segment will go up to this point. Again, HH:MM:SS.
  • -c copy: This is important. It tells ffmpeg to simply copy the audio stream without re-encoding it. This makes the process extremely fast and avoids any quality loss.
  • output_trimmed.mp3: This is the name of your new, trimmed MP3 file. Choose something descriptive.

Run that command. Your new file, output_trimmed.mp3, will be exactly 1 minute and 55 seconds long. Done. Go build something.