ruff suggestions

This commit is contained in:
Jakub Jezek 2024-10-02 11:51:21 +02:00
parent 029cbe4fa0
commit 05291b2fe9
No known key found for this signature in database
GPG key ID: 06DBD609ADF27FD9
2 changed files with 46 additions and 43 deletions

View file

@ -57,13 +57,12 @@ class ExtractOTIOReview(publish.Extractor):
# Not all hosts can import these modules. # Not all hosts can import these modules.
import opentimelineio as otio import opentimelineio as otio
from ayon_core.pipeline.editorial import ( from ayon_core.pipeline.editorial import (
otio_range_to_frame_range,
make_sequence_collection, make_sequence_collection,
remap_range_on_file_sequence, remap_range_on_file_sequence,
is_clip_from_media_sequence is_clip_from_media_sequence
) )
# TODO refactore from using instance variable # TODO refactor from using instance variable
self.temp_file_head = self._get_folder_name_based_prefix(instance) self.temp_file_head = self._get_folder_name_based_prefix(instance)
# TODO: convert resulting image sequence to mp4 # TODO: convert resulting image sequence to mp4
@ -75,8 +74,8 @@ class ExtractOTIOReview(publish.Extractor):
otio_review_clips = instance.data["otioReviewClips"] otio_review_clips = instance.data["otioReviewClips"]
# add plugin wide attributes # add plugin wide attributes
self.representation_files = list() self.representation_files = []
self.used_frames = list() self.used_frames = []
self.workfile_start = int(instance.data.get( self.workfile_start = int(instance.data.get(
"workfileFrameStart", 1001)) - handle_start "workfileFrameStart", 1001)) - handle_start
self.padding = len(str(self.workfile_start)) self.padding = len(str(self.workfile_start))
@ -101,9 +100,7 @@ class ExtractOTIOReview(publish.Extractor):
for index, r_otio_cl in enumerate(otio_review_clips): for index, r_otio_cl in enumerate(otio_review_clips):
# QUESTION: what if transition on clip? # QUESTION: what if transition on clip?
# check if resolution is the same # check if resolution is the same as source
width = self.to_width
height = self.to_height
otio_media = r_otio_cl.media_reference otio_media = r_otio_cl.media_reference
media_metadata = otio_media.metadata media_metadata = otio_media.metadata
@ -151,7 +148,7 @@ class ExtractOTIOReview(publish.Extractor):
# Gap: no media, generate range based on source range # Gap: no media, generate range based on source range
else: else:
available_range = processing_range = None available_range = processing_range = None
self.actual_fps = src_range.duration.rate self.actual_fps = src_range.duration.rate
start = src_range.start_time start = src_range.start_time
duration = src_range.duration duration = src_range.duration
@ -216,7 +213,7 @@ class ExtractOTIOReview(publish.Extractor):
collection.indexes.update( collection.indexes.update(
[i for i in range(first, (last + 1))]) [i for i in range(first, (last + 1))])
# render segment # render segment
self._render_seqment( self._render_segment(
sequence=[dirname, collection, input_fps]) sequence=[dirname, collection, input_fps])
# generate used frames # generate used frames
self._generate_used_frames( self._generate_used_frames(
@ -230,7 +227,7 @@ class ExtractOTIOReview(publish.Extractor):
dir_path, collection = collection_data dir_path, collection = collection_data
# render segment # render segment
self._render_seqment( self._render_segment(
sequence=[dir_path, collection, input_fps]) sequence=[dir_path, collection, input_fps])
# generate used frames # generate used frames
self._generate_used_frames( self._generate_used_frames(
@ -252,7 +249,7 @@ class ExtractOTIOReview(publish.Extractor):
duration=processing_range.duration, duration=processing_range.duration,
) )
# render video file to sequence # render video file to sequence
self._render_seqment( self._render_segment(
video=[path, extract_range]) video=[path, extract_range])
# generate used frames # generate used frames
self._generate_used_frames( self._generate_used_frames(
@ -261,7 +258,7 @@ class ExtractOTIOReview(publish.Extractor):
# QUESTION: what if nested track composition is in place? # QUESTION: what if nested track composition is in place?
else: else:
# at last process a Gap # at last process a Gap
self._render_seqment(gap=duration) self._render_segment(gap=duration)
# generate used frames # generate used frames
self._generate_used_frames(duration) self._generate_used_frames(duration)
@ -334,7 +331,6 @@ class ExtractOTIOReview(publish.Extractor):
) )
avl_start = avl_range.start_time avl_start = avl_range.start_time
avl_duration = avl_range.duration
# An additional gap is required before the available # An additional gap is required before the available
# range to conform source start point and head handles. # range to conform source start point and head handles.
@ -344,7 +340,7 @@ class ExtractOTIOReview(publish.Extractor):
duration -= gap_duration duration -= gap_duration
# create gap data to disk # create gap data to disk
self._render_seqment(gap=gap_duration.round().to_frames()) self._render_segment(gap=gap_duration.round().to_frames())
# generate used frames # generate used frames
self._generate_used_frames(gap_duration.round().to_frames()) self._generate_used_frames(gap_duration.round().to_frames())
@ -358,7 +354,7 @@ class ExtractOTIOReview(publish.Extractor):
duration -= gap_duration duration -= gap_duration
# create gap data to disk # create gap data to disk
self._render_seqment( self._render_segment(
gap=gap_duration.round().to_frames(), gap=gap_duration.round().to_frames(),
end_offset=duration.to_frames() end_offset=duration.to_frames()
) )
@ -377,10 +373,10 @@ class ExtractOTIOReview(publish.Extractor):
) )
) )
def _render_seqment(self, sequence=None, def _render_segment(self, sequence=None,
video=None, gap=None, end_offset=None): video=None, gap=None, end_offset=None):
""" """
Render seqment into image sequence frames. Render segment into image sequence frames.
Using ffmpeg to convert compatible video and image source Using ffmpeg to convert compatible video and image source
to defined image sequence format. to defined image sequence format.
@ -416,18 +412,24 @@ class ExtractOTIOReview(publish.Extractor):
input_path = os.path.join(input_dir, input_file) input_path = os.path.join(input_dir, input_file)
input_extension = os.path.splitext(input_path)[-1] input_extension = os.path.splitext(input_path)[-1]
# form command for rendering sequence files """
# (need to explicit set the input frame range Form Command for Rendering Sequence Files
# if case input sequence has framerate metadata
# to preserve frame range and avoid silent dropped To explicitly set the input frame range and preserve the frame
# frames caused by input mismatch with FFmpeg default range, avoid silent dropped frames caused by input mismatch
# rate 25.0 fps) more info refer to FFmpeg image2 demuxer with FFmpeg's default rate of 25.0 fps. For more info,
# refer to the FFmpeg image2 demuxer.
# Implicit
# [Input 100 frames (24fps from metadata)] -> [Demuxer video 25fps] -> [Output 98 frames, dropped 2] Implicit:
# - Input: 100 frames (24fps from metadata)
# Explicit with "-framerate" - Demuxer: video 25fps
# [Input 100 frames (24fps from metadata)] -> [Demuxer video 24fps] -> [Output 100 frames] - Output: 98 frames, dropped 2
Explicit with "-framerate":
- Input: 100 frames (24fps from metadata)
- Demuxer: video 24fps
- Output: 100 frames, no dropped frames
"""
command.extend([ command.extend([
"-start_number", str(in_frame_start), "-start_number", str(in_frame_start),
@ -566,4 +568,3 @@ class ExtractOTIOReview(publish.Extractor):
self.log.debug(f"file_prefix::{file_prefix}") self.log.debug(f"file_prefix::{file_prefix}")
return file_prefix return file_prefix

View file

@ -1,11 +1,10 @@
import mock import mock
import os import os
import pytest import pytest # noqa
from typing import NamedTuple from typing import NamedTuple
import opentimelineio as otio import opentimelineio as otio
import ayon_core.lib
from ayon_core.plugins.publish import extract_otio_review from ayon_core.plugins.publish import extract_otio_review
@ -19,7 +18,7 @@ class MockInstance():
""" Mock pyblish instance for testing purpose. """ Mock pyblish instance for testing purpose.
""" """
def __init__(self, data: dict): def __init__(self, data: dict):
self.data = data self.data = data
self.context = self self.context = self
@ -34,7 +33,7 @@ class CaptureFFmpegCalls():
self.calls.append(" ".join(ffmpeg_args_list)) self.calls.append(" ".join(ffmpeg_args_list))
return True return True
def get_fmpeg_executable(self, _): def get_ffmpeg_executable(self, _):
return ["/path/to/ffmpeg"] return ["/path/to/ffmpeg"]
@ -48,20 +47,23 @@ def run_process(file_name: str):
# Prepare dummy instance and capture call object # Prepare dummy instance and capture call object
capture_call = CaptureFFmpegCalls() capture_call = CaptureFFmpegCalls()
processor = extract_otio_review.ExtractOTIOReview() processor = extract_otio_review.ExtractOTIOReview()
instance = MockInstance({ Anatomy = NamedTuple("Anatomy", [("project_name")])
"otioReviewClips": [clip], instance = MockInstance(
"handleStart": 10, {
"handleEnd": 10, "otioReviewClips": [clip],
"workfileFrameStart": 1001, "handleStart": 10,
"folderPath": "/dummy/path", "handleEnd": 10,
"anatomy": NamedTuple("Anatomy", [('project_name', "test_project")]) "workfileFrameStart": 1001,
}) "folderPath": "/dummy/path",
"anatomy": Anatomy("test_project"),
}
)
# Mock calls to extern and run plugins. # Mock calls to extern and run plugins.
with mock.patch.object( with mock.patch.object(
extract_otio_review, extract_otio_review,
"get_ffmpeg_tool_args", "get_ffmpeg_tool_args",
side_effect=capture_call.get_fmpeg_executable, side_effect=capture_call.get_ffmpeg_executable,
): ):
with mock.patch.object( with mock.patch.object(
extract_otio_review, extract_otio_review,