|
import cv2 |
|
from moviepy.editor import VideoFileClip |
|
from gemini_vision import process_frame_with_gemini, summarize_with_gemini, extract_code_with_gemini |
|
|
|
def frame_generator(video_path): |
|
video = cv2.VideoCapture(video_path) |
|
while True: |
|
ret, frame = video.read() |
|
if not ret: |
|
break |
|
yield frame |
|
video.release() |
|
|
|
def process_video(video_path, summary_words): |
|
|
|
extracted_text = "" |
|
for frame in frame_generator(video_path): |
|
extracted_text += process_frame_with_gemini(frame) + " " |
|
|
|
|
|
video = VideoFileClip(video_path) |
|
audio = video.audio |
|
audio_path = "temp_audio.wav" |
|
audio.write_audiofile(audio_path) |
|
|
|
|
|
transcription = process_frame_with_gemini(audio_path, mode="audio") |
|
|
|
|
|
summary = summarize_with_gemini(transcription, max_words=summary_words) |
|
|
|
|
|
extracted_code = extract_code_with_gemini(transcription) |
|
|
|
return { |
|
'summary': summary, |
|
'extracted_text': extracted_text, |
|
'transcription': transcription, |
|
'extracted_code': extracted_code |
|
} |