Antonio
commited on
Commit
·
e1cc37c
1
Parent(s):
c643d9f
Added functionality to make sure that the video has enough frames
Browse files
app.py
CHANGED
@@ -47,9 +47,20 @@ def delete_files_in_directory(directory):
|
|
47 |
except Exception as e:
|
48 |
print(f"Failed to delete {file_path}. Reason: {e}")
|
49 |
|
|
|
|
|
|
|
|
|
|
|
50 |
def process_video(file_path):
|
51 |
container = av.open(file_path)
|
52 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
53 |
video = read_video_pyav(container=container, indices=indices)
|
54 |
container.close()
|
55 |
return video
|
@@ -134,7 +145,7 @@ def weighted_average_method(video_prediction, audio_prediction):
|
|
134 |
def confidence_level_method(video_prediction, audio_prediction, threshold=0.7):
|
135 |
highest_video_label = max(video_prediction, key=video_prediction.get)
|
136 |
highest_video_confidence = video_prediction[highest_video_label]
|
137 |
-
if highest_video_confidence >= threshold:
|
138 |
return highest_video_label
|
139 |
combined_probabilities = {}
|
140 |
for label in set(video_prediction) | set(audio_prediction):
|
|
|
47 |
except Exception as e:
|
48 |
print(f"Failed to delete {file_path}. Reason: {e}")
|
49 |
|
50 |
+
def get_total_frames(container):
|
51 |
+
stream = container.streams.video[0]
|
52 |
+
total_frames = stream.frames
|
53 |
+
return total_frames
|
54 |
+
|
55 |
def process_video(file_path):
|
56 |
container = av.open(file_path)
|
57 |
+
total_frames = get_total_frames(container)
|
58 |
+
|
59 |
+
if total_frames < 64:
|
60 |
+
container.close()
|
61 |
+
raise ValueError("Video must have at least 64 frames.")
|
62 |
+
|
63 |
+
indices = sample_frame_indices(clip_len=32, frame_sample_rate=2, seg_len=total_frames)
|
64 |
video = read_video_pyav(container=container, indices=indices)
|
65 |
container.close()
|
66 |
return video
|
|
|
145 |
def confidence_level_method(video_prediction, audio_prediction, threshold=0.7):
|
146 |
highest_video_label = max(video_prediction, key=video_prediction.get)
|
147 |
highest_video_confidence = video_prediction[highest_video_label]
|
148 |
+
if (highest_video_confidence >= threshold):
|
149 |
return highest_video_label
|
150 |
combined_probabilities = {}
|
151 |
for label in set(video_prediction) | set(audio_prediction):
|