Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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
up vote 49 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 -i orginalfile -t 00:00:05 -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

Do you need to cut video with re-encoding or without re-encoding mode? You can try to following below command.

Synopsis: ffmpeg -i [input_file] -ss [start_seconds] -t [duration_seconds] [output_file]

use FFmpeg cut mp4 video without re-encoding

Example:
ffmpeg -i source.mp4 -ss 00:00:05 -t 00:00:10 -c copy cut_video.mp4

use FFmpeg cut mp4 video with re-encoding

Example:
ffmpeg -i source.mp4 -ss 00:00:05 -t 00:00:10 -async 1 -strict -2 cut_video.mp4
share|improve this answer
    
Working fine, thanks for this tuto – Washington Indacochea Delgado Mar 22 at 17:54

To be more precise you can: MANUALLY Open the file in a media player that will frame by frame advance (potplayer my favorite but MPC-HC works)and play an AVISynth file with data such as:

DirectShowSource(("C:\Downloads\Video\Do you want him.flv"), Pixel_Type="yuy2").Crop(0,0,-0,-0)
Subtitle("C:\Downloads\Video\Do you want him.flv", font="Arial", size=24, text_color=$ff0000, align=3)
ShowFrameNumber(scroll=true, x=336, y=27, font="Arial", size=24, text_color=$ff0000)

ShowTime(x=398, y=44, font="Arial", size=24, text_color=$ff0000)

Then cut with the EXACT time format:

ffmpeg -i "Path\do you want him.flv" -ss 00:00:05.240 -to 00:00:08.360 -vcodec libx264 -acodec libvo_aacenc "Path\Do you want him1.flv"

and

ffmpeg -i "Path\do you want him.flv" -ss 00:00:10.240 -to 00:00:14.360 -vcodec libx264 -acodec libvo_aacenc "Path\Do you want him2.flv"

If you wish to join, make a txt file with the video files with contents like:

file 'C:\Downloads\Video\Do you want him1.flv'

file 'C:\Downloads\Video\Do you want him2.flv'

Run ffmpeg:

ffmpeg -f concat -i FileList.txt -c copy "Path\NewName_joined.flv"

PROGRAMMATICALLY I wrote a program but have no level 10 to show it, sorry

share|improve this answer

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.