-
Notifications
You must be signed in to change notification settings - Fork 0
/
video2wav.py
35 lines (26 loc) · 1.08 KB
/
video2wav.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import sys
from moviepy.editor import VideoFileClip
def extract_audio_from_video(video_file_path, output_audio_path):
"""
Extracts audio from a video file and saves it as a .wav file.
:param video_file_path: Path to the video file
:param output_audio_path: Path where the .wav file will be saved
"""
try:
# Load the video file
video = VideoFileClip(video_file_path)
# Extract the audio
audio = video.audio
# Write the audio to a file in wav
audio.write_audiofile(output_audio_path, codec='pcm_s16le')
print(f"Audio extracted and saved to {output_audio_path}")
except Exception as e:
print(f"An error occurred: {e}")
# Check if the script is being run directly and ensure enough arguments are provided
if __name__ == "__main__":
if len(sys.argv) != 3:
print("Usage: python script_name.py <source_video_path> <output_audio_path>")
sys.exit(1)
source_video_path = sys.argv[1]
output_audio_path = sys.argv[2]
extract_audio_from_video(source_video_path, output_audio_path)