I have a video lasting 10 minutes which I want to cut into five 2-minute segments.

I can use ffmpeg to cut a video to a specific time with the following:

ffmpeg -sameq -ss [start_seconds] -t [duration_seconds] -i [input_file] [outputfile]

Do I first have to obtain the length of the video and then repeat the above command, or is there a simpler way to do this?

link|improve this question
feedback

1 Answer

i=-120
infile=<inputfile>
while [[ "$?" == "0" ]]; do \
    ((i+=120)) \
    ffmpeg -sameq -ss $i -t 120 -i $infile ${infile/.mpg/.$((i/120)).mpg} \
done
link|improve this answer
Thanks. Any explanatio on this:${infile/.mpg/.$((i/120)).mpg}? – DocWiki Jul 8 '11 at 23:16
I see Simple String Replace... – DocWiki Jul 8 '11 at 23:34
Assuming that the infile's extension is .mpg, that should produce output files named infile.0.mpg infile.1.mpg infile.2.mpg ... – blahdiblah Jul 8 '11 at 23:36
$? seems to be an error. It says:line 3: 0: command not found – DocWiki Jul 8 '11 at 23:40
oops, fixed. Such is the price of quick fixes. – blahdiblah Jul 8 '11 at 23:45
show 3 more comments
feedback

Your Answer

 
or
required, but never shown

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