fix temp file

This commit is contained in:
2025-07-26 09:01:38 -07:00
parent c4af7baf3d
commit 99c4da83af
2 changed files with 73 additions and 49 deletions

View File

@@ -89,9 +89,10 @@ class SAM2VideoMatting:
if video_frames is None or len(video_frames) == 0:
raise ValueError("Either video_path or video_frames must be provided")
# Create temporary video file
temp_dir = tempfile.mkdtemp()
temp_video_path = Path(temp_dir) / "temp_video.mp4"
# Create temporary video file in current directory
import uuid
temp_video_name = f"temp_sam2_{uuid.uuid4().hex[:8]}.mp4"
temp_video_path = Path.cwd() / temp_video_name
# Write frames to temporary video
height, width = video_frames[0].shape[:2]
@@ -266,8 +267,8 @@ class SAM2VideoMatting:
if self.temp_video_path is not None:
try:
if self.temp_video_path.exists():
# Remove the temporary directory
shutil.rmtree(self.temp_video_path.parent)
# Remove the temporary video file
self.temp_video_path.unlink()
self.temp_video_path = None
except Exception as e:
warnings.warn(f"Failed to cleanup temp video: {e}")