| from pathlib import Path | |
| from tqdm import tqdm | |
| import subprocess | |
| txt_path = Path("testSet.txt") # 你的 txt 文件路径 | |
| video_dir = Path("AVE") # 视频所在目录 | |
| audio_dir = Path("AVE_Audio") # 输出音频目录 | |
| audio_dir.mkdir(parents=True, exist_ok=True) | |
| # 读取 ID 或目录名(txt 每行:类别&id&...) | |
| with open(txt_path, "r", encoding="utf-8") as f: | |
| ids = [line.strip().split("&")[1] for line in f if line.strip()] | |
| for vid in tqdm(ids): | |
| mp4_path = video_dir / f"{vid}.mp4" | |
| wav_path = audio_dir / f"{vid}.wav" | |
| if not mp4_path.exists(): | |
| print(f"⚠️ {mp4_path} 不存在,跳过") | |
| continue | |
| cmd = [ | |
| "ffmpeg", "-y", | |
| "-i", str(mp4_path), | |
| "-vn", | |
| "-acodec", "pcm_s16le", | |
| "-ar", "16000", | |
| "-ac", "1", | |
| str(wav_path) | |
| ] | |
| subprocess.run(cmd, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) | |
| print("✅ 转换完成") |