Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

If I have a video, normally avi, but could be any, and I want to create another one in the same format but just a part, the position i seconds to f seconds into the video, what is the one-line command to do this?

share|improve this question

1 Answer 1

up vote 29 down vote accepted

This can be done with both mencoder and ffmpeg.

mencoder

Say that you want to cut out a part starting at 00:01:30 into the original file with a 5 seconds length and that it shouldn't be reencoded (if you want to re-encode it you'll have to replace copy with audio and video codecs, for a list of available audio codecs issue mencoder -oac help, for a list of available video codecs issue mencoder -ovc help), then you issue:

mencoder -ss 00:30:00 -endpos 00:00:05 -oac copy -ovc copy originalfile -o newfile

You'll have to replace orginalfile and newfile with actual file names, the later is the name of the file that is created to hold the cut out part.

ffmpeg

Say that you want to cut out a part starting at 00:0:30 into the original file with a 5 seconds length and that it shouldn't be re-encoded (if you want to re-encode it you'll have to replace copy with audio and video codecs, for a list of available codecs issue ffmpeg -formats -E), then you issue:

ffmpeg -ss 00:00:30 -t 00:00:05 -i orginalfile -vcodec copy -acodec copy newfile

You'll have to replace orginalfile and newfile with actual file names, the later is the name of the file that is created to hold the cut out part.


For reference see http://lazyxiong-tech.blogspot.com/2007/05/using-mencoder-to-cut-out-pieces-of.html and "7. Copy Only A Part Of Video" in http://segfault.in/2010/10/ffmpeg-tricks-you-should-know-about/

share|improve this answer
    
I tried it and failed. Can you show me what the command would be for you with your typical codecs to use for avi, flv and mpg? I listed the codecs but couldn't make much sense of it. –  Strapakowsky Sep 1 '11 at 5:07
    
@strapakowsky It depends on the input file and what codecs you have installed. Maybe you should make a new question for that and add information about what file you've got and what command you tried. –  N.N. Sep 1 '11 at 6:36
    
@strapakowsky I cannot get it to work with ffmpeg either but all the guides on cutting out parts with ffmpeg suggests that it should work somehow so I keep it in my answer. However, I've also added a mencoder line which I get to work. –  N.N. Sep 1 '11 at 8:35
    
Just used a version of this. It's not working for you because -ss ... -t ... needs to be before the -i infile option. See this answer for the real one-liner. You almost got it, just not the order... –  Hendy Nov 20 '12 at 22:29
1  
@Hendy Edited accordingly –  N.N. Nov 21 '12 at 5:50

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.