Process a single video or directory of images.
(self, input_path, output_dir,
num_frames_per_batch=8,
denoise_steps=1,
max_frames=None,
decode_chunk_size=8,
num_interp_frames=1,
num_overlap_frames=1,
use_clip_img_emb=False,
noise_type='zeros',
mode='matte',
write_video=True,
direct_output_dir=None,
progress_callback=None)
| 104 | logging.info("Models loaded.") |
| 105 | |
| 106 | def process_sequence(self, input_path, output_dir, |
| 107 | num_frames_per_batch=8, |
| 108 | denoise_steps=1, |
| 109 | max_frames=None, |
| 110 | decode_chunk_size=8, |
| 111 | num_interp_frames=1, |
| 112 | num_overlap_frames=1, |
| 113 | use_clip_img_emb=False, |
| 114 | noise_type='zeros', |
| 115 | mode='matte', |
| 116 | write_video=True, |
| 117 | direct_output_dir=None, |
| 118 | progress_callback=None): |
| 119 | """ |
| 120 | Process a single video or directory of images. |
| 121 | """ |
| 122 | input_path = Path(input_path) |
| 123 | file_name = input_path.stem |
| 124 | is_video = input_path.suffix.lower() in ['.mp4', '.mkv', '.gif', '.mov', '.avi'] |
| 125 | |
| 126 | # --- Determine Resolution & Upscaling --- |
| 127 | if is_video: |
| 128 | cap = cv2.VideoCapture(str(input_path)) |
| 129 | orig_w = int(cap.get(cv2.CAP_PROP_FRAME_WIDTH)) |
| 130 | orig_h = int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT)) |
| 131 | cap.release() |
| 132 | else: |
| 133 | image_files = sorted([f for f in input_path.iterdir() if f.is_file() and f.suffix.lower() in ['.jpg', '.png', '.jpeg', '.exr']]) |
| 134 | if not image_files: |
| 135 | logging.warning(f"No images found in {input_path}") |
| 136 | return |
| 137 | # Use cv2 for EXR support if needed |
| 138 | first_img_path = str(image_files[0]) |
| 139 | if first_img_path.lower().endswith('.exr'): |
| 140 | # import cv2 # Global import used |
| 141 | if "OPENCV_IO_ENABLE_OPENEXR" not in os.environ: |
| 142 | os.environ["OPENCV_IO_ENABLE_OPENEXR"] = "1" |
| 143 | img = cv2.imread(first_img_path, cv2.IMREAD_UNCHANGED) |
| 144 | else: |
| 145 | img = cv2.imread(first_img_path) |
| 146 | |
| 147 | if img is not None: |
| 148 | orig_h, orig_w = img.shape[:2] |
| 149 | else: |
| 150 | orig_h, orig_w = 1080, 1920 # Fallback |
| 151 | |
| 152 | target_h = orig_h |
| 153 | if target_h < 1024: |
| 154 | scale_ratio = 1024 / target_h |
| 155 | target_h = 1024 |
| 156 | |
| 157 | # Calculate max resolution / long edge |
| 158 | if orig_h < orig_w: # Landscape |
| 159 | ratio = orig_w / orig_h |
| 160 | new_long = int(1024 * ratio) |
| 161 | else: |
| 162 | ratio = orig_h / orig_w |
| 163 | new_long = int(1024 * ratio) |
no test coverage detected