MCPcopy Create free account
hub / github.com/TMElyralab/MuseTalk / extract_audio

Function extract_audio

scripts/preprocess.py:134–160  ·  view source on GitHub ↗

Extract audio from video files and save as WAV format. Parameters: org_path (str): The directory containing the original video files. dst_path (str): The directory where the extracted audio files will be saved. vid_list (List[str]): A list of video file names to process. R

(org_path: str, dst_path: str, vid_list: List[str])

Source from the content-addressed store, hash-verified

132 subprocess.run(command, check=True)
133
134def extract_audio(org_path: str, dst_path: str, vid_list: List[str]) -> None:
135 """
136 Extract audio from video files and save as WAV format.
137
138 Parameters:
139 org_path (str): The directory containing the original video files.
140 dst_path (str): The directory where the extracted audio files will be saved.
141 vid_list (List[str]): A list of video file names to process.
142
143 Returns:
144 None
145 """
146 for idx, vid in enumerate(vid_list):
147 if vid.endswith('.mp4'):
148 video_path = os.path.join(org_path, vid)
149 audio_output_path = os.path.join(dst_path, os.path.splitext(vid)[0] + ".wav")
150 try:
151 command = [
152 'ffmpeg', '-hide_banner', '-y', '-i', video_path,
153 '-vn', '-acodec', 'pcm_s16le', '-f', 'wav',
154 '-ar', '16000', '-ac', '1', audio_output_path,
155 ]
156
157 subprocess.run(command, check=True)
158 print(f"Audio saved to: {audio_output_path}")
159 except subprocess.CalledProcessError as e:
160 print(f"Error extracting audio from {vid}: {e}")
161
162def split_data(video_files: List[str], val_list_hdtf: List[str]) -> (List[str], List[str]):
163 """

Callers 1

mainFunction · 0.85

Calls 1

runMethod · 0.80

Tested by

no test coverage detected