-
Notifications
You must be signed in to change notification settings - Fork 20
/
extractaudio.py
28 lines (23 loc) · 939 Bytes
/
extractaudio.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
from moviepy.editor import VideoFileClip
import ffmpeg
from moviepy.editor import VideoFileClip, AudioFileClip
def extract_audio(input_path, audio_path):
clip1 = VideoFileClip(input_path)
audio = clip1.audio
audio.write_audiofile(audio_path)
def add_audio_to_video(video_path, audio_path, combined_path):
# Load the video clip
video_clip = VideoFileClip(video_path)
# Load the audio clip
audio_clip = AudioFileClip(audio_path)
# Set the audio of the video clip to the extracted audio
video_clip = video_clip.set_audio(audio_clip)
# Write the new video clip to the output file
video_clip.write_videofile(combined_path)
if __name__=="__main__":
input_path = 'test1.mp4'
audio_path = 'my_audio.wav'
extract_audio(input_path, audio_path)
video_path = 'video.mp4'
combinedvideo_path = 'my_combined_video.mp4'
add_audio_to_video(video_path, audio_path, combinedvideo_path)