forked from hoangsonww/Image-Video-Tools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
remove_audio_from_video.py
59 lines (46 loc) · 1.8 KB
/
remove_audio_from_video.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
from moviepy.editor import VideoFileClip
import os
def remove_audio_from_video(input_path, output_path):
"""
Removes the audio track from a video file.
Args:
input_path (str): Path to the input video file.
output_path (str): Path to save the video file without audio.
Returns:
bool: True if the operation was successful, False otherwise.
"""
try:
# Load the video file
print("Loading video...")
video = VideoFileClip(input_path)
print("Video loaded successfully.")
# Remove audio
print("Removing audio...")
video_no_audio = video.without_audio()
# Save the new video
print("Saving the new video without audio...")
video_no_audio.write_videofile(output_path, codec='libx264', audio_codec=None)
print(f"Video saved without audio at {output_path}")
# Close the video file to free up resources
video.close()
video_no_audio.close()
return True
except Exception as e:
print(f"An error occurred: {e}")
return False
def main():
# Get user input for file paths
input_video_path = input("Enter the path to the video file: ")
output_video_path = input("Enter the path for the output video file: ")
# Check if the input file exists
if not os.path.exists(input_video_path):
print("The specified input file does not exist. Please check the path and try again.")
return
# Remove audio from the video
result = remove_audio_from_video(input_video_path, output_video_path)
if result:
print("Process completed successfully.")
else:
print("Process failed. Please check the error messages above for details.")
if __name__ == "__main__":
main()