mp3ffmpeg

Crop MP3 to first 30 seconds


I want to generate a new (fully valid) MP3 file from an existing MP3 file as a preview try-before-you-buy style. The new file should only contain the first n seconds.

I could chop the stream at n seconds (calculating from the bitrate and header size) but this is dirty on a VBR track. I'd like to generate a proper MP3 file.


Solution

  • I also recommend ffmpeg, but the command line suggested by John Boker has an unintended side effect: it re-encodes the file to the default bitrate (which is 64 kb/s in the version I have here at least). This might give your customers a false impression of the quality of your sound files, and it also takes longer to do.

    Here's a command line that will slice to 30 seconds without transcoding:

    ffmpeg -t 30 -i inputfile.mp3 -acodec copy outputfile.mp3
    

    The -acodec switch tells ffmpeg to use the special "copy" codec which does not transcode. It is lightning fast.

    NOTE: the command was updated based on comment from Oben Sonne