Here's what I use and will only take a few seconds to run:
ffmpeg -i input.mp4 -ss 01:19:27 -to 02:18:51 -c:v copy -c:a copy output.mp4
Reference: Trim video files using FFmpeg by Alexander Refsum Jensenius.
Generated mp4
files could also be used in iMovie
. More info related to get the full duration using get_duration(input_video) model.
If you want to concatenate multiple cut scenes you can use following Python script:
#!/usr/bin/env python3
import subprocess
def get_duration(input_video):
cmd = ["ffprobe", "-i", input_video, "-show_entries", "format=duration",
"-v", "quiet", "-sexagesimal", "-of", "csv=p=0"]
return subprocess.check_output(cmd).decode("utf-8").strip()
def main():
name = "input.mkv"
times = []
times.append(["00:00:00", "00:00:10"])
times.append(["00:06:00", "00:07:00"])
# times = [["00:00:00", get_duration(name)]]
if len(times) == 1:
time = times[0]
cmd = ["ffmpeg", "-i", name, "-ss", time[0], "-to", time[1], "-c:v", "copy", "-c:a", "copy", "output.mp4"]
subprocess.check_output(cmd)
else:
open('concatenate.txt', 'w').close()
for idx, time in enumerate(times):
output_filename = f"output{idx}.mp4"
cmd = ["ffmpeg", "-i", name, "-ss", time[0], "-to", time[1], "-c:v", "copy", "-c:a", "copy", output_filename]
subprocess.check_output(cmd)
with open("concatenate.txt", "a") as myfile:
myfile.write(f"file {output_filename}\n")
cmd = ["ffmpeg", "-f", "concat", "-i", "concatenate.txt", "-c", "copy", "output.mp4"]
output = subprocess.check_output(cmd).decode("utf-8").strip()
print(output)
if __name__ == "__main__":
main()
Example script will cut and merge scenes in between 00:00:00 - 00:00:10
and 00:06:00 - 00:07:00
.
If you want to cut the complete video (in case if you want to convert mkv
format into mp4
) just uncomment the following line:
# times = [["00:00:00", get_duration(name)]]
-t 00:00:05
or-to 00:00:08
in order to cut the video from 00:00:03 to 00:00:08. Check out the documentation.