Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- """
- Subtitles in moviepy are still annoying, but doable
- I struggled with this, so maybe somebody else did too. You can't use pango with stroke (stroke_width) so if you want to change one word, you're screwed. I run this on linux cuz it's easier than figuring out how to get ImageMagick working on Windows, lol
- I don't do the timings manually (I'd die). I use AWS Transcribe, and as long as it's less than 60 minutes a month, it's free for the first year. It's cheap if you go over anyway
- The video is generated with Deforum notebook (Stable Diffusion)
- If you navigated here from somewhere other than my video, here's a link to see the end result
- https://youtu.be/YN_XWoMTGdY
- """
- import math
- from moviepy.editor import *
- from moviepy.video.tools import *
- screensize = (1024, 768)
- audioclip = AudioFileClip("untitled.mp3")
- v4 = VideoFileClip('20230205043321.mp4')
- clip_list = [v4]
- def do_text(text, font_size, main_color, highlight_color, highlight_index, start_time, end_time, y_pos= 573, wobble = 1.0, backcolor = "white"):
- def lambda_with_var(i, yi, w):
- return lambda t: (i, yi + w * t * 10 * math.sin(t * 3 + i))
- items = []
- widths = [0]
- te = text.split(' ')
- co = [main_color] * len(te)
- if highlight_index >= 0 and highlight_index < len(co):
- co[highlight_index] = highlight_color
- for i in range(len(te)):
- txt_clip = TextClip(te[i], method='label', fontsize=font_size, color=co[i], stroke_color=backcolor,
- stroke_width=1.5, font='URW-Chancery-L-Medium-Italic').set_duration(end_time - start_time)
- txt_clip = txt_clip.set_start(start_time)
- widths.append(widths[-1] + txt_clip.size[0] + 10)
- items.append(txt_clip)
- assert widths[-1] < screensize[0], f"Too damn wide! {widths[-1]}"
- indent = (screensize[0] - widths[-1]) // 2
- for i in range(len(items)):
- items[i] = items[i].set_pos(lambda_with_var(widths[i] + indent, y_pos, wobble))
- clip_list.extend(items)
- do_text("I want to own a sword", 120, "purple", "red", 0, 0.39, 0.62)
- do_text("I want to own a sword", 120, "purple", "red", 1, 0.62, 1.06)
- do_text("I want to own a sword", 120, "purple", "red", 2, 1.06, 1.19)
- do_text("I want to own a sword", 120, "purple", "red", 3, 1.2, 1.44)
- do_text("I want to own a sword", 120, "purple", "red", 4, 1.44, 1.5)
- do_text("I want to own a sword", 120, "purple", "red", 5, 1.5, 2.17)
- do_text("But not because Andrew Tate", 90, "purple", "red", 0, 2.17, 2.36, 500)
- do_text("But not because Andrew Tate", 90, "purple", "red", 1, 2.36, 2.63, 500)
- do_text("But not because Andrew Tate", 90, "purple", "red", 2, 2.63, 2.97, 500)
- do_text("But not because Andrew Tate", 90, "purple", "red", 3, 2.97, 3.38, 500)
- do_text("But not because Andrew Tate", 90, "purple", "red", 4, 3.38, 3.7, 500)
- do_text("But not because Andrew Tate", 90, "purple", "red", -1, 3.7, 4.94, 500)
- do_text("told me that I should!", 90, "purple", "red", -1, 2.17, 3.7, 620)
- do_text("told me that I should!", 90, "purple", "red", 0, 3.7, 3.99, 620)
- do_text("told me that I should!", 90, "purple", "red", 1, 3.99, 4.14, 620)
- do_text("told me that I should!", 90, "purple", "red", 2, 4.14, 4.29, 620)
- do_text("told me that I should!", 90, "purple", "red", 3, 4.29, 4.4, 620)
- do_text("told me that I should!", 90, "purple", "red", 4, 4.4, 4.94, 620)
- do_text("Also, I think I figured", 110, "pink", "red", -1, 5.79, 8.2, 500, backcolor = "black", wobble=0)
- do_text("out the subtitle thing.", 110, "yellow", "red", -1, 5.79, 8.2, 620, backcolor = "black", wobble=0)
- final_clip = CompositeVideoClip(clip_list).set_audio(audioclip)
- final_clip.write_videofile("my_concatenation.mp4", fps=24, codec='libx264', threads=7)
Advertisement
Comments
-
- Oh ... the youtube video is not technically the final version, because I added the wobble=0 to the last two text lines .. that was SUPPOSED to be on, but I just forgot, okay?
Add Comment
Please, Sign In to add comment
Advertisement