diff --git a/vr180_matting/vr180_processor.py b/vr180_matting/vr180_processor.py index 72d7cd7..3e39c95 100644 --- a/vr180_matting/vr180_processor.py +++ b/vr180_matting/vr180_processor.py @@ -170,13 +170,35 @@ class VR180Processor(VideoProcessor): for fourcc_str, ext in codecs_to_try: fourcc = cv2.VideoWriter_fourcc(*fourcc_str) temp_video_path_with_ext = temp_video_path.with_suffix(ext) + + print(f"Trying codec {fourcc_str} with path {temp_video_path_with_ext}") + print(f"Video params: size=({width}, {height}), fps=30.0") + writer = cv2.VideoWriter(str(temp_video_path_with_ext), fourcc, 30.0, (width, height)) if writer.isOpened(): - temp_video_path = temp_video_path_with_ext - print(f"Using codec {fourcc_str} for temp video") - break + # Test writing the first frame + test_frame = eye_frames[0].copy() + if test_frame.dtype != np.uint8: + test_frame = test_frame.astype(np.uint8) + if not test_frame.flags['C_CONTIGUOUS']: + test_frame = np.ascontiguousarray(test_frame) + + test_success = writer.write(test_frame) + print(f"Test write with {fourcc_str}: {'SUCCESS' if test_success else 'FAILED'}") + + if test_success: + temp_video_path = temp_video_path_with_ext + print(f"Using codec {fourcc_str} for temp video") + # Reset writer to start fresh + writer.release() + writer = cv2.VideoWriter(str(temp_video_path_with_ext), fourcc, 30.0, (width, height)) + break + else: + writer.release() + writer = None else: + print(f"Failed to open writer with {fourcc_str}") writer.release() writer = None