Nick088 commited on
Commit
33a9dc7
·
verified ·
1 Parent(s): 37f1dd0

Update infer.py

Browse files
Files changed (1) hide show
  1. infer.py +5 -3
infer.py CHANGED
@@ -7,6 +7,7 @@ import numpy as np
7
  import tqdm
8
  import pydub
9
  from pydub import AudioSegment
 
10
 
11
  device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
12
 
@@ -31,7 +32,7 @@ def infer_video(video_filepath: str, size_modifier: int) -> str:
31
  model.load_weights(f'weights/RealESRGAN_x{size_modifier}.pth', download=False)
32
 
33
  # Extract audio from the original video file
34
- audio = AudioSegment.from_file(video_filepath, format=video_filepath.split('.')[-1])
35
  audio_array = np.array(audio.get_array_of_samples())
36
 
37
  # Create a VideoCapture object for the video file
@@ -75,10 +76,11 @@ def infer_video(video_filepath: str, size_modifier: int) -> str:
75
  vid_writer.release()
76
 
77
  # Create a new VideoFileClip object from the output video
78
- output_clip = mpy.VideoFileClip(vid_output)
79
 
80
  # Add the audio back to the output video
81
- output_clip = output_clip.set_audio(mpy.AudioFileClip(video_filepath, fps=output_clip.fps))
 
82
 
83
  # Save the output video to a new file
84
  output_clip.write_videofile(f'output_{video_filepath}')
 
7
  import tqdm
8
  import pydub
9
  from pydub import AudioSegment
10
+ from moviepy.editor import VideoFileClip, AudioFileClip
11
 
12
  device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
13
 
 
32
  model.load_weights(f'weights/RealESRGAN_x{size_modifier}.pth', download=False)
33
 
34
  # Extract audio from the original video file
35
+ audio = AudioSegment.from_file(video_filepath, format="mp4")
36
  audio_array = np.array(audio.get_array_of_samples())
37
 
38
  # Create a VideoCapture object for the video file
 
76
  vid_writer.release()
77
 
78
  # Create a new VideoFileClip object from the output video
79
+ output_clip = VideoFileClip(vid_output)
80
 
81
  # Add the audio back to the output video
82
+ audio_clip = AudioFileClip(f"{video_filepath.split('.')[0]}.wav", fps=output_clip.fps)
83
+ output_clip = output_clip.set_audio(audio_clip)
84
 
85
  # Save the output video to a new file
86
  output_clip.write_videofile(f'output_{video_filepath}')