diff --git a/inference_video.py b/inference_video.py index 6fd129f..96bf4c1 100644 --- a/inference_video.py +++ b/inference_video.py @@ -15,28 +15,28 @@ def transferAudio(sourceVideo, targetVideo): import shutil import moviepy.editor tempAudioFileName = "./temp/audio.mp3" - try: - # split audio from original video file and store in "temp" directory + + # split audio from original video file and store in "temp" directory + if True: + # extract audio from video if True: - # extract audio from video - if True: - video = moviepy.editor.VideoFileClip(sourceVideo) - audio = video.audio - # clear old "temp" directory if it exits - if os.path.isdir("temp"): - # remove temp directory - shutil.rmtree("temp") - # create new "temp" directory - os.makedirs("temp") - # write audio file to "temp" directory - audio.write_audiofile(tempAudioFileName) - os.rename(targetVideo, "noAudio_"+targetVideo) - # combine audio file and new video file - os.system("ffmpeg -y -i " + "noAudio_"+targetVideo + " -i " + tempAudioFileName + " -c copy " + targetVideo) - # remove audio-less video - os.remove("noAudio_"+targetVideo) - except: - pass + video = moviepy.editor.VideoFileClip(sourceVideo) + audio = video.audio + # clear old "temp" directory if it exits + if os.path.isdir("temp"): + # remove temp directory + shutil.rmtree("temp") + # create new "temp" directory + os.makedirs("temp") + # write audio file to "temp" directory + audio.write_audiofile(tempAudioFileName) + + os.rename(targetVideo, "noAudio_"+targetVideo) + # combine audio file and new video file + os.system("ffmpeg -y -i " + "noAudio_"+targetVideo + " -i " + tempAudioFileName + " -c copy " + targetVideo) + # remove audio-less video + os.remove("noAudio_"+targetVideo) + # remove temp directory shutil.rmtree("temp") @@ -196,5 +196,8 @@ if not vid_out is None: # move audio to new video file if appropriate if args.png == False and fpsNotAssigned == True and not args.skip and not args.video is None: - outputVideoFileName = '{}_{}X_{}fps.{}'.format(video_path_wo_ext, args.exp, int(np.round(args.fps)), args.ext) - transferAudio(video_path_wo_ext + "." + args.ext, outputVideoFileName) + outputVideoFileName = '{}_{}X_{}fps.{}'.format(video_path_wo_ext, 2 ** args.exp, int(np.round(args.fps)), args.ext) + try: + transferAudio(args.video, outputVideoFileName) + except: + print("Audio transfer failed. Interpolated video will have no audio")