68

I am trying to clip an MP3 between two starting points, like starting at 10 seconds and ending at 16 seconds (time interval of 6 seconds).

I am using this command:

ffmpeg -ss 10 -i input.mp3 -t 6 output.mp3

The resulting output.mp3 contains the 6 seconds that I specified followed by 8 or 9 seconds of empty audio. Is there something wrong with my command?

Edit:

ffmpeg -ss 10 -t 6 -i input.mp3 output.mp3 says -t is not an input option, keeping it for the next output; consider fixing your command line. and gives me a file that's got 8 seconds of audio starting from 10s and then some 9 or 10 seconds of silence.

ffmpeg -ss 10 -to 16 -i input.mp3 output.mp3 produces a file that is twice the length of the original - basically the same audio file repeated again.\

Testing the output:

I used Quicktime and it has silent audio at the end. The description of the output file in finder says like 14 seconds. When I use VLC, it plays for the correct 6 seconds and stops, even though its duration in the file browser in VLC says 14. My MPlayer doesn't work properly. I also did the preview audio in Finder, and it plays the 6 seconds properly and then stops. But the round seeker bar of the MP3 didn't reach the end. And it also says 14 seconds instead of 6.

My goal is to stream this 6 second file through a REST API to the front end. I want the user to be able to download this file properly. Ideally it won't have inconsistent metadata (14 seconds instead of 6).

2
  • I am using this command to trim audio for 30 sec but it si giving me error. String[] complexCommnad = { " -i", mAudioPath + ".mp3", "-ss", "0", " -to", " 30", "copy", destination.getPath()}; Dec 6, 2018 at 11:14
  • Unable to find a suitable output format for ' -i' -i: Invalid argument Dec 6, 2018 at 11:14

3 Answers 3

93

For me both

ffmpeg -ss 10 -t 6 -i input.mp3 output.mp3

or

ffmpeg -ss 10 -i input.mp3 -t 6 output.mp3

work OK, just 6 seconds of audio. Here's the mplayer output (last line):

A:   5.8 (05.7) of 6.0 (06.0)  0.5%

Also

ffmpeg -ss 10 -to 16 -i input.mp3 output.mp3

work the same way. I use ffmpeg version 1.2.4. I guess your ffmpeg is somehow "broken" or the input file is somehow (report a bug in either case).

You may try the other answer with mp3cut from portforwardpodcast or

sox input.mp3 output.mp3 trim 10 6
7
  • The first one says -t is not an input option, keeping it for the next output; consider fixing your command line.. The second produces a result that is twice the length of the original file.
    – gruuuvy
    Nov 30, 2013 at 1:24
  • Yikes none of these work for me. My ffmpeg is 1.2.1, but I am on OSX. Maybe my input file is wrong, I am using youtube-dl with --extract-audio --audio-format mp3 options.
    – gruuuvy
    Nov 30, 2013 at 1:39
  • How do you play/check the output file? The exiftool reports wrong duration (13.90 s (approx)), but mplayer, mpg321 and mpg123 all play it correctly and display 6 seconds duration. Nov 30, 2013 at 1:40
  • I used Quicktime and it has silent audio at the end. The description of the output file in finder says like 14 seconds. When I use VLC, it plays for the correct 6 seconds and stops, even though its duration in the file browser in VLC says 14. My MPlayer doesn't work properly. I also did the preview audio in Finder, and it plays the 6 seconds properly and then stops. But the round seeker bar of the MP3 didn't reach the end. And it also says 14 seconds instead of 6.
    – gruuuvy
    Nov 30, 2013 at 1:45
  • I'm using ffmpeg on win32 (built on Mar 7 2014). Can't get these options to work.
    – Sun
    Sep 22, 2014 at 18:08
48

ffmpeg - Trim audio file without re-encoding

Use ffmpeg to trim an audio file without re-encoding it.

Trim starting from 10 seconds and end at 16 seconds (total time 6 seconds)

ffmpeg -i input.mp3 -ss 10 -t 6 -acodec copy output.mp3

Trim from 00:02:54.583 to the end of the file

ffmpeg -i input.mp3 -ss 00:02:54.583 -acodec copy output.mp3

Trim from 00:02:54.583 for 5 minutes (300 seconds)

ffmpeg -i input.mp3 -ss 00:02:54.583 -t 300 -acodec copy output.mp3
0
2

I've had great success with both CBR and VBR mp3 files using mp3cut.

mp3cut -o output.mp3 -t 00:10-00:16 input.mp3

http://manpages.ubuntu.com/manpages/lucid/man1/mp3cut.1.html

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.