from moviepy.editor import VideoFileClip
import os
def convert_to_mp4(input_path, output_path):
try:
# Load the video clip from the input_path
clip = VideoFileClip(input_path)
# Set the output path with .mp4 extension
output_path_with_mp4 = os.path.splitext(output_path)[0] + ".mp4"
# Convert and save the video clip to mp4 format
clip.write_videofile(output_path_with_mp4, codec='libx264')
print(f"Successfully converted {input_path} to {output_path_with_mp4}")
except Exception as e:
print(f"Error converting {input_path}: {str(e)}")
def batch_convert_to_mp4(input_folder, output_folder):
# Ensure output folder exists
os.makedirs(output_folder, exist_ok=True)
# Loop through all files in the input folder
for file_name in os.listdir(input_folder):
input_path = os.path.join(input_folder, file_name)
# Check if the file is a wav video
if file_name.lower().endswith(".wav"):
# Set the output path with .mp4 extension
output_path = os.path.join(output_folder, os.path.splitext(file_name)[0] + ".mp4")
convert_to_mp4(input_path, output_path)
if __name__ == "__main__":
input_folder = "D:\\dataset\\Mirror\\Female_mirror" # Replace with the path to your folder containing wav videos
output_folder = "D:\\dataset\\Mirror\\Female_pic" # Replace with the path where you want to save mp4 videos
batch_convert_to_mp4(input_folder, output_folder)