Skip to content

Instantly share code, notes, and snippets.

@smhuda
Created September 2, 2024 10:41
Show Gist options
  • Save smhuda/d8b5e79e49dfcdb84c2462586013715e to your computer and use it in GitHub Desktop.
Save smhuda/d8b5e79e49dfcdb84c2462586013715e to your computer and use it in GitHub Desktop.
Remove audio from video files in bulk
import os
import subprocess
# Specify the folder containing the videos
folder_path = "/Users/myuser/Downloads/vidz"
# Create a new folder to save the output videos without audio
output_folder = os.path.join(folder_path, "no_audio_videos")
if not os.path.exists(output_folder):
os.makedirs(output_folder)
# Loop through all files in the folder
for filename in os.listdir(folder_path):
# Check if the file is a video (you can add more extensions if needed)
if filename.endswith(('.MP4', '.AVI', '.MKV', '.MOV', '.mp4', '.avi', '.mkv', '.mov')):
# Full path to the input video
input_video_path = os.path.join(folder_path, filename)
# Define the output video path
output_video_path = os.path.join(output_folder, filename)
# Command to remove audio using ffmpeg
command = ["ffmpeg", "-i", input_video_path, "-an", output_video_path]
# Run the command
subprocess.run(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
print(f"Processed: {filename}")
print("All videos have been processed.")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment