Update video2.py
Browse files22 unmodified lines2324252627282930312 unmodified lines34353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808122 unmodified linesCLIPS_DIR = "/tmp/video"os.makedirs(CLIPS_DIR, exist_ok=True)# Generate audio# --- CONFIGURATION ---def video_func(id,lines):tts = gTTS(text=lines[id], lang='ta', slow=False)audio_name = "audio"+str(id)+".mp3"2 unmodified linesif os.path.exists(audio_path):audio = MP3(audio_path)duration = audio.info.lengthIMAGE_PATH = os.path.join(IMAGE_DIR,f"slide{id}.png") # Ensure this path is correctVIDEO_DURATION = duration # secondsHIGHLIGHT_COLOR = (255, 255, 0) # Yellow highlightHIGHLIGHT_OPACITY = 0.5 # Semi-transparent# --- OCR STEP ---img = Image.open(IMAGE_PATH)data = pytesseract.image_to_data(img, output_type=pytesseract.Output.DICT)# Extract words and their positionswords = []for i in range(len(data['text'])):word = data['text'][i].strip()if word and int(data['conf'][i]) > 60:x, y, w, h = data['left'][i], data['top'][i], data['width'][i], data['height'][i]words.append({'text': word, 'box': (x, y, w, h)})# --- BASE IMAGE CLIP ---image_clip = ImageClip(IMAGE_PATH).set_duration(VIDEO_DURATION)# --- HIGHLIGHT WORDS ONE BY ONE ---n_words = len(words)highlight_duration = VIDEO_DURATION / n_wordshighlight_clips = []for i, word in enumerate(words):x, y, w, h = word['box']start = i * highlight_durationend = start + highlight_duration# Create highlight rectanglerect = ColorClip(size=(w, h), color=HIGHLIGHT_COLOR)rect = rect.set_opacity(HIGHLIGHT_OPACITY).set_position((x, y)).set_start(start).set_end(end)highlight_clips.append(rect)# --- FINAL VIDEO --final_clip = CompositeVideoClip([image_clip] + highlight_clips)audio = AudioFileClip(audio_path)final_clip = final_clip.set_audio(audio)clip_name = "clip"+str(id)+".mp4"video_path=os.path.join(CLIPS_DIR,clip_name)final_clip.write_videofile(video_path, fps=24)22 unmodified lines2324252627282 unmodified lines3132333422 unmodified linesCLIPS_DIR = "/tmp/video"os.makedirs(CLIPS_DIR, exist_ok=True)def video_func(id,lines):tts = gTTS(text=lines[id], lang='ta', slow=False)audio_name = "audio"+str(id)+".mp3"2 unmodified linesif os.path.exists(audio_path):audio = MP3(audio_path)duration = audio.info.lengthprint(audio_path,duration)
video2.py+1-48