[TIDY] Apply autopep8 formatting

This commit is contained in:
Jannik Beyerstedt 2023-10-29 11:53:59 +01:00
parent 909bf79673
commit b0e83b1134
12 changed files with 405 additions and 329 deletions

2
.pep8 Normal file
View file

@ -0,0 +1,2 @@
[pycodestyle]
max_line_length = 99

View file

@ -4,6 +4,7 @@
import math
def easeLinear(t, b, c, d):
return c*t/d + b
@ -12,19 +13,22 @@ def easeOutCubic(t, b, c, d):
t = float(t)/d-1
return c*((t)*t*t + 1) + b
def easeInCubic(t, b, c, d):
t = float(t)/d
return c*(t)*t*t + b;
return c*(t)*t*t + b
def easeInQuad(t, b, c, d):
t /= d
return c*t*t + b
def easeOutQuad(t, b, c, d):
t /= d
return -c * t*(t-2) + b
def easeInOutQuad(t, b, c, d):
t /= d/2
if t < 1:
@ -40,15 +44,18 @@ def easeInOutCubic(t, b, c, d):
t -= 2
return c/2*(t*t*t + 2) + b
def easeInQuart(t, b, c, d):
t /= d
return c*t*t*t*t + b
def easeOutQuart(t, b, c, d):
t /= d
t -= 1
return -c * (t*t*t*t - 1) + b
def easeInOutQuart(t, b, c, d):
t /= d/2
if t < 1:
@ -56,15 +63,18 @@ def easeInOutQuart(t, b, c, d):
t -= 2
return -c/2 * (t*t*t*t - 2) + b
def easeInQuint(t, b, c, d):
t /= d
return c*t*t*t*t*t + b
def easeOutQuint(t, b, c, d):
t /= d
t -= 1
return c*(t*t*t*t*t + 1) + b
def easeInOutQuint(t, b, c, d):
t /= d/2
if t < 1:
@ -72,9 +82,11 @@ def easeInOutQuint(t, b, c, d):
t -= 2
return c/2*(t*t*t*t*t + 2) + b
def easeInSine(t, b, c, d):
return -c * math.cos(t/d * (math.pi/2)) + c + b
def easeOutSine(t, b, c, d):
return c * math.sin(t/d * (math.pi/2)) + b
@ -82,9 +94,11 @@ def easeOutSine(t, b, c, d):
def easeInOutSine(t, b, c, d):
return -c/2 * (math.cos(math.pi*t/d) - 1) + b
def easeInExpo(t, b, c, d):
return c * math.pow(2, 10 * (t/d - 1)) + b
def easeOutExpo(t, b, c, d):
return c * (-math.pow(2, -10 * t/d) + 1) + b
@ -96,15 +110,18 @@ def easeInOutExpo(t, b, c, d):
t -= 1
return c/2 * (-math.pow(2, -10 * t) + 2) + b
def easeInCirc(t, b, c, d):
t /= d
return -c * (math.sqrt(1 - t*t) - 1) + b
def easeOutCirc(t, b, c, d):
t /= d;
t /= d
t -= 1
return c * math.sqrt(1 - t*t) + b
def easeInOutCirc(t, b, c, d):
t /= d/2
if t < 1:
@ -132,6 +149,7 @@ def easeInElastic(t, b, c, d, s = 1.70158):
t -= 1
return -(a * pow(2, 10 * t) * math.sin((t * d - s) * (2 * math.pi) / p)) + b
def easeOutElastic(t, b, c, d, a=1.70158):
if t == 0:
return b
@ -147,6 +165,7 @@ def easeOutElastic(t, b, c, d, a = 1.70158):
return a * pow(2, -10 * t) * math.sin((t * d - s) * (2 * math.pi) / p) + c + b
def easeInOutElastic(t, b, c, d, a=1.70158):
if t == 0:
return b
@ -167,45 +186,51 @@ def easeInOutElastic(t, b, c, d, a = 1.70158):
t -= 1
return a * pow(2, -10 * t) * math.sin((t * d - s) * (2 * math.pi) / p) * 0.5 + c + b
def easeInBack(t, b, c, d, s=1.70158):
t /= d
return c * t * t * ((s + 1) * t - s) + b
def easeOutBack(t, b, c, d, s=1.70158):
t = t / d - 1
return c * (t * t * ((s + 1) * t + s) + 1) + b
def easeInOutBack(t, b, c, d, s=1.70158):
t /= d / 2
s *= 1.525
if t < 1:
return c / 2 * (t * t * ((s + 1) * t - s)) + b;
return c / 2 * (t * t * ((s + 1) * t - s)) + b
t -= 2
return c/2 * (t * t * ((s + 1) * t + s) + 2) + b;
return c/2 * (t * t * ((s + 1) * t + s) + 2) + b
def easeInBounce(t, b, c, d):
return c - easeOutBounce(d-t, 0, c, d) + b;
return c - easeOutBounce(d-t, 0, c, d) + b
def easeOutBounce(t, b, c, d):
t /= d
if t < (1/2.75):
return c*(7.5625*t*t) + b;
return c*(7.5625*t*t) + b
elif t < (2/2.75):
t -= (1.5/2.75)
return c*(7.5625*t*t + 0.75) + b;
return c*(7.5625*t*t + 0.75) + b
elif t < (2.5/2.75):
t -= (2.25/2.75)
return c*(7.5625*t*t + 0.9375) + b;
return c*(7.5625*t*t + 0.9375) + b
else:
t -= (2.625/2.75)
return c*(7.5625*t*t + 0.984375) + b;
return c*(7.5625*t*t + 0.984375) + b
def easeInOutBounce(t, b, c, d):
if t < d/2:
return easeInBounce(t*2, 0, c, d) * .5 + b;
return easeInBounce(t*2, 0, c, d) * .5 + b
return easeOutBounce(t*2-d, 0, c, d) * .5 + c*.5 + b;
return easeOutBounce(t*2-d, 0, c, d) * .5 + c*.5 + b

