Split video files using ffmpeg

I’ve been working with large video files lately, files that are too large for regular storage media. I’ve come to learn how much better ffmpeg is at these jobs than the graphical tools. Mainly because the graphical ones draw more resources and require more fiddling about, in total taking more time than a short command. Here’s the only command you’ll need to create new files from one source video:

$ ffmpeg -i INPUT -vcodec copy -acodec copy -ss START OF VIDEO -t DURATION OUTPUT

So, let’s say I have bigvid.mpeg that’s 50 minutes and want to split it in files that are 30 minutes and then another with the next 15 minutes, discarding the last 5; respectively small1.mpeg and small2.mpeg.
Here are the two commands to deliver what we want:

$ ffmpeg -i bigvid.mpeg -vcodec copy -acodec copy -ss 00:00:00 -t 00:30:00 small1.mpeg

and then

$ ffmpeg -i bigvid.mpeg -vcodec copy -acodec copy -ss 00:30:00 -t 00:15:00 small2.mpeg

As you can see the start of video operand is relative to the input file (source video), while the duration or -t parameter is not. The -vcodec and -acodec options aren’t strictly necessary, ffmpeg’s default output codec should match the input.

ffmpeg and audio delays
However, I have experienced that videos created without codec specification will have audio delays or audio that is not synchronized to the video stream. Specifying both the audio and video codecs as exact copies using -vcodec copy and -acodec copy as in the examples will give you less headaches. That’s all!

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.