Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

FFMPEG -ss and -t for cutting mp3

Tags:

ffmpeg

mp3

I have been trying to use FFMPEG to cut out a specific portion of a sound track. I wanted to cut from 00:07 to 04:33, so I input the ffmpeg command as follows:

bin\ffmpeg -ss 00:07 -t 04:26 -i "input.mp3" -acodec copy "output.mp3"

I used 04:26 for -t, which is [end_time - start_time]. However, the output.mp3 I got was cut from 00:07 to 04:40, and the track was 04:33 long. In order to get the correct output file, I had to use a -t 04:19, which is [end_time - 2*(start_time)].

timeline of desired mp3 track

I tried an alternate command using -to instead of -t

bin\ffmpeg -i "input.mp3" -ss 00:07 -to 04:33 -acodec copy -y "output.mp3"

and this worked as expected, giving the desired output track from 00:07 to 04:33.

The question is, why does the first method require -t to be [end_time - 2* (start_time)]? intuitively, I want to seek 00:07 and then capture the subsequent 04:26, so -ss 00:07 and -t 04:26 makes sense to me. I can't figure out how ffmpeg is interpreting this such that I have to use 04:19 as -t instead.

Since the second method works, I'm not really looking for a solution. I'm just wondering why this happens.

like image 308
cobaltB12 Avatar asked Jul 10 '17 05:07

cobaltB12


1 Answers

When -ss and -t are placed before the input, ffmpeg resorts to fast seek which relies on the index of the input to allow ffmpeg to start and stop seeking. MP3s don't have indices, so ffmpeg estimates duration via bitrate. This can be inaccurate.

When -ss and -t are placed after the input, ffmpeg counts demuxed packets. This will be accurate.

like image 86
Gyan Avatar answered Oct 12 '22 01:10

Gyan