View file

@ -117,6 +117,7 @@ def fmt_command(command, **kwargs):
def run(command, **kwargs):
os.system(fmt_command(command, **kwargs))
def run_output(command, **kwargs):
# Apple Compressor behaves weirdly with its stdout. It will not terminate right when ran through
# os.subprocess, but work fine when run via os.system. To still get the output, we pipe it into a
@ -127,6 +128,7 @@ def run_output(command, **kwargs):
os.system(f'{cmd} >{t.name} 2>&1')
return t.read().decode('utf-8')
def enqueue_job(event):
event_id = str(event['id'])
work_doc = os.path.join(tempdir.name, event_id + '.motn')
@ -156,7 +158,8 @@ def enqueue_job(event):
def fetch_job_status():
compressor_status = run_output('/Applications/Compressor.app/Contents/MacOS/Compressor -monitor')
compressor_status = run_output(
'/Applications/Compressor.app/Contents/MacOS/Compressor -monitor')
job_status_matches = re.finditer(r"<jobStatus (.*) \/jobStatus>", compressor_status)
status_dict = {}
@ -188,7 +191,8 @@ def filter_finished_jobs(active_jobs):
elif status == 'Successful':
finished_jobs.append((job_id, event))
else:
event_print(event, "failed with staus=" + status + " removing from postprocessing queue")
event_print(event, "failed with staus=" + status +
" removing from postprocessing queue")
return new_active_jobs, finished_jobs
@ -209,6 +213,7 @@ def finalize_job(job_id, event):
event_print(event, "finalized intro to " + final_clip)
active_jobs = []
if args.ids:
@ -219,7 +224,8 @@ if args.exclude_ids:
filtered_events = events
filtered_events = filter(lambda event: not args.ids or event['id'] in args.ids, filtered_events)
filtered_events = filter(lambda event: not args.exclude_ids or event['id'] not in args.exclude_ids, filtered_events)
filtered_events = filter(
lambda event: not args.exclude_ids or event['id'] not in args.exclude_ids, filtered_events)
filtered_events = list(filtered_events)
print("enqueuing {} jobs into compressor".format(len(filtered_events)))

