From 26b18be9882690e1ee44746928e18cffa1131450 Mon Sep 17 00:00:00 2001 From: Atakan <68283731+KsBenAtaGG@users.noreply.github.com> Date: Tue, 26 Nov 2024 10:47:29 +0300 Subject: [PATCH] Add files via upload --- main.py | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 main.py diff --git a/main.py b/main.py new file mode 100644 index 0000000..1f7bd83 --- /dev/null +++ b/main.py @@ -0,0 +1,43 @@ +import os +from moviepy.editor import AudioFileClip, ImageClip + +def find_files(directory): + mp3_files = [] + global image_file + + for filename in os.listdir(directory): + if filename.endswith(".mp3"): + mp3_files.append(os.path.join(directory, filename)) + elif filename.endswith(".jpg") or filename.endswith(".png"): + image_file = os.path.join(directory, filename) + + return mp3_files + +def create_video(mp3_file, image_file): + # Create audio clip + audio_clip = AudioFileClip(mp3_file) + + # Create image clip and set duration to match audio + image_clip = ImageClip(image_file) + image_clip = image_clip.set_duration(audio_clip.duration) + + # Combine image and audio into a video + video = image_clip.set_audio(audio_clip) + + # Extract the name of the mp3 file without extension for the video name + output_file = os.path.splitext(os.path.basename(mp3_file))[0] + ".mp4" + + # Export video + video.write_videofile(output_file, codec="libx264", fps=24) + +if __name__ == "__main__": + directory = "." + + mp3_files = find_files(directory) + + if mp3_files and image_file: + for mp3_file in mp3_files: + create_video(mp3_file, image_file) + print(f"Video başarıyla {mp3_file} dosyasından oluşturuldu!") + else: + print("MP3 dosyası veya resim dosyası bulunamadı!")