Skip to main content
added 70 characters in body
Source Link
slhck
  • 230.2k
  • 71
  • 621
  • 603

Or, same as above, but using -to:

This achieves the same thingresult as abovethe previous command, since the internal timestamps of the video get reset to 0 after seeking 5 seconds in the input. The output will still be 30 seconds long.

Or:

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.

Or, same as above, but using -to:

This achieves the same result as the previous command, since the internal timestamps of the video get reset to 0 after seeking 5 seconds in the input. The output will still be 30 seconds long.

ffmpeg -ss [start] -i in.mp4 -t [duration] -map 0 -c copy out.mp4
ffmpeg -copyts -ss [start] -i in.mp4 -to [end] -map 0 -c copy out.mp4
  • -ss specifies the start time, e.g. 00:01:23.000 or 83 (in seconds)
  • -t specifies the duration of the clip. The format of the time is the same.
  • Instead of -t, you can also use -to, which specifies the end time.
  • -map 0 maps all streams, audio, video and subtitles
ffmpeg -ss 5 -i in.mp4 -t 30 -map 0 -c copy out.mp4
ffmpeg -ss 5 -i in.mp4 -to 30 -map 0 -c copy out.mp4
ffmpeg -copyts -ss 5 -i in.mp4 -to 35 -map 0 -c copy out.mp4
ffmpeg -ss [start] -i in.mp4 -t [duration] -c copy out.mp4
ffmpeg -copyts -ss [start] -i in.mp4 -to [end] -c copy out.mp4
  • -ss specifies the start time, e.g. 00:01:23.000 or 83 (in seconds)
  • -t specifies the duration of the clip. The format of the time is the same.
  • Instead of -t, you can also use -to, which specifies the end time.
ffmpeg -ss 5 -i in.mp4 -t 30 -c copy out.mp4
ffmpeg -ss 5 -i in.mp4 -to 30 -c copy out.mp4
ffmpeg -copyts -ss 5 -i in.mp4 -to 35 -c copy out.mp4
ffmpeg -ss [start] -i in.mp4 -t [duration] -map 0 -c copy out.mp4
ffmpeg -copyts -ss [start] -i in.mp4 -to [end] -map 0 -c copy out.mp4
  • -ss specifies the start time, e.g. 00:01:23.000 or 83 (in seconds)
  • -t specifies the duration of the clip. The format of the time is the same.
  • Instead of -t, you can also use -to, which specifies the end time.
  • -map 0 maps all streams, audio, video and subtitles
ffmpeg -ss 5 -i in.mp4 -t 30 -map 0 -c copy out.mp4
ffmpeg -ss 5 -i in.mp4 -to 30 -map 0 -c copy out.mp4
ffmpeg -copyts -ss 5 -i in.mp4 -to 35 -map 0 -c copy out.mp4
added 832 characters in body
Source Link
slhck
  • 230.2k
  • 71
  • 621
  • 603

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.

Or compile it yourself.

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

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

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 out.mp4

Explaining the options

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. The format of the time is the same.
  • Instead of -t, you can also use -to, which specifies the end time.

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 -b:a 192k 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.

added 221 characters in body
Source Link
slhck
  • 230.2k
  • 71
  • 621
  • 603
Loading
added 173 characters in body
Source Link
slhck
  • 230.2k
  • 71
  • 621
  • 603
Loading
remove legacy stuff
Source Link
slhck
  • 230.2k
  • 71
  • 621
  • 603
Loading
deleted 114 characters in body
Source Link
slhck
  • 230.2k
  • 71
  • 621
  • 603
Loading
added 49 characters in body
Source Link
slhck
  • 230.2k
  • 71
  • 621
  • 603
Loading
added 502 characters in body
Source Link
slhck
  • 230.2k
  • 71
  • 621
  • 603
Loading
added 655 characters in body
Source Link
slhck
  • 230.2k
  • 71
  • 621
  • 603
Loading
added 113 characters in body
Source Link
slhck
  • 230.2k
  • 71
  • 621
  • 603
Loading
added 202 characters in body
Source Link
slhck
  • 230.2k
  • 71
  • 621
  • 603
Loading
Source Link
slhck
  • 230.2k
  • 71
  • 621
  • 603
Loading