From e7f83afeafb4a22dcb0696fece45eac5cc4ac764 Mon Sep 17 00:00:00 2001 From: Konstantin Dmitriev Date: Thu, 25 May 2023 16:11:04 +0700 Subject: [PATCH] feat(opentoonz): Add possibility to render to avi format --- renderchan/contrib/opentoonz.py | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/renderchan/contrib/opentoonz.py b/renderchan/contrib/opentoonz.py index a5ce082..eda10bf 100644 --- a/renderchan/contrib/opentoonz.py +++ b/renderchan/contrib/opentoonz.py @@ -7,6 +7,7 @@ import subprocess import os import random +import shutil class RenderChanOpentoonzModule(RenderChanModule): def __init__(self): @@ -25,19 +26,34 @@ def getInputFormats(self): return ["tnz"] def getOutputFormats(self): - return ["png", "tiff"] + return ["png", "tiff", "avi"] def render(self, filename, outputPath, startFrame, endFrame, format, updateCompletion, extraParams={}): updateCompletion(0.0) - - if not os.path.exists(outputPath): - os.mkdir(outputPath) + + if format == "avi": + img_format="tiff" + img_outputPath=outputPath+"."+img_format + else: + img_format=format + img_outputPath=outputPath + + if os.path.exists(img_outputPath): + shutil.rmtree(img_outputPath) + os.mkdir(img_outputPath) # TODO: Progress callback os.chdir(os.path.dirname(self.conf['binary'])) - commandline=[self.conf['binary'], filename, "-o", os.path.join(outputPath, "image."+format), "-nthreads", extraParams['nthreads'], "-step", extraParams['step'], "-shrink", extraParams['shrink'], "-multimedia", extraParams['multimedia']] + + commandline=[self.conf['binary'], filename, "-o", os.path.join(img_outputPath, "image."+img_format), "-nthreads", extraParams['nthreads'], "-step", extraParams['step'], "-shrink", extraParams['shrink'], "-multimedia", extraParams['multimedia']] subprocess.check_call(commandline) + + if format == "avi": + #TODO: Detect frame rate! + commandline=[self.findBinary("ffmpeg"), "-r", "24", "-f", "image2", "-i", os.path.join(img_outputPath, "image.%04d."+img_format), outputPath] + subprocess.check_call(commandline) + shutil.rmtree(img_outputPath) updateCompletion(1.0)