def _compose_external_reference(self, offset, mob_id, clip): width, height = self.streamInfo.resolution.split("x") return ExternalReference( clip["sourceFile"], TimeRange( RationalTime(0, self.streamInfo.frame_rate), # RationalTime((end_frame - start_frame), self.frame_rate) RationalTime(self.streamInfo.nb_frames / offset, self.streamInfo.frame_rate)), self._compose_external_reference_metadata(width, height, mob_id))
def _compose_video_track(self, width, height, i, video_clips): return Track( f"v{i}", # this used to be cast to int, but i was always int video_clips, TimeRange( RationalTime(0, self.streamInfo.frame_rate), RationalTime(self.streamInfo.nb_frames, self.streamInfo.frame_rate)), TrackKind.Video, metadata=self._compose_video_metadata(width, height))
def _compose_marker(self, edit): return Marker( "jumpcut", TimeRange( RationalTime( math.floor((edit["start"]) * self.streamInfo.frame_rate), self.streamInfo.frame_rate), RationalTime( # this used to add offset to edit["end"], but offset is always 0, so... math.floor((edit["end"]) * self.streamInfo.frame_rate), self.streamInfo.frame_rate)), "PURPLE")
def _compose_audio_track(self, video_track, i, audio_clips): return Track( f"aa{i}", # used to explicitly cast i to int, but is redundant audio_clips, # None, TimeRange( RationalTime(0, self.streamInfo.frame_rate), RationalTime(self.streamInfo.nb_frames, self.streamInfo.frame_rate)), TrackKind.Audio, metadata=self._compose_audio_metadata(video_track.name))
def _add_gaps(self, clip, video_clips, audio_clips): timeline_start = clip["timelineStart"] offset = 1 if len(self.layers) > 1 and timeline_start > 0: offset = int(timeline_start / 1000 * self.streamInfo.frame_rate) gap = ("timelineStart", TimeRange(RationalTime(0, self.streamInfo.frame_rate), RationalTime(offset, self.streamInfo.frame_rate))) video_clips.append(Gap(*gap)) audio_clips.append(Gap(*gap)) self.streamInfo.nb_frames = self.streamInfo.nb_frames * offset return offset
def _clip_export(self, sourceFile, external_reference, mob_id, start_frame, end_frame, time_scalar): width, height = self.streamInfo.resolution.split("x") clip = Clip(sourceFile, external_reference, TimeRange( RationalTime(start_frame, self.streamInfo.frame_rate), RationalTime((end_frame - start_frame) * time_scalar, self.streamInfo.frame_rate)), metadata=self._compose_clip_metadata( width, height, mob_id)) if time_scalar != 1: clip.effects.append(LinearTimeWarp(time_scalar=time_scalar)) return clip
def _compose_timeline_edl(self, timeline_name, i): return Timeline( # "AX", f"{timeline_name}{i // 2}.edl", # f string, also int division # [tracks[i - 1], tracks[i]], [self.tracks[i], self.tracks[i + 1]], RationalTime(0, self.streamInfo.frame_rate))
def _compose_timeline_generic(self, timeline_name): return Timeline(f"{timeline_name}.{self.streamInfo.vcodec}", self.tracks, RationalTime(0, self.streamInfo.frame_rate))
def range_from_s_fps(start, dur, fps): return TimeRange( start_time=RationalTime.from_seconds(start).rescaled_to(fps), duration=RationalTime.from_seconds(dur).rescaled_to(fps))