Wednesday, January 22, 2025

from moviepy.editor import * from moviepy.video.fx.all import vfx_fadein, vfx_fadeout def text_to_video(text, duration=5, output_file="output.mp4", font="Arial", fontsize=30, color="white", bg_color="black"): """ Creates a video with the given text. Args: text: The text to display in the video. duration: The duration of the video in seconds. output_file: The name of the output video file. font: The font to use for the text. fontsize: The font size of the text. color: The color of the text. bg_color: The background color of the video. Returns: None """ # Create a TextClip txt_clip = TextClip(text, fontsize=fontsize, color=color, font=font) # Center the text horizontally and vertically txt_clip = txt_clip.set_position('center') # Create a ColorClip for the background bg_clip = ColorClip(size=(txt_clip.w + 50, txt_clip.h + 50), color=bg_color) # Combine the text and background clips video_clip = CompositeVideoClip([bg_clip, txt_clip]) # Add fade-in and fade-out effects video_clip = vfx_fadein(video_clip, duration=1) video_clip = vfx_fadeout(video_clip, duration=1) # Set the video duration video_clip = video_clip.set_duration(duration) # Write the video to file video_clip.write_videofile(output_file, fps=24) if __name__ == "__main__": text_to_video("Hello, World!", duration=3)

No comments:

Post a Comment

ताज़ा समाचार - आपकी हिंदी न्यूज़ वेबसाइट ताज़ा समाचार मुख्य समाचार व्याप...