youssef
commited on
Commit
·
9a80e6e
1
Parent(s):
630bec9
test
Browse files- src/app.py +10 -11
- src/video_processor/processor.py +12 -2
src/app.py
CHANGED
@@ -53,29 +53,28 @@ def on_process(video):
|
|
53 |
|
54 |
# Get duration and calculate total segments
|
55 |
duration = get_video_duration_seconds(video)
|
56 |
-
total_segments = int(duration
|
57 |
|
58 |
-
# Process
|
59 |
yield [
|
60 |
-
f"Processing video... (This
|
61 |
"",
|
62 |
gr.update(visible=True)
|
63 |
]
|
64 |
|
65 |
-
#
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
for i, segment in enumerate(all_segments):
|
70 |
progress = int((i + 1) / total_segments * 100)
|
71 |
|
72 |
# Format current segments
|
73 |
formatted_desc = "### Video Analysis by Segments:\n\n"
|
74 |
-
for
|
75 |
-
formatted_desc += f"**[{
|
76 |
|
77 |
yield [
|
78 |
-
f"
|
79 |
formatted_desc,
|
80 |
gr.update(visible=True)
|
81 |
]
|
|
|
53 |
|
54 |
# Get duration and calculate total segments
|
55 |
duration = get_video_duration_seconds(video)
|
56 |
+
total_segments = (int(duration) + 9) // 10 # Ceiling division for 10-second segments
|
57 |
|
58 |
+
# Process video segments
|
59 |
yield [
|
60 |
+
f"Processing video... (This will process {total_segments} segments)",
|
61 |
"",
|
62 |
gr.update(visible=True)
|
63 |
]
|
64 |
|
65 |
+
# Process segments and show progress
|
66 |
+
segments = []
|
67 |
+
for i, segment in enumerate(analyzer.process_video(video)):
|
68 |
+
segments.append(segment)
|
|
|
69 |
progress = int((i + 1) / total_segments * 100)
|
70 |
|
71 |
# Format current segments
|
72 |
formatted_desc = "### Video Analysis by Segments:\n\n"
|
73 |
+
for seg in segments:
|
74 |
+
formatted_desc += f"**[{seg['timestamp']}]** {seg['description']}\n\n"
|
75 |
|
76 |
yield [
|
77 |
+
f"Processing segments... {progress}% complete",
|
78 |
formatted_desc,
|
79 |
gr.update(visible=True)
|
80 |
]
|
src/video_processor/processor.py
CHANGED
@@ -109,11 +109,19 @@ Be specific about visual details but stay concise."""}
|
|
109 |
|
110 |
# Get video duration
|
111 |
duration = get_video_duration_seconds(video_path)
|
|
|
|
|
|
|
112 |
|
113 |
# Process video in segments
|
114 |
-
for
|
|
|
115 |
end_time = min(start_time + segment_length, duration)
|
116 |
|
|
|
|
|
|
|
|
|
117 |
# Create segment
|
118 |
segment_path = os.path.join(temp_dir, f"segment_{start_time}.mp4")
|
119 |
cmd = [
|
@@ -121,7 +129,7 @@ Be specific about visual details but stay concise."""}
|
|
121 |
"-y",
|
122 |
"-i", video_path,
|
123 |
"-ss", str(start_time),
|
124 |
-
"-t", str(
|
125 |
"-c:v", "libx264",
|
126 |
"-preset", "ultrafast",
|
127 |
"-pix_fmt", "yuv420p",
|
@@ -140,6 +148,8 @@ Be specific about visual details but stay concise."""}
|
|
140 |
|
141 |
# Clean up segment file
|
142 |
os.remove(segment_path)
|
|
|
|
|
143 |
|
144 |
# Clean up temp directory
|
145 |
os.rmdir(temp_dir)
|
|
|
109 |
|
110 |
# Get video duration
|
111 |
duration = get_video_duration_seconds(video_path)
|
112 |
+
segments_processed = 0
|
113 |
+
total_segments = int(duration / segment_length)
|
114 |
+
logger.info(f"Processing {total_segments} segments for video of length {duration:.2f} seconds")
|
115 |
|
116 |
# Process video in segments
|
117 |
+
for segment_idx in range(total_segments):
|
118 |
+
start_time = segment_idx * segment_length
|
119 |
end_time = min(start_time + segment_length, duration)
|
120 |
|
121 |
+
# Skip if we've reached the end
|
122 |
+
if start_time >= duration:
|
123 |
+
break
|
124 |
+
|
125 |
# Create segment
|
126 |
segment_path = os.path.join(temp_dir, f"segment_{start_time}.mp4")
|
127 |
cmd = [
|
|
|
129 |
"-y",
|
130 |
"-i", video_path,
|
131 |
"-ss", str(start_time),
|
132 |
+
"-t", str(end_time - start_time), # Duration of this segment
|
133 |
"-c:v", "libx264",
|
134 |
"-preset", "ultrafast",
|
135 |
"-pix_fmt", "yuv420p",
|
|
|
148 |
|
149 |
# Clean up segment file
|
150 |
os.remove(segment_path)
|
151 |
+
|
152 |
+
logger.info(f"Processed segment {segment_idx + 1}/{total_segments} ({start_time}-{end_time}s)")
|
153 |
|
154 |
# Clean up temp directory
|
155 |
os.rmdir(temp_dir)
|