Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
ffmpeg trim/cut video to video
from datetime import timedelta
from subprocess import Popen
Edit section *User data*, and uncomment one of the commands `cmd`
# User data
tstart = timedelta(minutes=18, seconds=20, milliseconds=0)
tend = timedelta(minutes=18, seconds=30, milliseconds=0)
src = 'video_src.mkv'
output = 'output.mkv'
ffmpeg = 'ffmpeg'
tdelta = tend - tstart
tstart = str(tstart)
tend = str(tend)
tdelta = str(tdelta.total_seconds())
cmd = (ffmpeg, '-i', src, '-ss', tstart, '-c:v', 'copy', '-c:a', 'copy', '-to',
tend, output)
#cmd = (ffmpeg, '-ss', tstart, '-i', src, '-c:v', 'copy', '-c:a', 'copy', '-t',
# tdelta, output)
#cmd = (ffmpeg, '-ss', tstart, '-i', src, '-t', tdelta, output)
#cmd = (ffmpeg, '-i', src, '-ss', tstart, '-to', tend, output)
proc = Popen(cmd)
print('Exit code: {}'.format(proc.wait()))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment