Created
January 21, 2026 18:41
-
-
Save me-suzy/3e40967e560cff3322a88be31e485ce9 to your computer and use it in GitHub Desktop.
FINAL - Convert poze si video cu melodie 2.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import os | |
| from moviepy.editor import ImageClip, VideoFileClip, concatenate_videoclips, AudioFileClip, ColorClip, CompositeVideoClip | |
| import moviepy.audio.fx.all as afx | |
| # Configurații | |
| media_directory = r"g:\De pus pe FTP 2\masina de spalat" | |
| audio_path = r"g:\Muzica\Hamidshax - Yesterday (Original Mix).mp3" | |
| output_path = r"g:\De pus pe FTP 2\masina de spalat\Video_Masina_Spalat.mp4" | |
| TARGET_RES = (1920, 1080) | |
| SORT_METHOD = 'DATE' | |
| def fix_clip_size(clip, target_res): | |
| """ Redimensionează clipul fără deformare și adaugă margini negre. """ | |
| w, h = clip.size | |
| scale = min(target_res[0]/w, target_res[1]/h) | |
| new_w, new_h = int(w * scale), int(h * scale) | |
| clip_resized = clip.resize(newsize=(new_w, new_h)) | |
| bg = ColorClip(size=target_res, color=(0, 0, 0)).set_duration(clip.duration) | |
| return CompositeVideoClip([bg, clip_resized.set_position("center")]) | |
| def create_video(): | |
| print("[*] Pornire procesare cu Audio Loop și corecție Aspect Ratio...") | |
| valid_extensions = ('.png', '.jpg', '.jpeg', '.mp4', '.mov', '.avi') | |
| files = [f for f in os.listdir(media_directory) if f.lower().endswith(valid_extensions)] | |
| if SORT_METHOD == 'NAME': | |
| files.sort() | |
| else: | |
| files.sort(key=lambda x: os.path.getmtime(os.path.join(media_directory, x))) | |
| clips = [] | |
| for index, file in enumerate(files): | |
| path = os.path.join(media_directory, file) | |
| print(f" [{index + 1}/{len(files)}] Procesez: {file}") | |
| try: | |
| if file.lower().endswith(('.mp4', '.mov', '.avi')): | |
| clip = VideoFileClip(path) | |
| # Corecție manuală rotație | |
| if hasattr(clip, 'rotation'): | |
| if clip.rotation == 90: | |
| clip = clip.resize(clip.size[::-1]).rotate(-90) | |
| elif clip.rotation == 270: | |
| clip = clip.resize(clip.size[::-1]).rotate(-270) | |
| elif clip.rotation == 180: | |
| clip = clip.rotate(180) | |
| else: | |
| clip = ImageClip(path).set_duration(3).set_fps(24) | |
| processed = fix_clip_size(clip, TARGET_RES).fadein(0.5).fadeout(0.5) | |
| clips.append(processed) | |
| except Exception as e: | |
| print(f" [!] Eroare la {file}: {e}") | |
| print("[*] Combinare clipuri...") | |
| final_video = concatenate_videoclips(clips, method="compose") | |
| print("[*] Procesare Audio (Loop activat)...") | |
| audio = AudioFileClip(audio_path) | |
| # Aplicăm LOOP pe melodie până la durata finală a video-ului | |
| looped_audio = afx.audio_loop(audio, duration=final_video.duration) | |
| final_video = final_video.set_audio(looped_audio) | |
| print(f"[*] Randare finală (Durată totală: {final_video.duration:.2f} secunde)...") | |
| final_video.write_videofile( | |
| output_path, | |
| codec="libx264", | |
| audio_codec="aac", | |
| fps=24, | |
| threads=2, | |
| ffmpeg_params=["-crf", "24"] | |
| ) | |
| # Eliberare memorie | |
| for c in clips: | |
| c.close() | |
| print(f"\n[+] Succes! Video-ul este gata: {output_path}") | |
| if __name__ == "__main__": | |
| create_video() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment