Cut part from video file from start position to end position with FFmpeg [duplicate]

Solution 1:

Install ffmpeg

Make sure you download a recent version of ffmpeg, and don't use the one that comes with your distribution (e.g. Ubuntu). Packaged versions from various distributions are often outdated and do not behave as expected.

Or compile it yourself.

How to cut a video, without re-encoding

Use this to cut video from [start] for [duration]:

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

Use this to cut video from [start] to [end]:

ffmpeg -ss [start] -i in.mp4 -to [end] -c copy -copyts 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).
  • Instead of -t, you can also use -to, which specifies the end time (needs -copyts if -ss is before -i, for faster seeking). Note that if you've used -ss, you have to subtract this from the -to timestamp. For example, if you cut with -ss 3 -i in.mp4 -to 5, the output will be five seconds long.
  • -c copy copies the first video, audio, and subtitle bitstream from the input to the output file without re-encoding them. This won't harm the quality and make the command run within seconds.

For more info, see https://trac.ffmpeg.org/wiki/Seeking

How to cut a video, with re-encoding

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.

For example:

ffmpeg -ss [start] -i in.mp4 -t [duration] -c:v libx264 -c:a aac -strict experimental -b:a 128k out.mp4

Solution 2:

I think you can use the following command now.

ffmpeg -i inputFile -vcodec copy -acodec copy -ss 00:09:23 -to 00:25:33 outputFile

Have a look also ffmpeg Doc, or this wiki page.