Commit 254f4cf4 authored by Michael Murtaugh's avatar Michael Murtaugh

added percentage support to frametime

parent 7c4e5fa2
...@@ -18,10 +18,16 @@ if __name__ == "__main__": ...@@ -18,10 +18,16 @@ if __name__ == "__main__":
framepath = args.framepath framepath = args.framepath
framepath = re.sub(r"{(\w+)}", r"{0[\1]}", framepath) framepath = re.sub(r"{(\w+)}", r"{0[\1]}", framepath)
print ("framepath", framepath) print ("framepath", framepath)
try: percentage = False
frametime = float(args.frametime) frametime = args.frametime
except ValueError: if frametime.endswith("%"):
frametime = timecode_tosecs(args.frametime) frametime = float(frametime[:-1])
percentage = True
else:
try:
frametime = float(frametime)
except ValueError:
frametime = timecode_tosecs(args.frametime)
r = [] r = []
for n in args.input: for n in args.input:
...@@ -33,8 +39,11 @@ if __name__ == "__main__": ...@@ -33,8 +39,11 @@ if __name__ == "__main__":
print ("extracting frame to", fp) print ("extracting frame to", fp)
usetime = frametime usetime = frametime
# ensure frametime is valid # ensure frametime is valid
if 'duration' in d and usetime > d['duration']-1: if 'duration' in d:
usetime = d['duration']-1 if percentage:
usetime = d['duration'] * (usetime / 100.0)
elif usetime > d['duration']-1:
usetime = d['duration']-1
extract_frame(n, fp, usetime) extract_frame(n, fp, usetime)
if len(r) == 1: if len(r) == 1:
......
...@@ -47,38 +47,3 @@ def get_info(url): ...@@ -47,38 +47,3 @@ def get_info(url):
data['metadata'] = md data['metadata'] = md
return data return data
if __name__ == "__main__":
ap = ArgumentParser("")
ap.add_argument("input", nargs="*")
ap.add_argument("--frame", default=False, action="store_true", help="extract frame / image")
ap.add_argument("--framepath", default="{base}.jpg")
ap.add_argument("--frametime", default="00:00:05", help="time to take frame")
args = ap.parse_args()
if args.frame:
framepath = args.framepath
framepath = re.sub(r"{(\w+)}", r"{0[\1]}", framepath)
print ("framepath", framepath)
try:
frametime = float(args.frametime)
except ValueError:
frametime = timecode_tosecs(args.frametime)
r = []
for n in args.input:
d = get_info(n)
r.append(d)
if args.frame:
base = os.path.splitext(n)[0]
fp = framepath.format({'base': base})
print ("extracting frame to", fp)
usetime = frametime
# ensure frametime is valid
if 'duration' in d and usetime > d-1:
usetime = d-1
extract_frame(n, fp, usetime)
if len(r) == 1:
print (json.dumps(r[0], indent=2))
else:
print (json.dumps(r, indent=2))
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment