fix temp file
This commit is contained in:
@@ -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}")
|
||||
|
||||
Reference in New Issue
Block a user