import edl, import movie, import audio
This commit is contained in:
+108
-29
@@ -10,7 +10,7 @@ def get_strips(channel=0, selected_only=False):
|
||||
scn = bpy.context.scene
|
||||
|
||||
if isinstance(channel, str):
|
||||
channel = scn.sequence_editor.channels.keys().index(channel)
|
||||
channel = get_channel(channel)
|
||||
|
||||
strips = [s for s in scn.sequence_editor.sequences_all if s.channel==channel]
|
||||
|
||||
@@ -19,6 +19,16 @@ def get_strips(channel=0, selected_only=False):
|
||||
|
||||
return sorted(strips, key=lambda x : x.frame_final_start)
|
||||
|
||||
def get_channel(name):
|
||||
scn = bpy.context.scene
|
||||
|
||||
channel_id = 0
|
||||
channel = scn.sequence_editor.channels.get(name)
|
||||
if channel:
|
||||
channel_id = scn.sequence_editor.channels.keys().index(name)
|
||||
|
||||
return channel_id
|
||||
|
||||
def get_shot_sequence(shot):
|
||||
sequences = get_strips(channel='Sequences')
|
||||
return next((s.name for s in sequences if s.frame_final_start<=shot.frame_final_start<s.frame_final_end), '')
|
||||
@@ -59,7 +69,7 @@ def rename_strips(
|
||||
def set_channels():
|
||||
scn = bpy.context.scene
|
||||
settings = get_settings()
|
||||
items = settings.rna_type.bl_rna.properties['channels'].enum_items
|
||||
items = settings.rna_type.bl_rna.properties['channel'].enum_items
|
||||
|
||||
for i, c in enumerate(items.keys(), start=1):
|
||||
scn.sequence_editor.channels[i].name = c.title()
|
||||
@@ -68,18 +78,35 @@ def render_strips(strips):
|
||||
for strip in strips:
|
||||
print(strip.name)
|
||||
|
||||
def import_edl(filepath, adapter="cmx_3600"):
|
||||
def import_edit(filepath, adapter="cmx_3600", clean_sequencer=False):
|
||||
import opentimelineio as otio
|
||||
from opentimelineio.schema import (
|
||||
Clip,
|
||||
ExternalReference,
|
||||
Gap,
|
||||
ImageSequenceReference,
|
||||
Stack,
|
||||
Timeline,
|
||||
Track,
|
||||
)
|
||||
|
||||
scn = bpy.context.scene
|
||||
|
||||
sequences = scn.sequence_editor.sequences
|
||||
|
||||
edl = Path(filepath)
|
||||
if clean_sequencer:
|
||||
movie = get_strips(channel='Movie')
|
||||
audio = get_strips(channel='Audio')
|
||||
|
||||
for strip in sequences:
|
||||
if strip not in (movie+audio):
|
||||
sequences.remove(strip)
|
||||
|
||||
edl = Path(filepath)
|
||||
try:
|
||||
timeline = otio.adapters.read_from_file(
|
||||
str(edl), adapter, rate=scn.render.fps, ignore_timecode_mismatch=True)
|
||||
except:
|
||||
print("[>.] read_from_file Failed. Using read_from_string method.")
|
||||
data = edl.read_text(encoding='latin-1')
|
||||
timeline = otio.adapters.read_from_string(
|
||||
data, adapter, rate=scn.render.fps, ignore_timecode_mismatch=True)
|
||||
@@ -87,46 +114,98 @@ def import_edl(filepath, adapter="cmx_3600"):
|
||||
scn.frame_start = (
|
||||
0 if timeline.global_start_time is None else timeline.global_start_time
|
||||
)
|
||||
scn.frame_end = otio.opentime.to_frames(timeline.duration()) - 1
|
||||
# scn.frame_end = otio.opentime.to_frames(timeline.duration())
|
||||
|
||||
for i, track in enumerate(timeline.tracks, 1):
|
||||
for child in track.each_child(shallow_search=False):
|
||||
for track in timeline.tracks:
|
||||
for child in track.each_child(shallow_search=True):
|
||||
|
||||
# FIXME Exclude Gaps for now. Gaps are Transitions, Blank Spaces...
|
||||
# if type(child) != Clip:
|
||||
if not isinstance(child, Clip):
|
||||
continue
|
||||
|
||||
# FIXME Exclude Audio for now
|
||||
if any(child.name.endswith(ext) for ext in ('.wav', '.mp3')):
|
||||
channel = get_channel('Audio')
|
||||
continue
|
||||
|
||||
channel = get_channel('Shots')
|
||||
frame_start = otio.opentime.to_frames(
|
||||
child.range_in_parent().start_time)
|
||||
|
||||
frame_end = otio.opentime.to_frames(
|
||||
child.range_in_parent().duration) - 1
|
||||
frame_end = frame_start + otio.opentime.to_frames(
|
||||
child.range_in_parent().duration)
|
||||
|
||||
try:
|
||||
strip = sequences.new_effect(
|
||||
name='',
|
||||
name=child.name,
|
||||
type='COLOR',
|
||||
channel=i,
|
||||
channel=channel,
|
||||
frame_start=frame_start,
|
||||
frame_end=frame_end,
|
||||
)
|
||||
strip.blend_alpha = 0.0
|
||||
|
||||
except Exception as e:
|
||||
print('e: ', e)
|
||||
continue
|
||||
|
||||
"""
|
||||
t = otio.adapters.read_from_file(edl, rate=C.scene.render.fps)
|
||||
t.video_tracks() # Video Tracks du fichiers. C'est une liste.
|
||||
Parcourir toutes les video_tracks ?
|
||||
Trouver comment fait Felix David
|
||||
"""
|
||||
print('timeline: ', timeline)
|
||||
|
||||
scn.frame_end = frame_end-1
|
||||
return timeline
|
||||
|
||||
"""
|
||||
def create_strip_effect(name, strip_type, channel, frame_start, frame_end):
|
||||
strip = scn.sequence_editor.sequences.new_effect(
|
||||
name=name,
|
||||
type=strip_type,
|
||||
channel=channel,
|
||||
frame_start=frame_start,
|
||||
frame_end=frame_end,
|
||||
def import_movie(filepath):
|
||||
scn = bpy.context.scene
|
||||
|
||||
res_x = scn.render.resolution_x
|
||||
res_y = scn.render.resolution_y
|
||||
|
||||
strip = scn.sequence_editor.sequences.new_movie(
|
||||
name=filepath.stem,
|
||||
filepath=str(filepath),
|
||||
channel=get_channel('Movie'),
|
||||
frame_start=scn.frame_start
|
||||
)
|
||||
|
||||
elem = strip.strip_elem_from_frame(scn.frame_current)
|
||||
src_width, src_height = elem.orig_width, elem.orig_height
|
||||
|
||||
if src_width != res_x:
|
||||
strip.transform.scale_x = (res_x / src_width)
|
||||
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):
|
||||
scn = bpy.context.scene
|
||||
|
||||
strip = scn.sequence_editor.sequences.new_sound(
|
||||
name=filepath.stem,
|
||||
filepath=str(filepath),
|
||||
channel=get_channel('Audio'),
|
||||
frame_start=scn.frame_start
|
||||
)
|
||||
|
||||
if bpy.data.is_saved:
|
||||
strip.sound.filepath = bpy.path.relpath(str(filepath))
|
||||
|
||||
strip.show_waveform = True
|
||||
return strip
|
||||
|
||||
|
||||
def clean_sequencer(edit=False, movie=False, sound=False):
|
||||
scn = bpy.context.scene
|
||||
sequences = []
|
||||
|
||||
if edit:
|
||||
sequences.extend(get_strips('Shots'))
|
||||
if movie:
|
||||
sequences.extend(get_strips('Movie'))
|
||||
if sound:
|
||||
sequences.extend(get_strips('Audio'))
|
||||
|
||||
for sequence in sequences:
|
||||
scn.sequence_editor.sequences.remove(sequence)
|
||||
Reference in New Issue
Block a user