This commit is contained in:
Christophe SEUX
2023-04-22 21:12:21 +02:00
parent d0230672f4
commit 5c35bae0e3
4 changed files with 159 additions and 53 deletions
+83 -10
View File
@@ -9,7 +9,9 @@ from bpy.app.handlers import persistent
from vse_toolbox.bl_utils import get_scene_settings, get_strip_settings
from vse_toolbox.constants import SOUND_SUFFIXES
import multiprocessing
#import multiprocessing
#from multiprocessing.pool import ThreadPool
import subprocess
def new_text_strip(name='Text', channel=0, start=0, end=50, text='Text', font_size=48,
@@ -131,18 +133,69 @@ def get_strip_render_path(strip, template):
render_path = template.format(strip_name=strip.name, ext=suffix[1:])
return Path(os.path.abspath(bpy.path.abspath(render_path)))
def render_strips(strips, template):
scn = bpy.context.scene
scene_start = scn.frame_start
scene_end = scn.frame_end
render_path = scn.render.filepath
'''
# def render_strip_background(blender_path, filepath, start, end, output):
# cmd = [
# blender_path, '-b', '--factory-startup', str(tmp_path), '-a',
# '-s', str(start), '-e', str(end),
# '-o', str(output)
# ]
# pool = multiprocessing.Pool(4)
# p.map(func, range(1, 100))
# print(cmd)
# process = subprocess.call(cmd)
def render_strips(strips, template):
from functools import partial
scn = bpy.context.scene
# scene_start = scn.frame_start
# scene_end = scn.frame_end
# render_path = scn.render.filepath
tmp_name = Path(bpy.data.filepath).name if bpy.data.filepath else 'Untitled.blend'
tmp_path = Path(bpy.app.tempdir, tmp_name)
bpy.ops.wm.save_as_mainfile(filepath=str(tmp_path), copy=True)
script_code = dedent(f"""
import bpy
for
""")
script_path = Path(bpy.app.tempdir) / 'bundle_library.py'
script_path.write_text(script_code)
cmd = [bpy.app.binary_path, tmp_path, '--python', ]
# nb_threads = min(multiprocessing.cpu_count()-2, 8)
# print(nb_threads)
# pool = multiprocessing.Pool(nb_threads)
#arguments = [(bpy.app.binary_path, str(tmp_path), s.frame_final_start, s.frame_final_end-1, str(get_strip_render_path(s, template))) for s in strips]
#print(arguments)
#pool.starmap(render_strip_background, arguments)
# def render_strip_background(index):
# cmd = [bpy.app.binary_path, etc]
# process = subprocess.Popen(substr + " --index {}".format(index), shell=True, stdout=subprocess.PIPE)
# process = subprocess.Popen(cmd)
# pool = ThreadPool(nb_threads)
# for strip in strips:
# start = strip.frame_final_start
# end = strip.frame_final_end-1
# output = str(get_strip_render_path(strip, template))
# cmd = [
# bpy.app.binary_path, '-b', str(tmp_path),
# '-s', str(start), '-e', str(end), '-a',
# '-o', str(output)
# ]
for strip in strips:
@@ -161,6 +214,25 @@ def render_strips(strips, template):
bpy.ops.render.opengl(animation=True, sequencer=True)
scn.frame_start = scene_start
scn.frame_end = scene_end
scn.render.filepath = render_path
'''
def render_strips(strips, template):
scn = bpy.context.scene
scene_start = scn.frame_start
scene_end = scn.frame_end
render_path = scn.render.filepath
for strip in strips:
scn.frame_start = strip.frame_final_start
scn.frame_end = strip.frame_final_end - 1
scn.render.filepath = str(get_strip_render_path(strip, template))
print(f'Render Strip to {scn.render.filepath}')
bpy.ops.render.opengl(animation=True, sequencer=True)
scn.frame_start = scene_start
scn.frame_end = scene_end
scn.render.filepath = render_path
@@ -278,7 +350,8 @@ def import_sound(filepath):
if bpy.data.is_saved:
strip.sound.filepath = bpy.path.relpath(str(filepath))
strip.show_waveform = True
strip.show_waveform = True if strip.frame_final_duration < 10000 else False
return strip
def clean_sequencer(edit=False, movie=False, sound=False):