-
Notifications
You must be signed in to change notification settings - Fork 0
/
strip_audio.py
31 lines (22 loc) · 1020 Bytes
/
strip_audio.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
import os
from moviepy.editor import VideoFileClip
def strip_audio_from_many(input_dir, output_dir):
# Get a list of all files in the directory
files = os.listdir(input_dir)
# Filter out non-video files
video_files = [f for f in files if f.endswith(('.mp4', '.flv', '.mkv', '.webm', '.avi'))]
for video_file in video_files:
# Create the full input file path
input_file_path = os.path.join(input_dir, video_file)
# Create VideoFileClip object
video = VideoFileClip(input_file_path)
# Remove audio
video = video.without_audio()
# Create the full output file path, even if it doesnt exist
output_file_path = os.path.join(output_dir, video_file)
# Write the result to a file
video.write_videofile(output_file_path)
input_directory = "./data"
output_directory = "./output/stripped_audio"
if __name__ == "__main__":
strip_audio_from_many(input_directory, output_directory)