Python how do they add those subtitle overlays on shorts ?

ATuringtest

Elite Member
Joined
Mar 8, 2019
Messages
1,625
Reaction score
2,848
As it says in the title - I'm trying to automate adding the subtitles as an overlay on a shorts video but cant find out how to do it ?

Like the video bleow

 
Python can surely do this, just check the GitHub repos for this, I am pretty sure that there would be something on this
 
Yes of course its possible. Use google and then you get faster and better results then here :D
 
I actually already have a script that does this. Not gonna give up too much on how I did this, but you're gonna wanna get a .srt file specifically from ur audio and use moviepy to overlay on video.
 
As it says in the title - I'm trying to automate adding the subtitles as an overlay on a shorts video but cant find out how to do it ?

Like the video bleow

two modules moviepy and ffmeg can do it easily.


Here is a example script.

from moviepy.editor import VideoFileClip, TextClip, CompositeVideoClip from moviepy.video.tools.drawing import color_gradient def add_caption_to_video(video_path, caption_text, caption_duration=5, output_path="output_video.mp4"): # Load the video video_clip = VideoFileClip(video_path) # Create a text clip with the caption caption_clip = TextClip(caption_text, fontsize=30, color='white', bg_color='black', size=video_clip.size, method='caption', align='center') # Set the duration of the caption clip caption_clip = caption_clip.set_duration(caption_duration) # Composite the caption clip with the original video final_clip = CompositeVideoClip([video_clip, caption_clip.set_position(("center", "bottom"))]) # Write the final video to the specified output path final_clip.write_videofile(output_path, codec='libx264', audio_codec='aac') if __name__ == "__main__": video_path = "path/to/your/video.mp4" caption_text = "Your caption text here" caption_duration = 5 # Duration of the caption in seconds output_path = "output_video.mp4" add_caption_to_video(video_path, caption_text, caption_duration, output_path)


This chatgpt code by the way. I think if you add a loop with the captions like show a new line every 5 second duration. Then i guess it will work.

If you want proper code let me know I can PM you that. [For free obviously] :)
 
two modules moviepy and ffmeg can do it easily.


Here is a example script.

from moviepy.editor import VideoFileClip, TextClip, CompositeVideoClip from moviepy.video.tools.drawing import color_gradient def add_caption_to_video(video_path, caption_text, caption_duration=5, output_path="output_video.mp4"): # Load the video video_clip = VideoFileClip(video_path) # Create a text clip with the caption caption_clip = TextClip(caption_text, fontsize=30, color='white', bg_color='black', size=video_clip.size, method='caption', align='center') # Set the duration of the caption clip caption_clip = caption_clip.set_duration(caption_duration) # Composite the caption clip with the original video final_clip = CompositeVideoClip([video_clip, caption_clip.set_position(("center", "bottom"))]) # Write the final video to the specified output path final_clip.write_videofile(output_path, codec='libx264', audio_codec='aac') if __name__ == "__main__": video_path = "path/to/your/video.mp4" caption_text = "Your caption text here" caption_duration = 5 # Duration of the caption in seconds output_path = "output_video.mp4" add_caption_to_video(video_path, caption_text, caption_duration, output_path)


This chatgpt code by the way. I think if you add a loop with the captions like show a new line every 5 second duration. Then i guess it will work.

If you want proper code let me know I can PM you that. [For free obviously] :)
Chatgpt has been loosing knowledge. If that's unedited gpt only code, 99/100 chance it won't work.
 
Chatgpt has been loosing knowledge. If that's unedited gpt only code, 99/100 chance it won't work.
For a programmer it's helpful as a guide. If you think that you can just write a prompt and create a end to end working script it's highly unlikely unless it's already written but it saves a lot of time that us programmers that used to waste on google and stack overflow.
 
Chatgpt has been loosing knowledge. If that's unedited gpt only code, 99/100 chance it won't work.
try it and see what it does, then proceed to make edits until you get the result you want, python code is very readable, you should figure it out
 
For a programmer it's helpful as a guide. If you think that you can just write a prompt and create a end to end working script it's highly unlikely unless it's already written but it saves a lot of time that us programmers that used to waste on google and stack overflow.
It really depends tbh. Before, 2 months ago, I would've completely agreed but just 2 days ago I wasted 30mins on chatgpt to a solution that stack overflow solved in 5mins. Idk if it's just me but chatgpt seems sick, it can't even answer basic math questions.
 
try it and see what it does, then proceed to make edits until you get the result you want, python code is very readable, you should figure it out
Ofc, it's a classical process of debugging. But like I said I already have a script for this and OP was looking for ways to accomplish this. I provided a general outline.
 
Chatgpt is fine for basic/core scripts but things like selenium - its sooo out of date now.
Thanks for the suggestions :)
 
Chatgpt is fine for basic/core scripts but things like selenium - its sooo out of date now.
Thanks for the suggestions :)
What do you plan on using the subtitle script for. If you don't need it strictly for python, you can take it over to clipchamp and get free auto captions.
 
It really depends tbh. Before, 2 months ago, I would've completely agreed but just 2 days ago I wasted 30mins on chatgpt to a solution that stack overflow solved in 5mins. Idk if it's just me but chatgpt seems sick, it can't even answer basic math questions.
Yeah i mean it's a great addition to our tools. Sometimes it works and sometimes other sites work. At the end of the day we want to be a little more productive so i think in that way chatgpt helps everyone.
 
Back
Top