Or compile it yourself. Under macOS, you can use Homebrew and brew install ffmpeg
.
ffmpeg -copyts -ss [start] -i in.mp4 -to [end] -c copy -copyts out.mp4
Explaining the options
Here, theThe 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. The format) of the time is the same.
- 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.
You have to understand that normally, -ss
resets the timestamps of the input video after the cut point to 0, so by default it does not matter if you use -t
or -to
. If you want -ss
to not reset the timestamp to 0, the -copyts
option can be used. This makes -to
behave more intuitively.
For example:
ffmpeg -ss 5 -i in.mp4 -t 30 -c copy out.mp4
This seeks forward in the input by 5 seconds and generates a 30 second long output file. In other words, you get the input video's part from 5–35 seconds.
Or:
ffmpeg -ss 5 -i in.mp4 -to 30 -c copy out.mp4
This achieves the same thing as above, since the timestamps get reset to 0 after seeking 5 seconds in the input. The output will still be 30 seconds long.
If we instead use -copyts
, and we want the part from 5–35 seconds, we should use:
ffmpeg -copyts -ss 5 -i in.mp4 -to 35 -c copy out.mp4
Finally, we've used the -c copy
option. -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 on seeking, see https://trac.ffmpeg.org/wiki/Seeking
Sometimes, using -c copy
leads to output files that some players cannot process (they'll show a black frame or have audio-video sync errors).
ffmpeg -ss [start] -i in.mp4 -t [duration] -c:v libx264 -crf 23 -c:a aac -strict experimental -b:a 128k192k out.mp4
You can change the CRF and audio bitrate parameters to vary the output quality. Lower CRF means better quality, and vice-versa. Sane values are between 18 and 28.