Created
November 13, 2022 17:41
-
-
Save nwizugbesamson/d25b3af88be11e34f4a817ba14d49762 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
this function will combine audio and video files to file named Output_Video.MP4 | |
in output folder created in the same directory you are running this function from | |
""" | |
### for more information for advance use check moviepy documentation ### | |
### https://zulko.github.io/moviepy/getting_started/getting_started.html ### | |
from moviepy.editor import * | |
import os | |
def combine_audio_video(audiofile,videofile,output_file_name_with_extension): | |
download_path = os.getcwd() | |
videoclip = VideoFileClip(videofile) | |
audioclip = AudioFileClip(audiofile) | |
video = videoclip.set_audio(audioclip) | |
if not os.path.exists(f'{download_path}\\output'): # if directory output dosen't | |
os.makedirs(f'{download_path}\\output') # exist create it | |
video.write_videofile(f'{download_path}\\output\\{output_file_name_with_extension}') | |
while True: ### check if audio and video files are closed to delete them | |
try: | |
myfile = open(f'{download_path}\\{files[1]}', "r+") | |
myfile.close() | |
os.remove(f'{download_path}\\{audiofile}') | |
os.remove(f'{download_path}\\{videofile}') | |
break | |
except IOError: | |
pass |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment