Using ffmpeg to cut up video
Solution 1:
You can use the -ss
option to specify a start timestamp, and the -t
option to specify the encoding duration. The timestamps need to be in HH:MM:SS.xxx
format or in seconds (s.msec
).
The following would clip the first 30 seconds, and then clip everything that is 10 seconds after that:
ffmpeg -ss 00:00:30.0 -i input.wmv -c copy -t 00:00:10.0 output.wmv
ffmpeg -ss 30 -i input.wmv -c copy -t 10 output.wmv
Note that -t
is an output option and always needs to be specified after -i
.
Some tips:
- For older ffmpeg versions, if you use
-ss
after-i
, you get more accurate seeking at the expense of a slower execution altogether. See also: Seeking with FFmpeg You can use
-to
instead of-t
to specify the timestamp to which you want to cut. So, instead of-i <input> -ss 30 -t 10
you could also do-i <input> -ss 30 -to 40
to achieve the same thing.If your ffmpeg does not support
-c
, or-to
, it is likely very outdated. Compile a new version yourself or download a static build from their homepage. It's really not complicated.
Solution 2:
As other people mentioned, putting -ss
before (much faster) or after (more accurate) the -i
makes a big difference. The section "Fast And Accurate Seeking" on the ffmpeg seek page tells you how to get both, and I have used it, and it makes a big difference. Basically you put -ss
before AND after the -i
, just make sure to leave enough time before where you want to start cutting to have another key frame. Example:
If you want to make a 1-minute clip, from 9min0sec to 10min 0sec in Video.mp4, you could do it both quickly and accurately using:
ffmpeg -ss 00:08:00 -i Video.mp4 -ss 00:01:00 -t 00:01:00 -c copy VideoClip.mp4
The first -ss
seeks fast to (approximately) 8min0sec, and then the second -ss
seeks accurately to 9min0sec, and the -t 00:01:00
takes out a 1min0sec clip.
Also note this important point from that page: "If you use -ss
with -c:v copy
, the resulting bitstream might end up being choppy, not playable, or out of sync with the audio stream, since ffmpeg is forced to only use/split on i-frames."
This means you need to re-encode the video, even if you want to just copy it, or risk it being choppy and out of sync. You could try just -c copy
first, but if the video sucks you'll need to re-do it.