Update video_processing.py
Browse files- video_processing.py +26 -23
video_processing.py
CHANGED
@@ -166,29 +166,32 @@ def process_video(video_path, anomaly_threshold, desired_fps, progress=None):
|
|
166 |
audio_path = os.path.join(temp_dir, "audio.wav")
|
167 |
video.export(audio_path, format="wav")
|
168 |
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
|
|
|
|
|
|
|
192 |
|
193 |
|
194 |
progress(0.95, "Generating plots")
|
|
|
166 |
audio_path = os.path.join(temp_dir, "audio.wav")
|
167 |
video.export(audio_path, format="wav")
|
168 |
|
169 |
+
try:
|
170 |
+
# Process audio
|
171 |
+
most_frequent_voice, voice_features, voice_clusters = process_audio(audio_path)
|
172 |
+
|
173 |
+
if len(voice_features) < 2:
|
174 |
+
print("Not enough voice segments for processing. Skipping voice analysis.")
|
175 |
+
raise ValueError("Insufficient voice data")
|
176 |
+
|
177 |
+
# Perform anomaly detection on voice
|
178 |
+
X_voice = np.array(most_frequent_voice)
|
179 |
+
mse_voice = anomaly_detection(X_voice, X_voice)
|
180 |
+
|
181 |
+
# Generate plots for voice
|
182 |
+
mse_plot_voice, anomaly_segments_voice = plot_mse(df, mse_voice, "Voice",
|
183 |
+
color='green',
|
184 |
+
anomaly_threshold=anomaly_threshold)
|
185 |
+
mse_histogram_voice = plot_mse_histogram(mse_voice, "MSE Distribution: Voice",
|
186 |
+
anomaly_threshold, color='green')
|
187 |
+
mse_heatmap_voice = plot_mse_heatmap(mse_voice, "Voice MSE Heatmap", df)
|
188 |
+
except Exception as e:
|
189 |
+
print(f"Error in voice processing: {str(e)}")
|
190 |
+
mse_voice = None
|
191 |
+
mse_plot_voice = None
|
192 |
+
mse_histogram_voice = None
|
193 |
+
mse_heatmap_voice = None
|
194 |
+
anomaly_segments_voice = None
|
195 |
|
196 |
|
197 |
progress(0.95, "Generating plots")
|