ffmpeg clip audio interval with starting and end time

gruuuvy picture gruuuvy · Nov 30, 2013 · Viewed 68.2k times · Source

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).

Answer

Doncho Gunchev picture Doncho Gunchev · Nov 30, 2013

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