Skip to content

Instantly share code, notes, and snippets.

@georgechalhoub
Created March 16, 2017 08:22
Show Gist options
  • Save georgechalhoub/e9c1c50507f651c8af90c5f40e8376c7 to your computer and use it in GitHub Desktop.
Save georgechalhoub/e9c1c50507f651c8af90c5f40e8376c7 to your computer and use it in GitHub Desktop.
Trimming a video using FFMPEG using Python
import os
def runBash(command):
os.system(command)
def crop(start,end,input,output):
str = "ffmpeg -i " + input + " -ss " + start + " -to " + end + " -c copy " + output
print str
runBash(str)
crop("00:07:09","00:09:12","ch1.mp4","level00.mp4")
crop("00:09:12","00:14:48","ch1.mp4","level01.mp4")
crop("00:11:48","00:14:13","ch1.mp4","level02.mp4")
crop("00:14:13","00:15:43","ch1.mp4","level03.mp4")
crop("00:15:43","00:18:27","ch1.mp4","level04.mp4")
crop("00:18:27","00:22:55","ch1.mp4","level05.mp4")
crop("00:22:55","00:29:54","ch1.mp4","level06.mp4")
crop("00:29:54","00:31:04","ch1.mp4","level07.mp4")
crop("00:31:04","00:33:10","ch1.mp4","level08.mp4")
crop("00:33:10","00:38:13","ch1.mp4","level09.mp4")
crop("00:38:13","00:42:17 ","ch1.mp4","level1018.mp4")
crop("00:42:17","00:42:52","ch1.mp4","level19.mp4")
@Anasadarsh
Copy link

Its not working
Simply nothing is showing

@AndreasKaratzas
Copy link

AndreasKaratzas commented Oct 1, 2020

It is working perfectly. Have you added ffmpeg to your User Path?

Edit: Tested on Windows OS

@cse001
Copy link

cse001 commented Feb 21, 2021

It will work, just in case it doesnt, install ffmpeg.
On debian systems you can install it using apt-get install ffmpeg.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment