ffmpeg clip audio interval with starting and end time
Solution 1
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
Solution 2
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
Solution 3
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
gruuuvy
Updated on July 08, 2022Comments
-
gruuuvy almost 2 years
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).
-
gruuuvy over 10 yearsThe 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 over 10 yearsYikes 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. -
Doncho Gunchev over 10 yearsHow 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.
-
gruuuvy over 10 yearsI 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.
-
Sun almost 10 yearsI'm using ffmpeg on win32 (built on Mar 7 2014). Can't get these options to work.
-
Mohit over 8 yearsFor me following worked. Thanks. ffmpeg -ss 10 -i input.mp3 -t 6 output.mp3
-
cwhsu about 8 years
ffmpeg -i a.mp3 -ss 10 -t 6 -acodec copy b.mp3
works for me on ffmpeg 2.4.3 on ubuntu 14.04