Spaces:
Sleeping
Sleeping
Update video_processing.py
Browse files- video_processing.py +9 -1
video_processing.py
CHANGED
|
@@ -75,6 +75,11 @@ def find_scenes(video_path):
|
|
| 75 |
def convert_timestamp_to_seconds(timestamp):
|
| 76 |
return float(timestamp)
|
| 77 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 78 |
def extract_frames(video_path, start_time, end_time):
|
| 79 |
frames = []
|
| 80 |
video_clip = VideoFileClip(video_path).subclip(start_time, end_time)
|
|
@@ -100,6 +105,8 @@ def analyze_scenes(video_path, scenes, description):
|
|
| 100 |
positive_feature, negative_features = text_features[0], text_features[1:]
|
| 101 |
|
| 102 |
for scene_num, (start_time, end_time) in enumerate(scenes):
|
|
|
|
|
|
|
| 103 |
frames = extract_frames(video_path, start_time, end_time)
|
| 104 |
if not frames:
|
| 105 |
print(f"Scene {scene_num + 1}: Start={start_time}, End={end_time} - No frames extracted")
|
|
@@ -116,7 +123,8 @@ def analyze_scenes(video_path, scenes, description):
|
|
| 116 |
scene_prob += positive_similarity - negative_similarities
|
| 117 |
|
| 118 |
scene_prob /= len(frames)
|
| 119 |
-
scene_duration =
|
|
|
|
| 120 |
print(f"Scene {scene_num + 1}: Start={start_time}, End={end_time}, Probability={scene_prob}, Duration={scene_duration}")
|
| 121 |
|
| 122 |
scene_scores.append((scene_prob, start_time, end_time, scene_duration))
|
|
|
|
| 75 |
def convert_timestamp_to_seconds(timestamp):
|
| 76 |
return float(timestamp)
|
| 77 |
|
| 78 |
+
def timecode_to_seconds(timecode):
|
| 79 |
+
h, m, s = timecode.split(':')
|
| 80 |
+
return int(h) * 3600 + int(m) * 60 + float(s)
|
| 81 |
+
|
| 82 |
+
|
| 83 |
def extract_frames(video_path, start_time, end_time):
|
| 84 |
frames = []
|
| 85 |
video_clip = VideoFileClip(video_path).subclip(start_time, end_time)
|
|
|
|
| 105 |
positive_feature, negative_features = text_features[0], text_features[1:]
|
| 106 |
|
| 107 |
for scene_num, (start_time, end_time) in enumerate(scenes):
|
| 108 |
+
start_seconds = timecode_to_seconds(start_time)
|
| 109 |
+
end_seconds = timecode_to_seconds(end_time)
|
| 110 |
frames = extract_frames(video_path, start_time, end_time)
|
| 111 |
if not frames:
|
| 112 |
print(f"Scene {scene_num + 1}: Start={start_time}, End={end_time} - No frames extracted")
|
|
|
|
| 123 |
scene_prob += positive_similarity - negative_similarities
|
| 124 |
|
| 125 |
scene_prob /= len(frames)
|
| 126 |
+
scene_duration = end_seconds - start_seconds
|
| 127 |
+
|
| 128 |
print(f"Scene {scene_num + 1}: Start={start_time}, End={end_time}, Probability={scene_prob}, Duration={scene_duration}")
|
| 129 |
|
| 130 |
scene_scores.append((scene_prob, start_time, end_time, scene_duration))
|