Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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?

share|improve this question
add comment

4 Answers

Use this to cut video from [start] for [duration]. Make sure you download a recent version of ffmpeg, and don't use the one that comes with your distribution (e.g. Ubuntu).

ffmpeg -i in.mp4 -ss [start] -t [duration] -c:v copy -c:a copy out.mp4

Here, the options mean the following:

  • -ss specifies the start time, e.g. 00:01:23.000 or 83 (in seconds)
  • -t specifies the duration of the clip (same format).
  • Recent ffmpeg also has a flag to supply the end time with -to.
  • -c:v copy and -c:a copy copy the video and audio bitstreams without re-encoding them. This won't harm the quality and make the command run within seconds. You can replace the two options with -c copy if you want to copy one video, audio and subtitle stream to the output.
  • 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.

However, there's one drawback. The video will have to be decoded until it reaches the position implied by -ss, and only then it starts copying the bitstream. This can take a long time, especially for really long videos.

For additional speed when doing this, you can supply the -ss option before -i. This way, the decoder will first seek to the position and then start decoding:

ffmpeg -ss [start] -i in.mp4 -t [duration] -c:v copy -c:a copy out.mp4

This might not be that accurate, so choose the appropriate command depending on what results you get. See also: Seeking with FFmpeg


If you need to use an old version of ffmpeg and can't use the -to option, you can create an edit list of in and out points, and convert these into in points with duration. For this you can use this Ruby script I wrote, which calculates the difference:

require "Time"
def time_diff(time1_str, time2_str)
  t = Time.at( Time.parse(time2_str) - Time.parse(time1_str) )
  (t - t.gmt_offset).strftime("%H:%M:%S.%L")
end

For example:

time_diff("00:09:23.000", "00:25:33.000")
=> "00:16:10.000" 
share|improve this answer
    
This should definitely be marked as answer - Works perfectly and much faster than -sameq! Thanks. –  Karl Cassar Oct 9 '12 at 16:16
1  
On ubuntu 12:10, -c:v and -c:a didn't work. I had to use "-acodec copy and -vcodec copy" instead. –  Samuel Lampa Apr 2 '13 at 14:21
    
@Samuel Then you're using an outdated version, which isn't even real FFmpeg, but the Libav fork. See: stackoverflow.com/a/9477756/1109017 –  slhck Apr 2 '13 at 14:45
    
Thanks for this! if you don't specify a duration, will it go to the end? –  Jeff Mar 31 at 17:03
    
@Jeff Yes! (character minimum) –  slhck Apr 1 at 5:34
add comment

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.

Way 1:

ffmpeg -ss <start> -i in1.avi -t <duration> -c copy out1.avi

Way 2:

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.

Examples:

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.

share|improve this answer
    
Ok, thnx. Will check out the docs and give it a try tomorrow. –  juGGaKNot Oct 3 '13 at 19:18
2  
-sameq does not mean "same quality" and has been removed from ffmpeg. Use -codec copy instead. Also, don't forget about the -to option. –  LordNeckbeard Oct 3 '13 at 20:47
    
I corrected the commands in your quote, as they were quite outdated. Please don't copy-paste information without properly quoting it. –  slhck Oct 4 '13 at 10:08
add comment

I use the following syntax to cut video with ffmpef:

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

-t is used to set the duration in seconds - you can't specify the end time but this should work for you.

share|improve this answer
    
Why are you setting FFmpeg to re-encode the file? Note that -sameq does not mean "same quality" at all. –  slhck Jan 11 '12 at 21:18
add comment

You can use this

ffmpeg -sameq -ss clip_start -t duration  -i  original.ogg  clip.ogg

Here you have to give duration of video. ie. 00:25:33-00:09:23

share|improve this answer
    
As I mentioned on the other answer: With your command, you're re-encoding the file, which is absolutely not necessary and results in reduced quality and increased processing time. –  slhck Jan 11 '12 at 21:18
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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