import os video_dir = "./videos" audio_dir = "./audios" # Ensure output directory exists os.makedirs(audio_dir, exist_ok=True) for filename in os.listdir(video_dir): if filename.endswith(".mp4"): video_path = os.path.join(video_dir, filename) audio_filename = filename.replace(".mp4", ".wav") audio_path = os.path.join(audio_dir, audio_filename) command = f"ffmpeg -i \"{video_path}\" \"{audio_path}\" -y" result = os.system(command) if result == 0: print(f"✅ Audio extracted from {filename} and saved as {audio_path}") else: print(f"❌ Failed to extract audio from {filename}") print(f"Command used: {command}")