FFMPEG cut for time range

I am using the below command for having 15sec - 45 sec range of music but sample.m4a file is starting from 15 sec to 60 sec. Am I using the wrong syntax or why it is so?

ffmpeg -ss 00:00:15 -t 00:00:45 -i song.m4a -acodec copy sample.m4a

Solution 1:

The -t flag sets duration.
So in case you want 15sec-45sec range you must set -t 00:00:30 (i.e. 45-15=30) and use -t parameter after filename for make it output parameter.

Full command will look like this:

ffmpeg -ss 00:00:15 -i song.m4a -t 00:00:30 -acodec copy sample.m4a

And alternatively

ffmpeg -ss 15 -i song.m4a -t 30 -acodec copy sample.m4a

Solution 2:

Use -to instead of -t.

  1. -t specifies the duration
  2. -to specifies the end time

If you'd like to grab 30 seconds starting from 00:00:15, you can either:

1) Specify the start time and duration.

-ss 00:00:15 -t 00:00:30

2) Alternatively, specify the start time and end time.

-ss 00:00:15 -to 00:00:45

Both will grab the same 30 seconds of video.