MCPcopy Index your code
hub / github.com/TIGER-AI-Lab/TheoremExplainAgent / evaluate_video_file

Function evaluate_video_file

evaluate.py:94–168  ·  view source on GitHub ↗

Evaluate a video file using the provided model. Args: model: The model to use for evaluation. video_path (str): Path to the video file. transcript_path (str): Path to the transcript file. description_path (str): Path to the description file. target_f

(model, video_path, transcript_path, description_path, target_fps=None, output_folder=None)

Source from the content-addressed store, hash-verified

92
93
94def evaluate_video_file(model, video_path, transcript_path, description_path, target_fps=None, output_folder=None):
95 """
96 Evaluate a video file using the provided model.
97
98 Args:
99 model: The model to use for evaluation.
100 video_path (str): Path to the video file.
101 transcript_path (str): Path to the transcript file.
102 description_path (str): Path to the description file.
103 target_fps (int, optional): Target frames per second for video processing.
104 output_folder (str, optional): Directory to store output files.
105
106 Returns:
107 Dict or None: Evaluation results if successful, None if file format unsupported.
108 """
109 if not video_path.endswith(('.mp4', '.mkv')):
110 print(f"Skipping {video_path}: Unsupported file format for video evaluation.")
111 return None
112
113 moviepy_temp_dir = os.path.join(output_folder, "moviepy_temp")
114
115 # Chunking
116 num_chunks = 10
117 with VideoFileClip(video_path) as clip:
118 duration = clip.duration
119 chunk_duration = duration / num_chunks
120 results = []
121
122 # Create a temporary directory in the output_folder
123 temp_dir_parent = output_folder or os.getcwd()
124 with tempfile.TemporaryDirectory(dir=temp_dir_parent) as temp_dir:
125 for i in range(10):
126 start = i * chunk_duration
127 end = min(start + chunk_duration, duration)
128 chunk = clip.subclipped(start, end)
129 chunk_path = os.path.join(temp_dir, f"chunk_{i+1}.mp4")
130 # Explicitly set the temp_audiofile path with matching codec
131 temp_audiofile = os.path.join(moviepy_temp_dir, f"temp_audio_chunk_{i+1}.m4a")
132 chunk.write_videofile(
133 chunk_path,
134 codec="libx264",
135 audio_codec="aac",
136 temp_audiofile=temp_audiofile,
137 audio_bitrate="192k",
138 preset="ultrafast", # Speed up encoding
139 logger=None
140 )
141 # Create processed videos folder inside output_folder
142 processed_videos_dir = os.path.join(output_folder, "processed_videos")
143 save_path = os.path.join(processed_videos_dir, f"processed_chunk_{i+1}.mp4")
144 result = evaluate_video_chunk_new(
145 model,
146 chunk_path,
147 transcript_path,
148 description_path,
149 target_fps=target_fps,
150 save_processed_video=save_path
151 )

Callers 1

process_theoremFunction · 0.85

Calls 2

evaluate_video_chunk_newFunction · 0.90
calculate_geometric_meanFunction · 0.90

Tested by

no test coverage detected