Skip to content

Instantly share code, notes, and snippets.

@penut85420
Created December 29, 2020 06:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save penut85420/30922c4503da5881ff32389668c49524 to your computer and use it in GitHub Desktop.
Save penut85420/30922c4503da5881ff32389668c49524 to your computer and use it in GitHub Desktop.
import os
import argparse
import datetime as dt
import subprocess as sp
def main(inn, bb, ee):
fn, ext = os.path.splitext(inn)
def parse_time(s):
try:
t = dt.datetime.strptime(s, '%H:%M:%S')
except:
t = dt.datetime.strptime(s, '%M:%S')
return t
def count_seconds(t):
return t.hour * 60 * 60 + t.minute * 60 + t.second
bb = parse_time(bb)
ee = parse_time(ee)
bs = count_seconds(bb)
es = count_seconds(ee)
dd = ee - bb
sp.call([
'ffmpeg',
'-ss', args.begin,
'-t', f'{dd.total_seconds()}',
'-i', inn,
'-vcodec', 'copy',
'-acodec', 'copy',
'-avoid_negative_ts', 'make_zero',
f'{fn}_{bs}-{es}{ext}'
])
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument('input', help='Input file name')
parser.add_argument('begin', help='Begin of time')
parser.add_argument('end', help='End of time')
args = parser.parse_args()
main(args.input, args.begin, args.end)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment