[Bugfix][Bench] Clean up synthetic video files and writers (#59529)
Signed-off-by: Prudhvivuda <prudhvi12042001@gmail.com> Co-authored-by: OpenAI Codex <noreply@openai.com>
This commit is contained in:
co-authored by
OpenAI Codex
parent
9bd993564f
commit
ea106db806
@@ -25,7 +25,7 @@ from dataclasses import dataclass, replace
|
||||
from functools import cache
|
||||
from io import BytesIO
|
||||
from pathlib import Path
|
||||
from tempfile import NamedTemporaryFile
|
||||
from tempfile import TemporaryDirectory
|
||||
from typing import Any, cast
|
||||
|
||||
import numpy as np
|
||||
@@ -975,32 +975,26 @@ class RandomMultiModalDataset(RandomDataset):
|
||||
dtype=np.uint8,
|
||||
)
|
||||
|
||||
# Create a temporary video file in memory
|
||||
fourcc = cv2.VideoWriter_fourcc(*"mp4v")
|
||||
fps = 30 # frames per second
|
||||
|
||||
with NamedTemporaryFile(suffix=".mp4", delete=False) as temp_file:
|
||||
temp_path = temp_file.name
|
||||
with TemporaryDirectory() as temp_dir:
|
||||
temp_path = Path(temp_dir) / "video.mp4"
|
||||
|
||||
# Create video writer
|
||||
video_writer = cv2.VideoWriter(
|
||||
temp_path, fourcc=fourcc, fps=fps, frameSize=(width, height)
|
||||
str(temp_path), fourcc=fourcc, fps=fps, frameSize=(width, height)
|
||||
)
|
||||
|
||||
if not video_writer.isOpened():
|
||||
raise RuntimeError("Failed to create video writer")
|
||||
try:
|
||||
if not video_writer.isOpened():
|
||||
raise RuntimeError("Failed to create video writer")
|
||||
|
||||
for frame in random_pixels:
|
||||
video_writer.write(frame)
|
||||
for frame in random_pixels:
|
||||
video_writer.write(frame)
|
||||
finally:
|
||||
video_writer.release()
|
||||
|
||||
video_writer.release()
|
||||
temp_file.close()
|
||||
|
||||
# Read the video file content
|
||||
with open(temp_path, "rb") as f:
|
||||
video_content = f.read()
|
||||
|
||||
return {"bytes": video_content}
|
||||
return {"bytes": temp_path.read_bytes()}
|
||||
|
||||
def map_config_to_modality(self, config: tuple[int, int, int]) -> str:
|
||||
"""Map the configuration to the modality."""
|
||||
|
||||
Reference in New Issue
Block a user