File size: 739 Bytes
a034ea5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
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}")