So far I have been using the following command to split an audio file from S to E:

ffmpeg -i input.mp3 -ss S -to E -c copy output.mp3

Due to the fact that I need to split an audio file into multiple segments, each having a different length, I have to use the above command multiple times for only a single file.

So, is there a way to split a single audio file into multiple segments using ffmpeg, but using only a single command? Note that the segments are not of the same length.

  • Are the segments overlapping? – Gyan Oct 9 '19 at 15:28
  • @Gyan the next segment's starting time is the same as the previous segment ending time. for example seg1 from 0 to 8 and seg2 from 8 to 22 and so on. – George Sid. Oct 9 '19 at 15:41

Sure, just give it more output files:

ffmpeg -i input.mp3 -ss S -to E -c copy output1.mp3 -ss S -to E -c copy output2.mp3 …

Options after the input file actually pertain to the output file (so the -c, -ss and -to options are for the output file). And you can have multiple output files.

(Unlike the segments muxer, you can have overlapping output this way if you want. Or different codecs, or metadata. But @Gyan's answer with the segment muxer is easier if its restrictions are OK for you).

| improve this answer | |

If the segments are non-overlapping, you can use the segment muxer.

ffmpeg -i input.mp3 -vn -c copy -f segment -segment_times 0,8,22 output%d.mp3
| improve this answer | |
  • thanks for the answer! is there a way to specify an output name for each segment, instead of having it indexed with %d? – George Sid. Oct 9 '19 at 16:01
  • No, the filename template is limited to sequences or datetime – Gyan Oct 9 '19 at 16:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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