jebin2 commited on
Commit
73e0acf
ยท
1 Parent(s): ecdfdf4

cta improv

Browse files
Fonts/Ubuntu-Bold.ttf ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:6dbcce3fdd846f3aebc7e1890b5ccca234806cbd84763785f7ced043a99e8268
3
+ size 270164
src/onscreebcta.py CHANGED
@@ -48,7 +48,8 @@ def create_cta_on_strip(
48
  appear_at_percent: float = 0.75,
49
  emoji_folder: str = "emoji",
50
  above_caption: bool = True,
51
- padding: int = 20
 
52
  ) -> CompositeVideoClip:
53
  """
54
  Overlays a full-width white strip and a dynamically sized, elevated CTA label with color emojis.
@@ -56,7 +57,7 @@ def create_cta_on_strip(
56
  """
57
  # --- 1. Customize Appearance ---
58
  # Use text font only (no emoji font needed)
59
- text_font_path = 'Fonts/Lora-Bold.ttf' # Or your preferred font
60
 
61
  # Fallback to system fonts if custom fonts not found
62
  if not os.path.exists(text_font_path):
@@ -250,17 +251,23 @@ def create_cta_on_strip(
250
 
251
  cta_element = ImageClip(np.array(canvas))
252
 
253
- # --- 4. Create the Full-Width Semi-Transparent White Strip ---
254
- strip_height = cta_element.h + (strip_v_padding * 2)
255
- white_strip_array = np.full((strip_height, video_clip.w, 4),
256
- [255, 255, 255, 230], dtype=np.uint8)
257
- white_strip = ImageClip(white_strip_array)
 
 
 
 
258
 
259
- # Composite the CTA on the strip
260
- full_banner = CompositeVideoClip([
261
- white_strip,
262
- cta_element.set_position(('center', 'center'))
263
- ])
 
 
264
 
265
  # --- 5. Calculate Final Position using SafeZone ---
266
  try:
@@ -293,7 +300,7 @@ def create_cta_on_strip(
293
 
294
  return CompositeVideoClip([video_clip, final_banner])
295
 
296
- def add_cta(input_video_path: str, cta_text: str, above_caption: bool = True, padding: int = 20):
297
  if above_caption:
298
  output_video_path = f"/tmp/{uuid.uuid4().hex[:8]}final_video_above_caption.mp4"
299
  else:
@@ -305,7 +312,7 @@ def add_cta(input_video_path: str, cta_text: str, above_caption: bool = True, pa
305
  logger.info(f"Generating CTA overlay with text: '{cta_text}'")
306
  logger.info(f"CTA will appear at 75% mark ({base_video.duration * 0.75:.2f}s)")
307
 
308
- final_video = create_cta_on_strip(cta_text, base_video, appear_at_percent=0.75, above_caption = above_caption, padding=padding)
309
 
310
  logger.info(f"Writing final video to '{output_video_path}'...")
311
  final_video.write_videofile(
@@ -324,9 +331,9 @@ def add_cta(input_video_path: str, cta_text: str, above_caption: bool = True, pa
324
  # --- MAIN EXECUTION BLOCK ---
325
  if __name__ == '__main__':
326
  input_video_path = os.path.join("testData", "final_video.mp4")
327
- cta_text = "๐Ÿ›๏ธ SALE ENDING SOON - ๐Ÿ”— LINK IN BIO "
328
  add_cta(
329
  input_video_path,
330
  cta_text,
331
- above_caption = False
332
  )
 
48
  appear_at_percent: float = 0.75,
49
  emoji_folder: str = "emoji",
50
  above_caption: bool = True,
51
+ padding: int = 20,
52
+ show_strip: bool = False
53
  ) -> CompositeVideoClip:
54
  """
55
  Overlays a full-width white strip and a dynamically sized, elevated CTA label with color emojis.
 
57
  """
58
  # --- 1. Customize Appearance ---
59
  # Use text font only (no emoji font needed)
60
+ text_font_path = 'Fonts/Ubuntu-Bold.ttf' # Or your preferred font
61
 
62
  # Fallback to system fonts if custom fonts not found
63
  if not os.path.exists(text_font_path):
 
251
 
252
  cta_element = ImageClip(np.array(canvas))
253
 
254
+ # --- 4. Optionally Create the Full-Width Semi-Transparent Strip ---
255
+ if show_strip:
256
+ strip_height = cta_element.h + (strip_v_padding * 2)
257
+ white_strip_array = np.full(
258
+ (strip_height, video_clip.w, 4),
259
+ [255, 255, 255, 230],
260
+ dtype=np.uint8
261
+ )
262
+ white_strip = ImageClip(white_strip_array)
263
 
264
+ full_banner = CompositeVideoClip([
265
+ white_strip,
266
+ cta_element.set_position(('center', 'center'))
267
+ ])
268
+ else:
269
+ # No strip โ†’ use only the CTA card
270
+ full_banner = cta_element
271
 
272
  # --- 5. Calculate Final Position using SafeZone ---
273
  try:
 
300
 
301
  return CompositeVideoClip([video_clip, final_banner])
302
 
303
+ def add_cta(input_video_path: str, cta_text: str, above_caption: bool = True, padding: int = 20, show_strip: bool = False):
304
  if above_caption:
305
  output_video_path = f"/tmp/{uuid.uuid4().hex[:8]}final_video_above_caption.mp4"
306
  else:
 
312
  logger.info(f"Generating CTA overlay with text: '{cta_text}'")
313
  logger.info(f"CTA will appear at 75% mark ({base_video.duration * 0.75:.2f}s)")
314
 
315
+ final_video = create_cta_on_strip(cta_text, base_video, appear_at_percent=0.75, above_caption = above_caption, padding=padding, show_strip=show_strip)
316
 
317
  logger.info(f"Writing final video to '{output_video_path}'...")
318
  final_video.write_videofile(
 
331
  # --- MAIN EXECUTION BLOCK ---
332
  if __name__ == '__main__':
333
  input_video_path = os.path.join("testData", "final_video.mp4")
334
+ cta_text = "LINK IN BIO ๐Ÿ›๏ธ"
335
  add_cta(
336
  input_video_path,
337
  cta_text,
338
+ show_strip=True
339
  )
testData/onscreencta.png CHANGED

Git LFS Details

  • SHA256: 49f4397982633388c1366f0ce5c7ca281c37239ddf721efa69901fabfb42ab6d
  • Pointer size: 130 Bytes
  • Size of remote file: 41.7 kB

Git LFS Details

  • SHA256: 3d326071efa8e94e42e9229590fd2bf51f6af88b97490ecb5e9d29d8cd0db31c
  • Pointer size: 132 Bytes
  • Size of remote file: 1.24 MB