Create video_processor.py
Browse files- video_processor.py +40 -0
video_processor.py
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import cv2
|
| 2 |
+
from moviepy.editor import VideoFileClip
|
| 3 |
+
from gemini_vision import process_frame_with_gemini, summarize_with_gemini, extract_code_with_gemini
|
| 4 |
+
|
| 5 |
+
def frame_generator(video_path):
|
| 6 |
+
video = cv2.VideoCapture(video_path)
|
| 7 |
+
while True:
|
| 8 |
+
ret, frame = video.read()
|
| 9 |
+
if not ret:
|
| 10 |
+
break
|
| 11 |
+
yield frame
|
| 12 |
+
video.release()
|
| 13 |
+
|
| 14 |
+
def process_video(video_path, summary_words):
|
| 15 |
+
# Process frames with Gemini Vision Pro
|
| 16 |
+
extracted_text = ""
|
| 17 |
+
for frame in frame_generator(video_path):
|
| 18 |
+
extracted_text += process_frame_with_gemini(frame) + " "
|
| 19 |
+
|
| 20 |
+
# Extract audio and transcribe
|
| 21 |
+
video = VideoFileClip(video_path)
|
| 22 |
+
audio = video.audio
|
| 23 |
+
audio_path = "temp_audio.wav"
|
| 24 |
+
audio.write_audiofile(audio_path)
|
| 25 |
+
|
| 26 |
+
# Use Gemini Vision Pro for transcription (assuming it can handle audio)
|
| 27 |
+
transcription = process_frame_with_gemini(audio_path, mode="audio")
|
| 28 |
+
|
| 29 |
+
# Summarize content using Gemini
|
| 30 |
+
summary = summarize_with_gemini(transcription, max_words=summary_words)
|
| 31 |
+
|
| 32 |
+
# Extract code using Gemini
|
| 33 |
+
extracted_code = extract_code_with_gemini(transcription)
|
| 34 |
+
|
| 35 |
+
return {
|
| 36 |
+
'summary': summary,
|
| 37 |
+
'extracted_text': extracted_text,
|
| 38 |
+
'transcription': transcription,
|
| 39 |
+
'extracted_code': extracted_code
|
| 40 |
+
}
|