Created
January 21, 2026 18:43
-
-
Save me-suzy/a7f904040217ca90cb401f0e81728ffb to your computer and use it in GitHub Desktop.
FINAL 2 cu sortare - Convert poze si video cu melodie
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) | |
| def show_sort_menu(): | |
| print("\n" + "="*50) | |
| print("📋 ALEGE MODUL DE SORTARE:") | |
| print("="*50) | |
| print(" 1. Crescător A-Z (după nume)") | |
| print(" 2. După dată (cronologic - vechi → noi)") | |
| print("="*50) | |
| while True: | |
| choice = input("\n👉 Introdu opțiunea (1 sau 2): ").strip() | |
| if choice == '1': | |
| return 'NAME' | |
| elif choice == '2': | |
| return 'DATE' | |
| print("❌ Opțiune invalidă! Alege 1 sau 2.") | |
| 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("\n🎬 VIDEO CREATOR\n") | |
| if not os.path.exists(media_directory): | |
| print(f"❌ Director inexistent: {media_directory}") | |
| return | |
| if not os.path.exists(audio_path): | |
| print(f"❌ Audio inexistent: {audio_path}") | |
| return | |
| print(f"📁 Media: {media_directory}") | |
| print(f"🎵 Audio: {os.path.basename(audio_path)}") | |
| SORT_METHOD = show_sort_menu() | |
| print("\n[*] 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() | |
| print("📋 Sortare: A-Z (după nume)") | |
| else: | |
| files.sort(key=lambda x: os.path.getmtime(os.path.join(media_directory, x))) | |
| print("📋 Sortare: După dată (cele mai vechi primele)") | |
| print(f"\n📄 Total fișiere: {len(files)}") | |
| print(f"📄 Primele 3: {files[:3]}") | |
| print(f"📄 Ultimele 3: {files[-3:]}\n") | |
| 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') and 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("\n[*] Combinare clipuri...") | |
| final_video = concatenate_videoclips(clips, method="compose") | |
| print("[*] Procesare Audio (Loop activat)...") | |
| audio = AudioFileClip(audio_path) | |
| 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"] | |
| ) | |
| 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