Spaces:
Sleeping
Sleeping
Update video_processing.py
Browse files- video_processing.py +8 -6
video_processing.py
CHANGED
@@ -154,22 +154,24 @@ def process_video(video_url, description):
|
|
154 |
video_path = download_video(video_url)
|
155 |
scenes = find_scenes(video_path)
|
156 |
best_scene = analyze_scenes(video_path, scenes, description)
|
157 |
-
if best_scene:
|
158 |
-
frames = extract_frames(video_path, *best_scene)
|
159 |
-
if frames:
|
160 |
-
# Classify the first frame
|
161 |
-
frame_results = classify_frame(frames[0])
|
162 |
-
print("Classification of the first frame:", frame_results)
|
163 |
final_clip = extract_best_scene(video_path, best_scene)
|
|
|
164 |
if final_clip:
|
|
|
|
|
|
|
|
|
|
|
165 |
output_dir = "output"
|
166 |
os.makedirs(output_dir, exist_ok=True)
|
167 |
final_clip_path = os.path.join(output_dir, f"{uuid.uuid4()}_final_clip.mp4")
|
168 |
final_clip.write_videofile(final_clip_path, codec='libx264', audio_codec='aac')
|
169 |
cleanup_temp_files()
|
170 |
return final_clip_path
|
|
|
171 |
return None
|
172 |
|
|
|
173 |
def cleanup_temp_files():
|
174 |
temp_dir = 'temp_videos'
|
175 |
if os.path.exists(temp_dir):
|
|
|
154 |
video_path = download_video(video_url)
|
155 |
scenes = find_scenes(video_path)
|
156 |
best_scene = analyze_scenes(video_path, scenes, description)
|
|
|
|
|
|
|
|
|
|
|
|
|
157 |
final_clip = extract_best_scene(video_path, best_scene)
|
158 |
+
|
159 |
if final_clip:
|
160 |
+
# Assuming final_clip is a MoviePy VideoFileClip object
|
161 |
+
frame = np.array(final_clip.get_frame(0)) # Get the first frame at t=0 seconds
|
162 |
+
frame_classification = classify_frame(frame) # Classify the frame
|
163 |
+
print("Frame classification probabilities:", frame_classification)
|
164 |
+
|
165 |
output_dir = "output"
|
166 |
os.makedirs(output_dir, exist_ok=True)
|
167 |
final_clip_path = os.path.join(output_dir, f"{uuid.uuid4()}_final_clip.mp4")
|
168 |
final_clip.write_videofile(final_clip_path, codec='libx264', audio_codec='aac')
|
169 |
cleanup_temp_files()
|
170 |
return final_clip_path
|
171 |
+
|
172 |
return None
|
173 |
|
174 |
+
|
175 |
def cleanup_temp_files():
|
176 |
temp_dir = 'temp_videos'
|
177 |
if os.path.exists(temp_dir):
|