Extract part of a video with a one-line command
This can be done using mencoder
or ffmpeg
.
mencoder
Say that you want to cut out a part starting at 00:00: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 pcm -ovc copy originalfile -o newfile
You'll have to replace orginalfile
and newfile
with actual file names, the latter 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:00: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/
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
If you want to cut off section from the beginning, simply drop -t 00:00:10
from the command