View file

@ -228,7 +228,8 @@ def enqueue_job(event):
if platform.system() == 'Darwin':
if args.debug:
print("running: Blender.app --background %s --python-use-system-env --python %s --use-extension 0 --threads 0 --render-output %s --render-anim" % (work_source, work_doc, intermediate_clip))
print("running: Blender.app --background %s --python-use-system-env --python %s --use-extension 0 --threads 0 --render-output %s --render-anim" %
(work_source, work_doc, intermediate_clip))
run(r'/Applications/Blender.app/Contents/MacOS/Blender --background {source} --python-use-system-env --python {jobpath} --use-extension 0 --threads 0 --render-output {locationpath} --render-anim',
source=work_source,
jobpath=work_doc,
@ -236,14 +237,16 @@ def enqueue_job(event):
if platform.system() == 'Windows':
if args.debug:
print("running: blender.exe --background %s --python-use-system-env --python %s --use-extension 0 --threads 0 --render-output %s --render-anim" % (work_source, work_doc, intermediate_clip))
print("running: blender.exe --background %s --python-use-system-env --python %s --use-extension 0 --threads 0 --render-output %s --render-anim" %
(work_source, work_doc, intermediate_clip))
run(r'C:/Program\ Files/Blender\ Foundation/Blender\ 2.92/blender.exe --background {source} --python-use-system-env --python {jobpath} --use-extension 0 --threads 0 --render-output {locationpath} --render-anim',
source=work_source,
jobpath=work_doc,
locationpath=intermediate_clip)
if platform.system() == 'Linux':
if args.debug:
print("running: blender --background %s --python-use-system-env --python %s --use-extension 0 --threads 0 --render-output %s --render-anim" % (work_source, work_doc, intermediate_clip))
print("running: blender --background %s --python-use-system-env --python %s --use-extension 0 --threads 0 --render-output %s --render-anim" %
(work_source, work_doc, intermediate_clip))
run(r'blender --background {source} --python-use-system-env --python {jobpath} --use-extension 0 --threads 0 --render-output {locationpath} --render-anim',
source=work_source,
jobpath=work_doc,

View file

@ -67,6 +67,7 @@ def error(str):
parser.print_help()
sys.exit(1)
cparser = ConfigParser()
cparser.read(os.path.join(os.path.dirname(args.project), 'config.ini'))
template = cparser['default']['template']
@ -145,6 +146,7 @@ if args.debug:
else:
events = list(schedulelib.events(schedule))
def describe_event(event):
return "#{}: {}".format(event['id'], event['title'])
@ -276,13 +278,17 @@ def enqueue_job(event):
if fileformat == '.mov':
if alpha == 'true':
if prores == 'true':
cmd = 'ffmpeg -y -i "{0}" -vf "{1}" -vcodec prores_ks -pix_fmt yuva444p10le -profile:v 4444 -shortest -movflags faststart -f mov "{2}"'.format(infile, videofilter, outfile)
cmd = 'ffmpeg -y -i "{0}" -vf "{1}" -vcodec prores_ks -pix_fmt yuva444p10le -profile:v 4444 -shortest -movflags faststart -f mov "{2}"'.format(
infile, videofilter, outfile)
else:
cmd = 'ffmpeg -y -i "{0}" -vf "{1}" -shortest -c:v qtrle -movflags faststart -f mov "{2}"'.format(infile, videofilter, outfile)
cmd = 'ffmpeg -y -i "{0}" -vf "{1}" -shortest -c:v qtrle -movflags faststart -f mov "{2}"'.format(
infile, videofilter, outfile)
else:
cmd = 'ffmpeg -y -i "{0}" -vf "{1}" -map 0:0 -c:v mpeg2video -q:v 2 -aspect 16:9 -map 0:1 -c:a mp2 -b:a 384k -shortest -f mpegts "{2}"'.format(infile, videofilter, outfile)
cmd = 'ffmpeg -y -i "{0}" -vf "{1}" -map 0:0 -c:v mpeg2video -q:v 2 -aspect 16:9 -map 0:1 -c:a mp2 -b:a 384k -shortest -f mpegts "{2}"'.format(
infile, videofilter, outfile)
else:
cmd = 'ffmpeg -y -i "{0}" -vf "{1}" -map 0:0 -c:v mpeg2video -pix_fmt:v yuv420p -qscale:v 2 -qmin:v 2 -qmax:v 7 -keyint_min 0 -bf 0 -g 0 -maxrate:0 90M -aspect 16:9 -map 0:1 -c:a mp2 -b:a 384k -shortest -f mpegts "{2}"'.format(infile, videofilter, outfile)
cmd = 'ffmpeg -y -i "{0}" -vf "{1}" -map 0:0 -c:v mpeg2video -pix_fmt:v yuv420p -qscale:v 2 -qmin:v 2 -qmax:v 7 -keyint_min 0 -bf 0 -g 0 -maxrate:0 90M -aspect 16:9 -map 0:1 -c:a mp2 -b:a 384k -shortest -f mpegts "{2}"'.format(
infile, videofilter, outfile)
if args.debug:
print(cmd)
@ -321,5 +327,3 @@ for event in events:
print('all done')

View file

@ -70,6 +70,7 @@ def error(str):
parser.print_help()
sys.exit(1)
cparser = ConfigParser()
cparser.read(os.path.join(os.path.dirname(args.project), 'config.ini'))
template = cparser['default']['template']
@ -148,6 +149,7 @@ if args.debug:
else:
events = list(schedulelib.events(schedule))
def describe_event(event):
return "#{}: {}".format(event['id'], event['title'])
@ -244,29 +246,41 @@ def enqueue_job(event):
if fontfile == 'true':
if platform.system() == 'Windows':
videofilter = "drawtext=enable='between({8},{0},{1})':fontfile='{2}':fontsize={3}:fontcolor={4}:x={5}:y={6}:text='{7}',".format(title_in, title_out, font_t_win, title_fontsize, title_fontcolor, title_x, title_y, t, inout)
videofilter += "drawtext=enable='between({8},{0},{1})':fontfile='{2}':fontsize={3}:fontcolor={4}:x={5}:y={6}:text='{7}':box=1,".format(speaker_in, speaker_out, font_s_win, speaker_fontsize, speaker_fontcolor, speaker_x, speaker_y, s, inout)
videofilter += "drawtext=enable='between({8},{0},{1})':fontfile='{2}':fontsize={3}:fontcolor={4}:x={5}:y={6}:text='{7}'".format(text_in, text_out, font_tt_win, text_fontsize, text_fontcolor, text_x, text_y, text_text, inout)
videofilter = "drawtext=enable='between({8},{0},{1})':fontfile='{2}':fontsize={3}:fontcolor={4}:x={5}:y={6}:text='{7}',".format(
title_in, title_out, font_t_win, title_fontsize, title_fontcolor, title_x, title_y, t, inout)
videofilter += "drawtext=enable='between({8},{0},{1})':fontfile='{2}':fontsize={3}:fontcolor={4}:x={5}:y={6}:text='{7}':box=1,".format(
speaker_in, speaker_out, font_s_win, speaker_fontsize, speaker_fontcolor, speaker_x, speaker_y, s, inout)
videofilter += "drawtext=enable='between({8},{0},{1})':fontfile='{2}':fontsize={3}:fontcolor={4}:x={5}:y={6}:text='{7}'".format(
text_in, text_out, font_tt_win, text_fontsize, text_fontcolor, text_x, text_y, text_text, inout)
else:
videofilter = "drawtext=enable='between({8},{0},{1})':fontfile='{2}':fontsize={3}:fontcolor={4}:x={5}:y={6}:text='{7}',".format(title_in, title_out, font_t, title_fontsize, title_fontcolor, title_x, title_y, t, inout)
videofilter += "drawtext=enable='between({8},{0},{1})':fontfile='{2}':fontsize={3}:fontcolor={4}:x={5}:y={6}:text='{7}':box=1,".format(speaker_in, speaker_out, font_s, speaker_fontsize, speaker_fontcolor, speaker_x, speaker_y, s, inout)
videofilter += "drawtext=enable='between({8},{0},{1})':fontfile='{2}':fontsize={3}:fontcolor={4}:x={5}:y={6}:text='{7}'".format(text_in, text_out, font_tt, text_fontsize, text_fontcolor, text_x, text_y, text_text, inout)
videofilter = "drawtext=enable='between({8},{0},{1})':fontfile='{2}':fontsize={3}:fontcolor={4}:x={5}:y={6}:text='{7}',".format(
title_in, title_out, font_t, title_fontsize, title_fontcolor, title_x, title_y, t, inout)
videofilter += "drawtext=enable='between({8},{0},{1})':fontfile='{2}':fontsize={3}:fontcolor={4}:x={5}:y={6}:text='{7}':box=1,".format(
speaker_in, speaker_out, font_s, speaker_fontsize, speaker_fontcolor, speaker_x, speaker_y, s, inout)
videofilter += "drawtext=enable='between({8},{0},{1})':fontfile='{2}':fontsize={3}:fontcolor={4}:x={5}:y={6}:text='{7}'".format(
text_in, text_out, font_tt, text_fontsize, text_fontcolor, text_x, text_y, text_text, inout)
else:
videofilter = "drawtext=enable='between({8},{0},{1})':font='{2}':fontsize={3}:fontcolor={4}:x={5}:y={6}:text='{7}',".format(title_in, title_out, title_fontfamily, title_fontsize, title_fontcolor, title_x, title_y, t, inout)
videofilter += "drawtext=enable='between({8},{0},{1})':font='{2}':fontsize={3}:fontcolor={4}:x={5}:y={6}:text='{7}':box=1,".format(speaker_in, speaker_out, speaker_fontfamily, speaker_fontsize, speaker_fontcolor, speaker_x, speaker_y, s, inout)
videofilter += "drawtext=enable='between({8},{0},{1})':font='{2}':fontsize={3}:fontcolor={4}:x={5}:y={6}:text='{7}'".format(text_in, text_out, text_fontfamily, text_fontsize, text_fontcolor, text_x, text_y, text_text, inout)
videofilter = "drawtext=enable='between({8},{0},{1})':font='{2}':fontsize={3}:fontcolor={4}:x={5}:y={6}:text='{7}',".format(
title_in, title_out, title_fontfamily, title_fontsize, title_fontcolor, title_x, title_y, t, inout)
videofilter += "drawtext=enable='between({8},{0},{1})':font='{2}':fontsize={3}:fontcolor={4}:x={5}:y={6}:text='{7}':box=1,".format(
speaker_in, speaker_out, speaker_fontfamily, speaker_fontsize, speaker_fontcolor, speaker_x, speaker_y, s, inout)
videofilter += "drawtext=enable='between({8},{0},{1})':font='{2}':fontsize={3}:fontcolor={4}:x={5}:y={6}:text='{7}'".format(
text_in, text_out, text_fontfamily, text_fontsize, text_fontcolor, text_x, text_y, text_text, inout)
if fileformat == '.mov':
if alpha == 'true':
if prores == 'true':
cmd = '{3} -y -i "{0}" -vf "{1}" -vcodec prores_ks -pix_fmt yuva444p10le -profile:v 4444 -shortest -movflags faststart -f mov "{2}"'.format(infile, videofilter, outfile, ffmpeg_path)
cmd = '{3} -y -i "{0}" -vf "{1}" -vcodec prores_ks -pix_fmt yuva444p10le -profile:v 4444 -shortest -movflags faststart -f mov "{2}"'.format(
infile, videofilter, outfile, ffmpeg_path)
else:
cmd = '{3} -y -i "{0}" -vf "{1}" -shortest -c:v qtrle -movflags faststart -f mov "{2}"'.format(infile, videofilter, outfile, ffmpeg_path)
cmd = '{3} -y -i "{0}" -vf "{1}" -shortest -c:v qtrle -movflags faststart -f mov "{2}"'.format(
infile, videofilter, outfile, ffmpeg_path)
else:
cmd = '{3} -y -i "{0}" -vf "{1}" -map 0:0 -c:v mpeg2video -q:v 2 -aspect 16:9 -map 0:1 -c:a mp2 -b:a 384k -shortest -f mpegts "{2}"'.format(infile, videofilter, outfile, ffmpeg_path)
cmd = '{3} -y -i "{0}" -vf "{1}" -map 0:0 -c:v mpeg2video -q:v 2 -aspect 16:9 -map 0:1 -c:a mp2 -b:a 384k -shortest -f mpegts "{2}"'.format(
infile, videofilter, outfile, ffmpeg_path)
else:
cmd = '{3} -y -i "{0}" -vf "{1}" -map 0:0 -c:v mpeg2video -q:v 2 -aspect 16:9 -map 0:1 -c:a mp2 -b:a 384k -shortest -f mpegts "{2}"'.format(infile, videofilter, outfile, ffmpeg_path)
cmd = '{3} -y -i "{0}" -vf "{1}" -map 0:0 -c:v mpeg2video -q:v 2 -aspect 16:9 -map 0:1 -c:a mp2 -b:a 384k -shortest -f mpegts "{2}"'.format(
infile, videofilter, outfile, ffmpeg_path)
if args.debug:
print(cmd)
@ -305,5 +319,3 @@ for event in events:
print('all done')

12
make.py
View file

@ -14,7 +14,8 @@ import renderlib
import argparse
# Parse arguments
parser = argparse.ArgumentParser(description='C3VOC Intro-Outro-Generator', usage="see help with option -h", formatter_class=argparse.RawTextHelpFormatter)
parser = argparse.ArgumentParser(description='C3VOC Intro-Outro-Generator',
usage="see help with option -h", formatter_class=argparse.RawTextHelpFormatter)
parser.add_argument('projectpath', action="store", metavar='yourproject/', type=str, help='''
Path to your project is a required argument.
Usage: ./make.py yourproject/
@ -87,7 +88,8 @@ projectpath = args.projectpath
try:
project = renderlib.loadProject(projectname)
except ImportError:
print("you must specify a project-name as first argument, eg. './make.py sotmeu14'. The supplied value '{0}' seems not to be a valid project (there is no '{0}/__init__.py').\n".format(projectname))
print(
"you must specify a project-name as first argument, eg. './make.py sotmeu14'. The supplied value '{0}' seems not to be a valid project (there is no '{0}/__init__.py').\n".format(projectname))
raise
# using --debug skips the threading, the network fetching of the schedule and
@ -98,7 +100,8 @@ renderlib.args = args
def render(infile, outfile, sequence, parameters={}, workdir=os.path.join(projectname, 'artwork')):
task = renderlib.Rendertask(infile=infile, outfile=outfile, sequence=sequence, parameters=parameters, workdir=workdir)
task = renderlib.Rendertask(infile=infile, outfile=outfile,
sequence=sequence, parameters=parameters, workdir=workdir)
return renderlib.rendertask(task)
@ -188,7 +191,8 @@ def worker():
renderlib.rendertask(task)
# print that we're finished
tprint('finished {0}, {1} tasks left'.format(task.outfile, max(0, tasks.qsize() - num_worker_threads)))
tprint('finished {0}, {1} tasks left'.format(
task.outfile, max(0, tasks.qsize() - num_worker_threads)))
# mark the task as finished
tasks.task_done()

View file

@ -19,6 +19,7 @@ args = None
scheduleTree = None
def loadProject(projectname):
sys.path.append(os.path.join(os.path.dirname(os.path.abspath(__file__)), projectname))
return __import__(projectname)
@ -70,6 +71,8 @@ class Rendertask:
return None
# try to create all folders needed and skip, they already exist
def ensurePathExists(path):
try:
os.makedirs(path)
@ -83,6 +86,7 @@ def ensureFilesRemoved(pattern):
for f in glob.glob(pattern):
os.unlink(f)
def renderFrame(infile, task, outfile):
width = 1920
height = 1080
@ -93,20 +97,25 @@ def renderFrame(infile, task, outfile):
converted.save(filename=outfile)
elif args.resvg:
# invoke inkscape to convert the generated svg-file into a png inside the .frames-directory
cmd = 'resvg --background white --width={1} --height={2} "{4}" "{3}" 2>&1 >/dev/null'.format(task.workdir, width, height, outfile, infile)
errorReturn = subprocess.check_output(cmd, shell=True, universal_newlines=True, stderr=subprocess.STDOUT, cwd=task.workdir)
cmd = 'resvg --background white --width={1} --height={2} "{4}" "{3}" 2>&1 >/dev/null'.format(
task.workdir, width, height, outfile, infile)
errorReturn = subprocess.check_output(
cmd, shell=True, universal_newlines=True, stderr=subprocess.STDOUT, cwd=task.workdir)
if errorReturn != '':
print("resvg exited with error\n" + errorReturn)
# sys.exit(42)
else:
# invoke inkscape to convert the generated svg-file into a png inside the .frames-directory
cmd = 'inkscape --export-background=white --export-background-opacity=0 --export-width={1} --export-height={2} --export-filename="{3}" "{4}" --pipe 2>&1 >/dev/null'.format(task.workdir, width, height, os.path.abspath(outfile), os.path.abspath(infile))
errorReturn = subprocess.check_output(cmd, shell=True, universal_newlines=True, stderr=subprocess.STDOUT, cwd=task.workdir)
cmd = 'inkscape --export-background=white --export-background-opacity=0 --export-width={1} --export-height={2} --export-filename="{3}" "{4}" --pipe 2>&1 >/dev/null'.format(
task.workdir, width, height, os.path.abspath(outfile), os.path.abspath(infile))
errorReturn = subprocess.check_output(
cmd, shell=True, universal_newlines=True, stderr=subprocess.STDOUT, cwd=task.workdir)
if errorReturn != '':
print("inkscape exited with error\n" + errorReturn)
# sys.exit(42)
def cachedRenderFrame(frame, frameNr, task, cache):
skip_rendering = False
# skip first n frames, to speed up rerendering during debugging
@ -129,7 +138,8 @@ def cachedRenderFrame(frame, frameNr, task, cache):
print("cache hit, reusing frame {0}".format(cache[frame]))
framedir = task.workdir + "/.frames/"
shutil.copyfile("{0}/{1:04d}.png".format(framedir, cache[frame]), "{0}/{1:04d}.png".format(framedir, frameNr))
shutil.copyfile("{0}/{1:04d}.png".format(framedir,
cache[frame]), "{0}/{1:04d}.png".format(framedir, frameNr))
return
elif not skip_rendering:
@ -157,6 +167,7 @@ def rendertask_image(task):
svg.write()
renderFrame(svgfile, task, task.outfile)
def rendertask_video(task):
# iterate through the animation sequence frame by frame
# frame is a ... tbd
@ -171,7 +182,8 @@ def rendertask_video(task):
ensureFilesRemoved(os.path.join(task.workdir, task.outfile))
if task.outfile.endswith('.png'):
cmd = 'cd {0} && cp ".frames/{1:04d}.png" "{2}"'.format(task.workdir, args.only_frame, task.outfile)
cmd = 'cd {0} && cp ".frames/{1:04d}.png" "{2}"'.format(
task.workdir, args.only_frame, task.outfile)
# invoke avconv aka ffmpeg and renerate a lossles-dv from the frames
# if we're not in debug-mode, suppress all output
@ -192,11 +204,14 @@ def rendertask_video(task):
cmd += '-shortest -f mpegts "{0}"'.format(task.outfile)
elif task.outfile.endswith('.mov'):
cmd = 'cd {0} && '.format(task.workdir)
cmd += 'ffmpeg -f lavfi -i anullsrc=channel_layout=stereo:sample_rate=44100 -f image2 -i .frames/%04d.png -r 25 -shortest -c:v qtrle -f mov "{0}"'.format(task.outfile)
cmd += 'ffmpeg -f lavfi -i anullsrc=channel_layout=stereo:sample_rate=44100 -f image2 -i .frames/%04d.png -r 25 -shortest -c:v qtrle -f mov "{0}"'.format(
task.outfile)
elif task.outfile.endswith('.mkv'):
cmd = 'cd {0} && ffmpeg -ar 48000 -ac 2 -f s16le -i /dev/zero -f image2 -i .frames/%04d.png -aspect 16:9 -c copy -shortest "{1}"'.format(task.workdir, task.outfile)
cmd = 'cd {0} && ffmpeg -ar 48000 -ac 2 -f s16le -i /dev/zero -f image2 -i .frames/%04d.png -aspect 16:9 -c copy -shortest "{1}"'.format(
task.workdir, task.outfile)
else:
cmd = 'cd {0} && ffmpeg -ar 48000 -ac 2 -f s16le -i /dev/zero -f image2 -i .frames/%04d.png -target pal-dv -aspect 16:9 -shortest "{1}"'.format(task.workdir, task.outfile)
cmd = 'cd {0} && ffmpeg -ar 48000 -ac 2 -f s16le -i /dev/zero -f image2 -i .frames/%04d.png -target pal-dv -aspect 16:9 -shortest "{1}"'.format(
task.workdir, task.outfile)
if debug:
print(cmd)
@ -208,14 +223,15 @@ def rendertask_video(task):
if r != 0:
sys.exit()
def rendertask(task):
global args
# in debug mode we have no thread-worker which prints its progress
if debug:
print("generating {0} from {1}".format(task.outfile, task.infile))
## Hacky workaround: Fix this properly without breaking the
## support for partially rendered intros
# Hacky workaround: Fix this properly without breaking the
# support for partially rendered intros
if True: # args.skip_frames and 'only_rerender_frames_after' not in task.parameters:
if os.path.isdir(os.path.join(task.workdir, '.frames')):
print("Removing", os.path.join(task.workdir, '.frames'))
@ -241,4 +257,3 @@ try:
except ImportError:
def colored(str, col):
return str

View file

@ -21,6 +21,7 @@ def downloadSchedule(scheduleUrl):
parser = etree.XMLParser(huge_tree=True)
return etree.fromstring(xml, parser)
def getSchedule(scheduleUrl):
global scheduleTree
if not scheduleTree:
@ -62,6 +63,7 @@ def persons(scheduleUrl, personmap={}, taglinemap={}, forEventId=None):
'tagline': tagline
}
def events(scheduleUrl, titlemap={}):
schedule = getSchedule(scheduleUrl)
# iterate all days
@ -117,4 +119,3 @@ try:
except ImportError:
def colored(str, col):
return str

View file

@ -35,6 +35,8 @@ if not os.environ.get('CRS_ROOM') is None:
filter['Fahrplan.Room'] = os.environ['CRS_ROOM']
projects = {}
def generatePreroll(ticket):
print(ticket)
projectname = ticket.get('Processing.Prerolls.Slug', ticket['Meta.Acronym'])
@ -55,9 +57,11 @@ def generatePreroll(ticket):
while True:
print(colored('Asking RPC for {0}-tickets which are ready for state {1}'.format(ticket_type, ticket_state), 'yellow'))
print(colored(
'Asking RPC for {0}-tickets which are ready for state {1}'.format(ticket_type, ticket_state), 'yellow'))
ticket_id = rpc.assignNextUnassignedForState(ticket_type, ticket_state, url, token, host, secret, filter)
ticket_id = rpc.assignNextUnassignedForState(
ticket_type, ticket_state, url, token, host, secret, filter)
if ticket_id != False:
ticket = rpc.getTicketProperties(str(ticket_id), url, token, host, secret)
try:
@ -72,5 +76,4 @@ while True:
print('No ticket found')
print('Sleeping for 30 seconds')
time.sleep(30);
time.sleep(30)

View file

@ -11,6 +11,7 @@ from xml.sax.saxutils import escape as xmlescape
cssutils.ser.prefs.lineSeparator = ' '
cssutils.log.setLevel(logging.FATAL)
class SVGTemplate:
def __init__(self, task, outfile):
self.task = task