jhj0517 commited on
Commit
6b74fe5
·
2 Parent(s): 8c8001e ec1ebf1

Fix unsupported video format error

Browse files
modules/utils/files_manager.py CHANGED
@@ -61,3 +61,8 @@ def format_gradio_files(files: list):
61
  gradio_files.append(NamedString(file))
62
  return gradio_files
63
 
 
 
 
 
 
 
61
  gradio_files.append(NamedString(file))
62
  return gradio_files
63
 
64
+
65
+ def is_video(file_path):
66
+ video_extensions = ['.mp4', '.mkv', '.avi', '.mov', '.flv', '.wmv', '.webm', '.m4v', '.mpeg', '.mpg', '.3gp']
67
+ extension = os.path.splitext(file_path)[1].lower()
68
+ return extension in video_extensions
modules/uvr/music_separator.py CHANGED
@@ -10,8 +10,8 @@ from datetime import datetime
10
 
11
  from uvr.models import MDX, Demucs, VrNetwork, MDXC
12
  from modules.utils.paths import DEFAULT_PARAMETERS_CONFIG_PATH
13
- from modules.utils.files_manager import load_yaml, save_yaml
14
-
15
 
16
  class MusicSeparator:
17
  def __init__(self,
@@ -82,14 +82,18 @@ class MusicSeparator:
82
  file_paths: List of file paths where the separated audio is saved. Return empty when save_file is False.
83
  """
84
  if isinstance(audio, str):
85
- self.audio_info = torchaudio.info(audio)
86
- sample_rate = self.audio_info.sample_rate
87
- output_filename, ext = os.path.splitext(audio)
88
  output_filename, ext = os.path.basename(audio), ".wav"
 
 
 
 
 
 
 
89
  else:
90
- sample_rate = 16000
91
  timestamp = datetime.now().strftime("%m%d%H%M%S")
92
  output_filename, ext = f"UVR-{timestamp}", ".wav"
 
93
 
94
  model_config = {
95
  "segment": segment_size,
@@ -99,7 +103,7 @@ class MusicSeparator:
99
  if (self.model is None or
100
  self.current_model_size != model_name or
101
  self.model_config != model_config or
102
- self.audio_info.sample_rate != sample_rate or
103
  self.device != device):
104
  progress(0, desc="Initializing UVR Model..")
105
  self.update_model(
 
10
 
11
  from uvr.models import MDX, Demucs, VrNetwork, MDXC
12
  from modules.utils.paths import DEFAULT_PARAMETERS_CONFIG_PATH
13
+ from modules.utils.files_manager import load_yaml, save_yaml, is_video
14
+ from modules.diarize.audio_loader import load_audio
15
 
16
  class MusicSeparator:
17
  def __init__(self,
 
82
  file_paths: List of file paths where the separated audio is saved. Return empty when save_file is False.
83
  """
84
  if isinstance(audio, str):
 
 
 
85
  output_filename, ext = os.path.basename(audio), ".wav"
86
+
87
+ if is_video(audio):
88
+ audio = load_audio(audio)
89
+ sample_rate = 16000
90
+ else:
91
+ self.audio_info = torchaudio.info(audio)
92
+ sample_rate = self.audio_info.sample_rate
93
  else:
 
94
  timestamp = datetime.now().strftime("%m%d%H%M%S")
95
  output_filename, ext = f"UVR-{timestamp}", ".wav"
96
+ sample_rate = 16000
97
 
98
  model_config = {
99
  "segment": segment_size,
 
103
  if (self.model is None or
104
  self.current_model_size != model_name or
105
  self.model_config != model_config or
106
+ self.model.sample_rate != sample_rate or
107
  self.device != device):
108
  progress(0, desc="Initializing UVR Model..")
109
  self.update_model(