sreepathi-ravikumar commited on
Commit
62c0db4
·
verified ·
1 Parent(s): 73c1f30

Update video2.py

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