Skip to content

Instantly share code, notes, and snippets.

@emelcd
Created September 16, 2021 02:13
Show Gist options
  • Save emelcd/d01e4544ce23fa0ea4bfd87e34a6a8d4 to your computer and use it in GitHub Desktop.
Save emelcd/d01e4544ce23fa0ea4bfd87e34a6a8d4 to your computer and use it in GitHub Desktop.
An easy python script to crop and merge video using ffmpeg
import os
from uuid import uuid4
def crop(start, end, input):
# get the path of the script
output = "__"+str(uuid4()) + ".mp4"
script_path = os.path.dirname(os.path.realpath(__file__))
os.system('echo "file \'{}\'" >> list.txt'.format(script_path+'/'+output))
cmd = "ffmpeg -i " + input + " -ss " + \
start + " -to " + end + " -c copy " + output
os.system(cmd)
def main(arr, file):
for i in arr:
crop(i[0], i[1], file)
os.system('ffmpeg -f concat -safe 0 -i list.txt -c copy output-{}.mp4'.format(str(uuid4())))
os.system('rm __* -f && rm list.txt')
return
main([['00:05:05', '00:05:25'], ['00:06:49', '00:07:20'], ['00:09:07', '00:09:36']], 'int1.mkv')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment