How can you trim mp3 files using `ffmpeg`?

For editing mp3's under linux, I'd recommend sox. It has a simple to use trim effect that will do what you ask for (see man sox for datails - search (press/) for "trim start"). Example:

sox input.mp3 output.mp3 trim 1 5

You didn't mention it, but if your aim is just to remove the silence at the beginning of files, you will find silence effect much more useful (man sox, search for "above-periods")


You could try using mp3splt, which can split MP3 and Ogg files and has the advantage that it does not re-encode the file, thereby avoiding quality loss.


Make sure that your time specifications start with hours.

To cite the ffmpeg man page:

position may be either in seconds or in "hh:mm:ss[.xxx]" form

That means that when you choose the 2nd syntax only the .xxx part is optional. Else ffmpeg might mis-parse it as seconds.

Same goes for duration:

duration may be a number in seconds, or in "hh:mm:ss[.xxx]"

Another pitfall is the ordering of ffmpeg arguments (e.g. the -ss/-t options for an input file have to come before the -i option).

Example

$ wget http://traffic.libsyn.com/twiv/TWiV179.mp3
$ ffmpeg -ss 1:05:59.3 -t 00:02:03.9 -i TWiV179.mp3 -acodec copy \
     what_is_a_hmm_twiv179.mp3

With the specification -ss 1:05:59.3 -t 2:03.9 you would get a different result (i.e. a 2 second long piece).

(Tested on Fedora 17 with ffmpeg version 0.10.7.)

Tags:

Linux

Mp3

Ffmpeg