mirror of
https://github.com/hzwer/ECCV2022-RIFE.git
synced 2025-12-16 16:37:51 +01:00
Fixed audio not transfering
fixed #59 and notify the user if audio fails to transfer.
This commit is contained in:
@@ -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")
|
||||
|
||||
Reference in New Issue
Block a user