Update app.py
Browse files
app.py
CHANGED
@@ -13,6 +13,7 @@ import os
|
|
13 |
from moviepy.editor import ImageSequenceClip
|
14 |
from gradio_client import Client, file
|
15 |
import subprocess
|
|
|
16 |
|
17 |
api_key = os.getenv("OPEN_AI_KEY")
|
18 |
user_name = os.getenv("USER_NAME")
|
@@ -38,6 +39,24 @@ client = openai.OpenAI(api_key=api_key)
|
|
38 |
stop_capture = False
|
39 |
alerts_mode = True
|
40 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
41 |
def clip_video_segment(input_video_path, start_time, duration):
|
42 |
os.makedirs('videos', exist_ok=True)
|
43 |
output_video_path = f"videos/{uuid.uuid4()}.mp4"
|
@@ -171,7 +190,7 @@ def process_clip_from_file(prompt, frames, chatbot, fps, video_path, id):
|
|
171 |
result = None
|
172 |
if api_response and api_response.get("condition_met", False):
|
173 |
# video_clip_path = encode_to_video_fast(frames, fps)
|
174 |
-
video_clip_path =
|
175 |
chatbot.append(((video_clip_path,), None))
|
176 |
chatbot.append((f"Event ID: {id+1}\nDetails: {api_response.get('details', '')}", None))
|
177 |
|
|
|
13 |
from moviepy.editor import ImageSequenceClip
|
14 |
from gradio_client import Client, file
|
15 |
import subprocess
|
16 |
+
import ffmpeg
|
17 |
|
18 |
api_key = os.getenv("OPEN_AI_KEY")
|
19 |
user_name = os.getenv("USER_NAME")
|
|
|
39 |
stop_capture = False
|
40 |
alerts_mode = True
|
41 |
|
42 |
+
def clip_video_segment_2(input_video_path, start_time, duration):
|
43 |
+
os.makedirs('videos', exist_ok=True)
|
44 |
+
output_video_path = f"videos/{uuid.uuid4()}.mp4"
|
45 |
+
|
46 |
+
# Use ffmpeg-python to clip the video
|
47 |
+
try:
|
48 |
+
(
|
49 |
+
ffmpeg
|
50 |
+
.input(input_video_path, ss=start_time) # Seek to start_time
|
51 |
+
.output(output_video_path, t=duration, c='copy') # Set the duration
|
52 |
+
.run(overwrite_output=True)
|
53 |
+
)
|
54 |
+
print('input_video_path', input_video_path, output_video_path)
|
55 |
+
return output_video_path
|
56 |
+
except ffmpeg.Error as e:
|
57 |
+
print(f"Error clipping video: {e}")
|
58 |
+
return None
|
59 |
+
|
60 |
def clip_video_segment(input_video_path, start_time, duration):
|
61 |
os.makedirs('videos', exist_ok=True)
|
62 |
output_video_path = f"videos/{uuid.uuid4()}.mp4"
|
|
|
190 |
result = None
|
191 |
if api_response and api_response.get("condition_met", False):
|
192 |
# video_clip_path = encode_to_video_fast(frames, fps)
|
193 |
+
video_clip_path = clip_video_segment_2(video_path, id*LENGTH, LENGTH)
|
194 |
chatbot.append(((video_clip_path,), None))
|
195 |
chatbot.append((f"Event ID: {id+1}\nDetails: {api_response.get('details', '')}", None))
|
196 |
|