add command line options to skip inkscape rendering

This commit is contained in:
Andreas Hubel 2017-10-24 19:45:16 +02:00
parent c593a0dd07
commit d851c1d989
2 changed files with 44 additions and 31 deletions

View file

@ -39,6 +39,10 @@ parser.add_argument('--skip', nargs='+', action="store", type=str, help='''
Example - only generate outro: ./make.py yourproject/ --skip pause bg Example - only generate outro: ./make.py yourproject/ --skip pause bg
Example - only generate pause and background: ./make.py yourproject/ --skip out Example - only generate pause and background: ./make.py yourproject/ --skip out
''') ''')
parser.add_argument('--skip-frames', action="store", default=None, type=int, help='''
Skip first n frames e.g. to quickly rerender during debugging.
Usage: ./make.py yourproject/ --debug --skip-frames 300
''')
if len(sys.argv) < 2: if len(sys.argv) < 2:
parser.print_help() parser.print_help()
@ -76,6 +80,7 @@ except ImportError:
# using --debug skips the threading, the network fetching of the schedule and # using --debug skips the threading, the network fetching of the schedule and
# just renders one type of video # just renders one type of video
renderlib.debug = args.debug renderlib.debug = args.debug
renderlib.args = args
#sys.exit(1) #sys.exit(1)
def render(infile, outfile, sequence, parameters={}, workdir=os.path.join(projectname, 'artwork')): def render(infile, outfile, sequence, parameters={}, workdir=os.path.join(projectname, 'artwork')):

View file

@ -18,6 +18,7 @@ from urllib.request import urlopen
# Frames per second. Increasing this renders more frames, the avconf-statements would still need modifications # Frames per second. Increasing this renders more frames, the avconf-statements would still need modifications
fps = 25 fps = 25
debug = False debug = False
args = None
cssutils.ser.prefs.lineSeparator = ' ' cssutils.ser.prefs.lineSeparator = ' '
cssutils.log.setLevel(logging.FATAL) cssutils.log.setLevel(logging.FATAL)
@ -73,6 +74,7 @@ def ensureFilesRemoved(pattern):
os.unlink(f) os.unlink(f)
def rendertask(task): def rendertask(task):
global args
# in debug mode we have no thread-worker which prints its progress # in debug mode we have no thread-worker which prints its progress
if debug: if debug:
print("generating {0} from {1}".format(task.outfile, task.infile)) print("generating {0} from {1}".format(task.outfile, task.infile))
@ -96,8 +98,11 @@ def rendertask(task):
# frame is a ... tbd # frame is a ... tbd
cache = {} cache = {}
for frame in task.sequence(task.parameters): for frame in task.sequence(task.parameters):
skip_rendering = False
if args.skip_frames:
skip_rendering = (frameNr <= args.skip_frames)
# print a line for each and every frame generated # print a line for each and every frame generated
if debug: if debug and not skip_rendering:
print("frameNr {0:3d} => {1}".format(frameNr, frame)) print("frameNr {0:3d} => {1}".format(frameNr, frame))
frame = tuple(frame) frame = tuple(frame)
@ -113,39 +118,41 @@ def rendertask(task):
else: else:
cache[frame] = frameNr cache[frame] = frameNr
# open the output-file (named ".gen.svg" in the workdir) # apply the replace-pairs to the input text, by finding the specified xml-elements by thier id and modify thier css-parameter the correct value
with open(os.path.join(task.workdir, '.gen.svg'), 'w') as fp: for replaceinfo in frame:
# apply the replace-pairs to the input text, by finding the specified xml-elements by thier id and modify thier css-parameter the correct value (id, type, key, value) = replaceinfo
for replaceinfo in frame:
(id, type, key, value) = replaceinfo
for el in svg.findall(".//*[@id='"+id.replace("'", "\\'")+"']"): for el in svg.findall(".//*[@id='"+id.replace("'", "\\'")+"']"):
if type == 'style': if type == 'style':
style = cssutils.parseStyle( el.attrib['style'] if 'style' in el.attrib else '' ) style = cssutils.parseStyle( el.attrib['style'] if 'style' in el.attrib else '' )
style[key] = str(value) style[key] = str(value)
el.attrib['style'] = style.cssText el.attrib['style'] = style.cssText
elif type == 'attr': elif type == 'attr':
el.attrib[key] = str(value) el.attrib[key] = str(value)
elif type == 'text': elif type == 'text':
el.text = str(value) el.text = str(value)
# write the generated svg-text into the output-file if not skip_rendering:
fp.write( etree.tostring(svg, encoding='unicode') ) # open the output-file (named ".gen.svg" in the workdir)
with open(os.path.join(task.workdir, '.gen.svg'), 'w') as fp:
if task.outfile.endswith('.ts'): # write the generated svg-text into the output-file
width = 1920 fp.write( etree.tostring(svg, encoding='unicode') )
height = 1080
else: if task.outfile.endswith('.ts'):
width = 1024 width = 1920
height = 576 height = 1080
else:
# invoke inkscape to convert the generated svg-file into a png inside the .frames-directory width = 1024
errorReturn = subprocess.check_output('cd {0} && inkscape --export-background=white --export-width={2} --export-height={3} --export-png=$(pwd)/.frames/{1:04d}.png $(pwd)/.gen.svg 2>&1 >/dev/null'.format(task.workdir, frameNr, width, height), shell=True, universal_newlines=True) height = 576
if errorReturn != '':
print("inkscape exitted with error\n"+errorReturn) # invoke inkscape to convert the generated svg-file into a png inside the .frames-directory
sys.exit(42) cmd = 'cd {0} && inkscape --export-background=white --export-width={2} --export-height={3} --export-png=$(pwd)/.frames/{1:04d}.png $(pwd)/.gen.svg 2>&1 >/dev/null'.format(task.workdir, frameNr, width, height)
errorReturn = subprocess.check_output(cmd, shell=True, universal_newlines=True, stderr=subprocess.STDOUT)
if errorReturn != '':
print("inkscape exitted with error\n"+errorReturn)
sys.exit(42)
# increment frame-number # increment frame-number
frameNr += 1 frameNr += 1
@ -186,7 +193,8 @@ def rendertask(task):
print("cleanup") print("cleanup")
# remove the .frames-dir with all frames in it # remove the .frames-dir with all frames in it
shutil.rmtree(os.path.join(task.workdir, '.frames')) if not debug:
shutil.rmtree(os.path.join(task.workdir, '.frames'))
# remove the generated svg # remove the generated svg
ensureFilesRemoved(os.path.join(task.workdir, '.gen.svg')) ensureFilesRemoved(os.path.join(task.workdir, '.gen.svg'))