rewrite import_shots and cleanup
This commit is contained in:
+66
-30
@@ -13,6 +13,7 @@ from vse_toolbox.constants import SOUND_SUFFIXES
|
||||
#import multiprocessing
|
||||
#from multiprocessing.pool import ThreadPool
|
||||
import subprocess
|
||||
from collections import defaultdict
|
||||
|
||||
|
||||
def frame_to_timecode(frame, fps):
|
||||
@@ -95,8 +96,7 @@ def get_strip_sequence_name(strip):
|
||||
else:
|
||||
return 'NoSequence'
|
||||
|
||||
def rename_strips(
|
||||
strips, template, increment=10, start_number=0, by_sequence=False):
|
||||
def rename_strips(strips, template, increment=10, start_number=0, padding=3, by_sequence=False):
|
||||
scn = bpy.context.scene
|
||||
settings = get_scene_settings()
|
||||
|
||||
@@ -110,16 +110,20 @@ def rename_strips(
|
||||
|
||||
for strip in strips:
|
||||
sequence_name = get_strip_sequence_name(strip)
|
||||
sequence_data = parse(project.sequence_template, sequence_name)
|
||||
|
||||
if (by_sequence and prev_sequence_name and
|
||||
sequence_name and sequence_name != prev_sequence_name):
|
||||
strip_number = 0
|
||||
|
||||
name = template.format(
|
||||
sequence=sequence_name,
|
||||
format_data = dict(
|
||||
sequence_strip=sequence_name,
|
||||
episode=episode_name,
|
||||
index=strip_number*increment+start_number
|
||||
)
|
||||
shot=str(strip_number*increment + start_number).zfill(padding))
|
||||
|
||||
format_data.update(sequence_data)
|
||||
|
||||
name = template.format(**format_data)
|
||||
|
||||
existing_strip = scn.sequence_editor.sequences_all.get(name)
|
||||
if existing_strip:
|
||||
@@ -399,8 +403,13 @@ def import_movie(filepath):
|
||||
res_x = scn.render.resolution_x
|
||||
res_y = scn.render.resolution_y
|
||||
|
||||
if bpy.data.is_saved:
|
||||
relpath = Path(bpy.path.relpath(str(filepath)))
|
||||
if len(relpath.as_posix()) < len(filepath.as_posix()):
|
||||
filepath = relpath
|
||||
|
||||
strip = scn.sequence_editor.sequences.new_movie(
|
||||
name=filepath.stem,
|
||||
name=Path(filepath).stem,
|
||||
filepath=str(filepath),
|
||||
channel=get_channel_index('Movie'),
|
||||
frame_start=scn.frame_start
|
||||
@@ -414,28 +423,48 @@ def import_movie(filepath):
|
||||
if src_height != res_y:
|
||||
strip.transform.scale_y = (res_y / src_height)
|
||||
|
||||
if bpy.data.is_saved:
|
||||
strip.filepath = bpy.path.relpath(str(filepath))
|
||||
|
||||
|
||||
return strip
|
||||
|
||||
def import_sound(filepath):
|
||||
def scale_clip_to_fit(strip):
|
||||
scn = bpy.context.scene
|
||||
res = scn.render.resolution_x, scn.render.resolution_y
|
||||
strip_res = strip.elements[0].orig_width, strip.elements[0].orig_height
|
||||
|
||||
#print(strip.name, strip_res, width, height)
|
||||
|
||||
strip.transform.scale_x = res[0] / strip_res[0]
|
||||
strip.transform.scale_y = strip.transform.scale_x
|
||||
|
||||
def import_sound(filepath, frame_start=None, frame_end=None):
|
||||
scn = bpy.context.scene
|
||||
|
||||
strip = scn.sequence_editor.sequences.new_sound(
|
||||
name=filepath.stem,
|
||||
filepath=str(filepath),
|
||||
channel=get_channel_index('Audio'),
|
||||
frame_start=scn.frame_start
|
||||
)
|
||||
if frame_start is None:
|
||||
frame_start = scn.frame_start
|
||||
|
||||
if bpy.data.is_saved:
|
||||
strip.sound.filepath = bpy.path.relpath(str(filepath))
|
||||
relpath = Path(bpy.path.relpath(str(filepath)))
|
||||
if len(relpath.as_posix()) < len(filepath.as_posix()):
|
||||
filepath = relpath
|
||||
|
||||
strip.show_waveform = True if strip.frame_final_duration < 10000 else False
|
||||
strip = scn.sequence_editor.sequences.new_sound(
|
||||
name=f'{filepath.stem} Audio',
|
||||
filepath=str(filepath),
|
||||
channel=get_channel_index('Audio'),
|
||||
frame_start=frame_start
|
||||
)
|
||||
|
||||
if frame_end is not None:
|
||||
strip.frame_final_end = frame_end
|
||||
|
||||
#strip.show_waveform = True if strip.frame_final_duration < 10000 else False
|
||||
|
||||
return strip
|
||||
|
||||
def get_empty_channel():
|
||||
return max(s.channel for s in bpy.context.scene.sequence_editor.sequences) + 1
|
||||
|
||||
def clean_sequencer(edit=False, movie=False, sound=False):
|
||||
scn = bpy.context.scene
|
||||
sequences = []
|
||||
@@ -470,44 +499,51 @@ def set_active_strip(scene):
|
||||
|
||||
@persistent
|
||||
def update_text_strips(scene):
|
||||
if not scene.sequence_editor or not scene.sequence_editor.sequences_all:
|
||||
return
|
||||
|
||||
#print("update_text_strips")
|
||||
settings = get_scene_settings()
|
||||
project = settings.active_project
|
||||
episode = settings.active_episode
|
||||
|
||||
|
||||
class MissingKey(dict):
|
||||
def __missing__(self, key):
|
||||
return '{' + key + '}'
|
||||
|
||||
|
||||
scn = bpy.context.scene
|
||||
if not scn.sequence_editor:
|
||||
return
|
||||
|
||||
format_data = {
|
||||
'scene': scene,
|
||||
'project_name': 'None',
|
||||
'episode_name': 'None',
|
||||
'sequence_name': 'None',
|
||||
'strip_name': 'None',
|
||||
'shot_name': 'None',
|
||||
'project': '...',
|
||||
'episode': '...',
|
||||
'sequence': '...',
|
||||
'sequence_strip': '...',
|
||||
'shot': '...',
|
||||
'shot_strip': '...',
|
||||
'shot_frame': 0,
|
||||
'shot_duration': 0,
|
||||
'shot_start': 0,
|
||||
'shot_end': 0,
|
||||
'time_code': ''
|
||||
'timecode': ''
|
||||
}
|
||||
|
||||
shot_strip = get_strip_at('Shots', frame=scene.frame_current)
|
||||
if shot_strip:
|
||||
format_data.update({
|
||||
'project_name': project.name,
|
||||
'episode_name': episode.name if episode else '',
|
||||
'sequence_name': get_strip_sequence_name(shot_strip),
|
||||
'strip_name': shot_strip.name,
|
||||
'shot_name': 'sh{index:04d}'.format(**shot_strip.vsetb_strip_settings.format_data),
|
||||
'project': project.name,
|
||||
'episode': episode.name if episode else '',
|
||||
'shot_duration': shot_strip.frame_final_duration,
|
||||
'shot_frame': scene.frame_current - shot_strip.frame_final_start + 1,
|
||||
'shot_start': shot_strip.frame_final_start,
|
||||
'shot_end': shot_strip.frame_final_end,
|
||||
'timecode' : frame_to_timecode(scene.frame_current, scene.render.fps)
|
||||
})
|
||||
format_data.update(shot_strip.vsetb_strip_settings.format_data)
|
||||
|
||||
for strip in scene.sequence_editor.sequences_all:
|
||||
if not strip.type == 'TEXT':
|
||||
@@ -520,4 +556,4 @@ def update_text_strips(scene):
|
||||
strip['text_pattern'] = strip.text
|
||||
|
||||
if 'text_pattern' in strip.keys():
|
||||
strip.text = strip['text_pattern'].format(**format_data)
|
||||
strip.text = strip['text_pattern'].format_map(MissingKey(**format_data))
|
||||
Reference in New Issue
Block a user