Compare commits
3 Commits
ad84469037
...
503f2817d2
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
503f2817d2 | ||
|
|
85b5717595 | ||
|
|
9c626a1e4a |
@@ -6,9 +6,35 @@ from moviepy.video.compositing.CompositeVideoClip import CompositeVideoClip
|
||||
from moviepy import TextClip
|
||||
|
||||
font = "./Montserrat.ttf"
|
||||
font_size = 70
|
||||
video_codec = "libx264"
|
||||
|
||||
def auto_wrap_text(text, font, font_size, max_width):
|
||||
if not text:
|
||||
return ""
|
||||
|
||||
words = text.split()
|
||||
lines = []
|
||||
|
||||
line = ""
|
||||
for word in words:
|
||||
test_line = f"{line} {word}".strip()
|
||||
test_clip = TextClip(test_line, font=font, font_size=font_size, color='white', method='label')
|
||||
|
||||
if test_clip.w > max_width and line != "":
|
||||
lines.append(line)
|
||||
line = word
|
||||
else:
|
||||
line = test_line
|
||||
|
||||
test_clip.close()
|
||||
|
||||
lines.append(line)
|
||||
|
||||
return "\n".join(lines)
|
||||
|
||||
def cut_video_new_clip(input_path: str, start: float, end: float, output_path: str):
|
||||
video_codec = "libx264"
|
||||
|
||||
|
||||
with VideoFileClip(input_path) as clip:
|
||||
segment = clip.subclipped(start, end)
|
||||
@@ -37,25 +63,26 @@ def process_segment(input_path: str, top_text: str = "", bottom_text: str = "",
|
||||
|
||||
with VideoFileClip(input_path) as clip:
|
||||
dur = clip.duration
|
||||
bg = ColorClip(size=(final_width, final_height), color=(255, 255, 255), duration=dur)
|
||||
bg = ColorClip(size=(final_width, final_height), color=(0, 0, 0), duration=dur)
|
||||
video_resized = clip.resized(width=final_width)
|
||||
y = top_h + (middle_h - video_resized.h) // 2
|
||||
video_resized = video_resized.with_position((0, y))
|
||||
video_codec = "libx264"
|
||||
wrapped_top_text = auto_wrap_text(top_text, font, font_size, final_width - 40)
|
||||
wrapped_bottom_text = auto_wrap_text(bottom_text, font, font_size, final_width - 40)
|
||||
|
||||
txt_top = TextClip(
|
||||
text=top_text,
|
||||
text=wrapped_top_text,
|
||||
font_size=70,
|
||||
color="black",
|
||||
color="white",
|
||||
font=font,
|
||||
method="label",
|
||||
size=(final_width, top_h)
|
||||
).with_duration(dur).with_position((0, 0))
|
||||
|
||||
txt_bot = TextClip(
|
||||
text=bottom_text,
|
||||
text=wrapped_bottom_text,
|
||||
font_size=70,
|
||||
color="black",
|
||||
color="white",
|
||||
font=font,
|
||||
method="label",
|
||||
size=(final_width, bottom_h),
|
||||
|
||||
Reference in New Issue
Block a user