How could I trim ( cut ) video based on start and end time using FFMPEG ?
Firstly, we can calculate the length of output video stream based on start, end time.
So we can cut your video in seconds with following command:
ffmpeg -ss 00:01:00 -i input.mp4 -to 00:02:00 -c copy output.mp4
-i: This specifies the input file. In that case, it is (input.mp4).
-ss: Used with -i, this seeks in the input file (input.mp4) to position.
00:01:00: This is the time your trimmed video will start with.
-to: This specifies duration from start (00:01:40) to end (00:02:12).
00:02:00: This is the time your trimmed video will end with.
-c copy: This is an option to trim via stream copy. (NB: Very fast)
In advanced, we can cut the content in the middle by following code
# In order to keep <start-15s> and <45s-end>, you need to # keep all the frames which are "not between 15s and 45s": ffmpeg -i input.mp4 \ -vf "select='not(between(t,15,45))', setpts=N/FRAME_RATE/TB" \ -af "aselect='not(between(t,15,45))', asetpts=N/SR/TB" \ output.mp4