137

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?

N.N.
  • 18,589
Strapakowsky
  • 12,304

4 Answers4

169

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 latter is the name of the file that is created to hold the cut-out part.


For reference see this and "7. Copy Only A Part Of Video" here

Pablo Bianchi
  • 17,371
N.N.
  • 18,589
46

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

Ben Wong
  • 569
2

medipack is a very simple command-line app as a wrapper over ffmpeg.

you can achieve trimming your video using these commands:

medipack trim input.mp4 -s 01:04 -e 14:08 -o output.mp4
medipack trim input.mp4 -s 01:04 -t 13:04 -o output.mp4

you can view options of trim subcommand as:

srb@srb-pc:$ medipack trim -h
usage: medipack trim [-h] [-s START] [-e END | -t TIME] [-o OUTPUT] [inp]

positional arguments:
  inp                   input video file ex: input.mp4

optional arguments:
  -h, --help            show this help message and exit
  -s START, --start START
                        start time for cuting in format hh:mm:ss or mm:ss
  -e END, --end END     end time for cuting in format hh:mm:ss or mm:ss
  -t TIME, --time TIME  clip duration in format hh:mm:ss or mm:ss
  -o OUTPUT, --output OUTPUT

you could also explore other options using medipack -h

srb@srb-pc:$ medipack --help
usage: medipack.py [-h] [-v] {trim,crop,resize,extract} ...

positional arguments:
  {trim,crop,resize,extract}

optional arguments:
  -h, --help            show this help message and exit
  -v, --version         Display version number

you may visit https://github.com/srbcheema1/medipack and checkout examples in README.

0

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

chaos
  • 28,186
Budman1
  • 11