Created
December 29, 2020 06:31
-
-
Save penut85420/30922c4503da5881ff32389668c49524 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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