-
Notifications
You must be signed in to change notification settings - Fork 0
/
adding_audio.py
33 lines (25 loc) · 1.06 KB
/
adding_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
32
33
from moviepy.editor import *
import subprocess as sp
import os
import sys
if __name__ == '__main__':
input_video_source=sys.argv[1]
input_video_dest=sys.argv[2]
audio_file="audio.mp3"
output_video=sys.argv[3]
###############################Extracting the audio and saving it as a .mp3 file###############################
source_video = VideoFileClip(r""+input_video_source+"")
source_video.audio.write_audiofile(r""+audio_file+"")
source_video.close()
##############################Creating the command to combine the frames with the audio and form a new video###############################
command = ['ffmpeg',
'-y', #approve output file overwite
'-i', input_video_dest,
'-i', audio_file,
'-c:v', 'libx264',
'-c:a', 'aac', #to convert mp3 to aac
output_video]
process = sp.Popen(command)
process.wait()
##############################Deleting the audio file###############################
os.remove(""+audio_file+"")