I have a video file of 30 minutes, but I want to extract a video from 00:09:23 to 00:25:33.
I can define the startposition with
-ss, but I couldn't find one for the end position. Any help please?
Super User is a question and answer site for computer enthusiasts and power users. It only takes a minute to sign up.Sign up to join this community
Make sure you download a recent version of
ffmpeg, and don't use the one that comes with your distribution (e.g. Ubuntu). Packaged versions from various distributions are often outdated and do not behave as expected.
Use this to cut video from
ffmpeg -ss [start] -i in.mp4 -t [duration] -c copy out.mp4
Here, the options mean the following:
-ssspecifies the start time, e.g.
-tspecifies the duration of the clip (same format).
-tyou can also supply the end time with
-c copycopies the first video, audio, and subtitle bitstream from the input to the output file without re-encoding them. This won't harm the quality and make the command run within seconds.
Note that if you've used
-ss, you have to subtract this from the
-to timestamp. For example, if you cut with
-ss 3 -i in.mp4 -to 5, the output will be five seconds long.
For more info, see https://trac.ffmpeg.org/wiki/Seeking
If you leave out the
-c copy option,
ffmpeg will automatically re-encode the output video and audio according to the format you chose. For high quality video and audio, read the x264 Encoding Guide and the AAC Encoding Guide, respectively.
ffmpeg -ss [start] -i in.mp4 -t [duration] -c:v libx264 -c:a aac -strict experimental -b:a 128k out.mp4
This is odd that no-one suggested the
Drop everything except the second minute of input:
ffmpeg -i INPUT -vf trim=60:120
Keep only the first second:
ffmpeg -i INPUT -vf trim=duration=1
Drop everything except from second 13 to second 58:
ffmpeg -i INPUT -vf trim=13:58 OUTPUT
You can use these two methods which work for Windows and Linux.
There are two ways how to split video files by ffmpeg. The first one is good in itself, more than that - it is faster, but sometimes creates output files with certain flaws. So for those cases there is the second way of splitting video files: it is considerably slower, the output files are bigger, but it seems they are always of the same quality level as input files used.
ffmpeg -ss <start> -i in1.avi -t <duration> -c copy out1.avi
ffmpeg -ss <start> -i in1.avi -t <duration> out1.avi
<start>– the beginning of the part of a video ffmpeg is to cut out. Format:
00:00:00.0000, meaning hours:minutes:seconds:milliseconds.
<duration>– the duration of the part of a video ffmpeg is to cut out. Same format as above.
ffmpeg -ss 01:19:00 -i in1.avi -t 00:05:00 -c copy out1.avi ffmpeg -ss 01:19:00 -i in1.avi -t 00:05:00 out1.avi
ffmpeg cuts out a part of the video file starting from 1 hour 19 minutes 0 seconds. The duration of the video sequence cut out is 5 minutes 0 seconds.