2

I have a large .mp4 file (many hours long) and I want to split it into many 3 minute clips. How do I do that? Doing it manually with an editing software would take ages. Is there any automatic way to do it WITHOUT losing quality? Maybe there is a video editing software with this option? I use Windows.

  • Can I ask why you are trying to accomplish this? There may be an easier way to accomplish your end goal. – AJ Henderson Dec 29 '14 at 15:30
  • There's nothing like what you're looking for. Hire an assistant editor, do it yourself, or reconsider your approach. – CyanideBaby Nov 2 '15 at 15:48
1

FFMPEG can do it, with a bit of shell scripting. Here's how you could do it using Powershell on Windows:

$vidLength = <the length of your video in seconds>
$vstart = 0;
$c = 0;
while ($start -lt $vidlength){
  ffmpeg -ss $vstart -t 180 -i inputvid.mp4 -c:v v210 -c:a pcms16le ("output_{0:0000}.avi" -f $c);
  $vstart += 180;
  $c++;
}

What I'm doing is using a loop to control the ffmpeg command line video program. $vstart is a variable that sets the start time of each video segment, $c is a counter that will be used to number the files.

The ffmpeg command works by using the -ss command which seeks to the given time in the input, and the -t command which sets the duration to encode - both numbers are in seconds. inputvid.mp4 is the name of your input video. the -c:v command sets the video codec to v210 which is lossless uncompressed. This will create very large files. Hours of v210 video will run into terrabytes of storage. You might want to use another codec, possibly a lossly one, if so you mightwant to consider using libx264 to encode as h.264. In which case the ffmpeg line would look like:

fmpeg -ss $i -t 180 -i inputvid.mp4 -crf 0 -c:a pcms16le ("output_{0:0000}.mp4" -f $c);

here the -crf command is basically like your compression setting. You can wind it down to 0 -> lossless / big files or as high as 31 -> crappy / small files. 20 is a sane value for good quality viewing copies. The -c:a command is the audio codec, in this case uncompressed. If you don't want audio you can replace this with -an.

the output name of the files is set with the expression ("output_{0:0000}.avi" -f $c) this uses powershell string formatting to produce files named output_0000.avi, output_0001.avi…`. The number of zeros after the colon sets how many leading zeros appear in the file name.

The loop continues, adding 180 (3 minutes in seconds) to $vstart every time, and updating the counter, until it reaches the end of the file.

If you want to get ffmpeg for Windows, I suggest downloading it from here, it's a lot easier than building it yourself.

  • If the OP simply wants to break the whole file into contiguous 3 min segments, then -segment_time 180 -f segment part%02d.mp4 will do it in one command. But I'm not sure if that's what the OP wanted. – Gyan Jan 2 '16 at 13:37
  • Didn't know about the -segment command. Thanks for that. – stib Jan 2 '16 at 21:44
  • @stib edit your answer to include a -segment_time option. That's useful for others – paulzag Sep 13 '16 at 23:17

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.