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])
| 132 | subprocess.run(command, check=True) |
| 133 | |
| 134 | def 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 | |
| 162 | def split_data(video_files: List[str], val_list_hdtf: List[str]) -> (List[str], List[str]): |
| 163 | """ |