четвъртък, 8 август 2013 г.

How to trim mp3 file with Linux

The short answer:
$ffmpeg -ss 0:00:00.0 -t 00:02:03.9 -i file.mp3 -acodec copy  new_file.mp3
This command will create a file lasting 2:03:9mins.
The longer version was that I desperately wanted to cut the end of one youtube downloaded mp3 file, but for some reason I couldn't do it with
$sudo mpgsplit -X file.mp3 [00:00:00-00:01:45] -o file_crop.mp3
(It told me "mmm, this file does not start with a pack, offset: -2 " and when I tried the "desperate mode" I got an endless loop - FUN!).
So I wanted to find something simple, instead of using Audacity, which seems too complicated for my simple needs. So this was my simple solution.
Note, ffmpeg gives you the following jolly message:
"This program is not developed anymore and is only provided for compatibility. Use avconv instead (see Changelog for the list of incompatible changes)."
But it still works, so anyway.
As for Audacity, you can do the same quite easily (it turns out) - just look at the bottom, there is Begining of Selection - End of selection. Type whatever you want and then click the first wave-button on the top right part of the screen "Trim audio". Then File->Export->mp3 and voila.
Well, can't compete with the one line solution of ffmpeg, right?