sreepathi-ravikumar commited on
Commit
cf1eaf1
·
verified ·
1 Parent(s): ffa9043

Update video2.py

Browse files
Files changed (1) hide show
  1. video2.py +1 -48
video2.py CHANGED
@@ -23,9 +23,6 @@ os.makedirs(AUDIO_DIR, exist_ok=True)
23
  CLIPS_DIR = "/tmp/video"
24
  os.makedirs(CLIPS_DIR, exist_ok=True)
25
 
26
-
27
- # Generate audio
28
- # --- CONFIGURATION ---
29
  def video_func(id,lines):
30
  tts = gTTS(text=lines[id], lang='ta', slow=False)
31
  audio_name = "audio"+str(id)+".mp3"
@@ -34,48 +31,4 @@ def video_func(id,lines):
34
  if os.path.exists(audio_path):
35
  audio = MP3(audio_path)
36
  duration = audio.info.length
37
- IMAGE_PATH = os.path.join(IMAGE_DIR,f"slide{id}.png") # Ensure this path is correct
38
- VIDEO_DURATION = duration # seconds
39
- HIGHLIGHT_COLOR = (255, 255, 0) # Yellow highlight
40
- HIGHLIGHT_OPACITY = 0.5 # Semi-transparent
41
-
42
- # --- OCR STEP ---
43
- img = Image.open(IMAGE_PATH)
44
- data = pytesseract.image_to_data(img, output_type=pytesseract.Output.DICT)
45
-
46
- # Extract words and their positions
47
- words = []
48
- for i in range(len(data['text'])):
49
- word = data['text'][i].strip()
50
- if word and int(data['conf'][i]) > 60:
51
- x, y, w, h = data['left'][i], data['top'][i], data['width'][i], data['height'][i]
52
- words.append({'text': word, 'box': (x, y, w, h)})
53
-
54
- # --- BASE IMAGE CLIP ---
55
- image_clip = ImageClip(IMAGE_PATH).set_duration(VIDEO_DURATION)
56
-
57
- # --- HIGHLIGHT WORDS ONE BY ONE ---
58
- n_words = len(words)
59
- highlight_duration = VIDEO_DURATION / n_words
60
-
61
- highlight_clips = []
62
-
63
- for i, word in enumerate(words):
64
- x, y, w, h = word['box']
65
- start = i * highlight_duration
66
- end = start + highlight_duration
67
-
68
- # Create highlight rectangle
69
- rect = ColorClip(size=(w, h), color=HIGHLIGHT_COLOR)
70
- rect = rect.set_opacity(HIGHLIGHT_OPACITY).set_position((x, y)).set_start(start).set_end(end)
71
-
72
- highlight_clips.append(rect)
73
-
74
- # --- FINAL VIDEO --
75
-
76
- final_clip = CompositeVideoClip([image_clip] + highlight_clips)
77
- audio = AudioFileClip(audio_path)
78
- final_clip = final_clip.set_audio(audio)
79
- clip_name = "clip"+str(id)+".mp4"
80
- video_path=os.path.join(CLIPS_DIR,clip_name)
81
- final_clip.write_videofile(video_path, fps=24)
 
23
  CLIPS_DIR = "/tmp/video"
24
  os.makedirs(CLIPS_DIR, exist_ok=True)
25
 
 
 
 
26
  def video_func(id,lines):
27
  tts = gTTS(text=lines[id], lang='ta', slow=False)
28
  audio_name = "audio"+str(id)+".mp3"
 
31
  if os.path.exists(audio_path):
32
  audio = MP3(audio_path)
33
  duration = audio.info.length
34
+ print(audio_path,duration)