You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
38 lines
1.1 KiB
Python
38 lines
1.1 KiB
Python
import csv, sys, argparse
|
|
from timecode import timecode_tosecs
|
|
from math import floor
|
|
from urllib.parse import urlparse
|
|
import os
|
|
|
|
|
|
def url_filename (url):
|
|
p = urlparse(url)
|
|
return os.path.split(p.path)[1]
|
|
|
|
def to_cmd (edl, framerate):
|
|
def s2f (t, framerate=args.framerate):
|
|
if t == None:
|
|
return None
|
|
return floor(framerate*timecode_tosecs(t))
|
|
def cmdify (edit):
|
|
if edit['end']:
|
|
return '"{0}" in={1} out={2}'.format(url_filename(edit['url']), s2f(edit['start']), s2f(edit['end']))
|
|
else:
|
|
return '"{0}" in={1}'.format(url_filename(edit['url']), s2f(edit['start']))
|
|
return "melt " + " ".join([cmdify(edit) for edit in edl])
|
|
|
|
ap = argparse.ArgumentParser("srt to melt command")
|
|
ap.add_argument("--framerate", type=float, default=25.0)
|
|
ap.add_argument("--output", default="edit.mp4")
|
|
ap.add_argument("--profile", default="quarter_pal_wide")
|
|
args = ap.parse_args()
|
|
|
|
outf = csv.writer(sys.stdout)
|
|
rows = []
|
|
for row in csv.DictReader(sys.stdin):
|
|
rows.append(row)
|
|
|
|
cmd = to_cmd(rows, args.framerate)
|
|
cmd += f" -profile {args.profile} -consumer avformat:{args.output}"
|
|
|
|
print (cmd) |