From 40eb76b968cad37db220cde995308a9aaecf63a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Peter=20K=C3=B6rner?= Date: Thu, 21 Nov 2024 19:08:46 +0100 Subject: [PATCH 1/4] make-apple-motion: add --no-cleanup flag --- make-apple-motion.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/make-apple-motion.py b/make-apple-motion.py index 1d4c631..079908a 100755 --- a/make-apple-motion.py +++ b/make-apple-motion.py @@ -57,6 +57,10 @@ parser.add_argument('--num-audio-streams', dest='naudio', type=int, default=1, h number of audio-streams to generate. defaults to 1 ''') +parser.add_argument('--no-cleanup', action='store_true', help=''' + keep temp-dir for debugging purposes + ''') + args = parser.parse_args() @@ -250,5 +254,9 @@ while len(active_jobs) > 0: finalize_job(job_id, event) -print('all done, cleaning up ' + tempdir.name) -tempdir.cleanup() +if args.no_cleanup: + print('all done, *NOT* cleaning up, *TEMPFILES REMAIN* in ' + tempdir.name) + +else: + print('all done, cleaning up ' + tempdir.name) + tempdir.cleanup() From 41db29d24b1c694a00ae3dcd3083b2b18bef2c3d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Peter=20K=C3=B6rner?= Date: Thu, 21 Nov 2024 19:19:58 +0100 Subject: [PATCH 2/4] make-apple-motion: add --setting-path flag and auto-detect absolute path to default .compressorsetting file --- make-apple-motion.py | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/make-apple-motion.py b/make-apple-motion.py index 079908a..4262030 100755 --- a/make-apple-motion.py +++ b/make-apple-motion.py @@ -61,6 +61,12 @@ parser.add_argument('--no-cleanup', action='store_true', help=''' keep temp-dir for debugging purposes ''') +parser.add_argument('--setting-path', default='hd1080p.compressorsetting', help=''' + filename in the script-dir (where this python script resides), + the work-dir (where the .motn-file resides) or absolute path to + a .compressorsetting file + ''') + args = parser.parse_args() @@ -105,9 +111,22 @@ def describe_event(event): def event_print(event, message): print("{} – {}".format(describe_event(event), message)) +def find_settingpath(): + artwork_dir = os.path.dirname(args.motn) + setting_path = os.path.join(artwork_dir, args.setting_path) + if os.path.exists(setting_path): + return setting_path + + setting_path = os.path.join(os.path.dirname(__file__), args.setting_path) + if os.path.exists(setting_path): + return setting_path + + return args.setting_path + tempdir = tempfile.TemporaryDirectory() print('working in ' + tempdir.name) +settingpath = find_settingpath() def fmt_command(command, **kwargs): @@ -148,10 +167,11 @@ def enqueue_job(event): fp.write(xmlstr) compressor_info = run_output( - '/Applications/Compressor.app/Contents/MacOS/Compressor -batchname {batchname} -jobpath {jobpath} -settingpath hd1080p.compressorsetting -locationpath {locationpath}', + '/Applications/Compressor.app/Contents/MacOS/Compressor -batchname {batchname} -jobpath {jobpath} -settingpath {settingpath} -locationpath {locationpath}', batchname=describe_event(event), jobpath=work_doc, - locationpath=intermediate_clip) + locationpath=intermediate_clip, + settingpath=settingpath) match = re.search(r"", compressor_info) if not match: From a9cbfc5eb3b0eaedf997e70bd9c3820ad93eedb3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Peter=20K=C3=B6rner?= Date: Thu, 21 Nov 2024 19:26:10 +0100 Subject: [PATCH 3/4] make-apple-motion: add --snapshot-sec to automatically generate a snapshot of the final clip for inspection or as thumbnail --- make-apple-motion.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/make-apple-motion.py b/make-apple-motion.py index 4262030..f4317c4 100755 --- a/make-apple-motion.py +++ b/make-apple-motion.py @@ -61,6 +61,10 @@ parser.add_argument('--no-cleanup', action='store_true', help=''' keep temp-dir for debugging purposes ''') +parser.add_argument('--snapshot-sec', type=int, default=3, help=''' + number of seconds into the final clip when to take a snapshot (for inspection purposes or as thumbnail) + ''') + parser.add_argument('--setting-path', default='hd1080p.compressorsetting', help=''' filename in the script-dir (where this python script resides), the work-dir (where the .motn-file resides) or absolute path to @@ -226,6 +230,7 @@ def finalize_job(job_id, event): intermediate_clip = os.path.join(tempdir.name, event_id + '.mov') final_clip = os.path.join(os.path.dirname(args.motn), event_id + '.ts') copy_clip = os.path.join(os.path.dirname(args.motn), event_id + '.mov') + snapshot_file = os.path.join(os.path.dirname(args.motn), event_id + '.png') shutil.copy(intermediate_clip, copy_clip) @@ -235,6 +240,11 @@ def finalize_job(job_id, event): vcodec=args.vcodec, acodec=args.acodec) + run('ffmpeg -y -hide_banner -loglevel error -i {input} -ss {snapshot_sec} -frames:v 1 -vf scale="iw*sar:ih" -f image2 -y -c png {output}', + input=intermediate_clip, + output=snapshot_file, + snapshot_sec=str(args.snapshot_sec)) + event_print(event, "finalized intro to " + final_clip) From 21a8e014ef3911201f017833cc8fc2fa9f3b288b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Peter=20K=C3=B6rner?= Date: Thu, 21 Nov 2024 19:32:20 +0100 Subject: [PATCH 4/4] make-apple-motion: replace xml.sax.saxutils.xmlescape with custom routine, which also escapes quotes xml.sax.saxutils.xmlescape is only a str.replace in a trencoat anyways. --- make-apple-motion.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/make-apple-motion.py b/make-apple-motion.py index f4317c4..c2940e9 100755 --- a/make-apple-motion.py +++ b/make-apple-motion.py @@ -11,8 +11,6 @@ import sys import os import re -from xml.sax.saxutils import escape as xmlescape - # Parse arguments parser = argparse.ArgumentParser( description='C3VOC Intro-Outro-Generator - Variant to use with apple Motion Files', @@ -155,6 +153,13 @@ def run_output(command, **kwargs): os.system(f'{cmd} >{t.name} 2>&1') return t.read().decode('utf-8') +def xmlescape(xml): + xml = xml.replace("&", "&") + xml = xml.replace("<", "<") + xml = xml.replace(">", ">") + xml = xml.replace("\"", """) + xml = xml.replace("'", "'") + return xml def enqueue_job(event): event_id = str(event['id'])