本文目录导读:

Windows - 使用FFmpeg的批处理脚本
方法1:按固定顺序合并
@echo off
setlocal enabledelayedexpansion
:: 设置输入和输出文件夹
set "input_dir=C:\audio_input"
set "output_file=C:\merged_output\combined.mp3"
:: 创建文件列表
cd /d "%input_dir%"
if exist filelist.txt del filelist.txt
:: 按文件名排序生成列表(注意:数字需补零,如01.mp3,02.mp3)
(for %%i in (*.mp3 *.wav *.flac) do (
echo file '%%i'
)) > filelist.txt
:: 执行合并
ffmpeg -f concat -safe 0 -i filelist.txt -c copy "%output_file%"
echo 合并完成!
pause
方法2:按创建时间合并
@echo off
for /f "delims=" %%i in ('dir /b /od *.mp3') do (
echo file '%%i' >> temp_list.txt
)
ffmpeg -f concat -safe 0 -i temp_list.txt -c copy merged_output.mp3
del temp_list.txt
macOS/Linux - Shell脚本
基本合并脚本
#!/bin/bash
# 设置输入目录
INPUT_DIR="./audio_files"
OUTPUT_FILE="./merged_audio.mp3"
# 创建临时文件列表
> filelist.txt
# 按自然排序添加文件
for file in "$INPUT_DIR"/*.mp3; do
echo "file '$file'" >> filelist.txt
done
# 执行合并
ffmpeg -f concat -safe 0 -i filelist.txt -c copy "$OUTPUT_FILE"
# 清理
rm filelist.txt
echo "已合并到 $OUTPUT_FILE"
高级脚本:支持多种格式和错误处理
#!/bin/bash
merge_audio() {
local input_dir="$1"
local output_file="$2"
local format="${3:-mp3}"
# 检查输入目录
if [ ! -d "$input_dir" ]; then
echo "错误:目录 $input_dir 不存在"
exit 1
fi
# 创建临时列表
local tmp_list=$(mktemp)
# 查找音频文件
find "$input_dir" -type f \( -iname "*.mp3" -o -iname "*.wav" -o -iname "*.flac" -o -iname "*.m4a" \) | sort > "$tmp_list"
# 检查文件数量
if [ ! -s "$tmp_list" ]; then
echo "错误:未找到音频文件"
rm "$tmp_list"
exit 1
fi
# 格式化为ffmpeg concat列表
sed -i "s/^/file '/; s/$/'/" "$tmp_list"
# 执行合并
ffmpeg -f concat -safe 0 -i "$tmp_list" -c copy "$output_file.$format"
rm "$tmp_list"
echo "完成!输出文件:$output_file.$format"
}
# 使用方法
merge_audio "./input" "./output/merged" "mp3"
Python脚本(跨平台)
使用pydub库
import os
from pydub import AudioSegment
def batch_merge(input_dir, output_file, format="mp3"):
"""批量合并音频文件"""
# 获取所有音频文件
audio_files = []
for file in sorted(os.listdir(input_dir)):
if file.endswith(('.mp3', '.wav', '.flac', '.m4a')):
audio_files.append(os.path.join(input_dir, file))
if not audio_files:
print("未找到音频文件")
return
# 合并音频
combined = AudioSegment.empty()
for file in audio_files:
print(f"正在处理: {file}")
# 根据扩展名加载
ext = os.path.splitext(file)[1].lower()
if ext == '.mp3':
audio = AudioSegment.from_mp3(file)
elif ext == '.wav':
audio = AudioSegment.from_wav(file)
elif ext == '.flac':
audio = AudioSegment.from_file(file, "flac")
elif ext == '.m4a':
audio = AudioSegment.from_file(file, "m4a")
else:
continue
combined += audio
# 导出合并文件
combined.export(output_file, format=format)
print(f"合并完成!输出文件: {output_file}")
# 使用示例
if __name__ == "__main__":
input_directory = "./audio_files"
output_path = "./merged/combined.mp3"
batch_merge(input_directory, output_path)
使用FFmpeg的Python库
import subprocess
import os
from glob import glob
def ffmpeg_batch_merge(input_dir, output_file):
"""使用FFmpeg批量合并"""
# 获取排序后的文件列表
files = sorted(glob(os.path.join(input_dir, "*.[mM][pP]3")))
if not files:
print("未找到MP3文件")
return
# 创建文件列表
list_file = "temp_filelist.txt"
with open(list_file, "w") as f:
for file in files:
f.write(f"file '{os.path.abspath(file)}'\n")
# 执行FFmpeg命令
cmd = [
"ffmpeg",
"-f", "concat",
"-safe", "0",
"-i", list_file,
"-c", "copy",
output_file
]
subprocess.run(cmd, check=True)
os.remove(list_file)
print(f"合并完成!输出文件: {output_file}")
# 使用示例
ffmpeg_batch_merge("./audio_files", "./merged/combined.mp3")
Node.js脚本
const fs = require('fs');
const path = require('path');
const { spawn } = require('child_process');
async function batchMerge(inputDir, outputFile) {
// 获取所有音频文件
const files = fs.readdirSync(inputDir)
.filter(file => /\.(mp3|wav|flac|m4a)$/i.test(file))
.sort()
.map(file => path.join(inputDir, file));
if (files.length === 0) {
console.log('未找到音频文件');
return;
}
// 创建临时文件列表
const listContent = files.map(file => `file '${file}'`).join('\n');
const listFile = 'temp_list.txt';
fs.writeFileSync(listFile, listContent);
// 使用FFmpeg合并
return new Promise((resolve, reject) => {
const ffmpeg = spawn('ffmpeg', [
'-f', 'concat',
'-safe', '0',
'-i', listFile,
'-c', 'copy',
outputFile
]);
ffmpeg.on('close', (code) => {
fs.unlinkSync(listFile);
if (code === 0) {
console.log(`合并完成!输出文件: ${outputFile}`);
resolve();
} else {
reject(new Error(`FFmpeg退出代码: ${code}`));
}
});
ffmpeg.on('error', (err) => {
reject(err);
});
});
}
// 使用示例
batchMerge('./audio_files', './merged/combined.mp3');
安装依赖
FFmpeg安装
- Windows: 从 https://ffmpeg.org/download.html 下载
- macOS:
brew install ffmpeg - Linux:
sudo apt install ffmpeg
Python依赖安装
pip install pydub # 或 pip install ffmpeg-python
Node.js前提条件
需系统安装FFmpeg
使用建议
- 文件命名:建议使用数字前缀(01_xxx.mp3, 02_xxx.mp3)控制顺序
- 格式一致性:最好所有文件使用相同格式
- 采样率匹配:不同格式合并时注意采样率兼容性
- 备份原始文件:合并前先备份
选择适合你操作系统和编程环境的脚本即可。
版权声明:NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
足球直播
足球直播
足球直播
篮球直播
篮球直播
篮球直播
NBA直播
NBA直播
NBA直播
CBA直播
CBA直播
CBA直播
亚冠直播
亚冠直播
亚冠直播
欧冠直播
欧冠直播
欧冠直播
英超直播
英超直播
英超直播
西甲直播
西甲直播
西甲直播
中超直播
中超直播
中超直播
足球直播
足球直播
足球直播
篮球直播
篮球直播
篮球直播
NBA直播
NBA直播
NBA直播
CBA直播
CBA直播
CBA直播
亚冠直播
亚冠直播
亚冠直播
欧冠直播
欧冠直播
欧冠直播
英超直播
英超直播
英超直播
西甲直播
西甲直播
西甲直播
中超直播
中超直播
中超直播
足球直播
足球直播
足球直播
篮球直播
篮球直播
篮球直播
NBA直播
NBA直播
NBA直播
CBA直播
CBA直播
CBA直播
亚冠直播
亚冠直播
亚冠直播
欧冠直播
欧冠直播
欧冠直播
英超直播
英超直播
英超直播
西甲直播
西甲直播
西甲直播
中超直播
中超直播
中超直播
足球直播
足球直播
足球直播
篮球直播
篮球直播
篮球直播
NBA直播
NBA直播
NBA直播
CBA直播
CBA直播
CBA直播
亚冠直播
亚冠直播
亚冠直播
欧冠直播
欧冠直播
欧冠直播
英超直播
英超直播
英超直播
西甲直播
西甲直播
西甲直播
中超直播
中超直播
中超直播
曼联直播
曼联直播
曼联直播
日职联直播
日职联直播
日职联直播
澳超直播
澳超直播
澳超直播
阿森纳直播
阿森纳直播
阿森纳直播
足球直播
足球直播
足球直播
NBA直播
NBA直播
NBA直播
曼联直播
曼联直播
曼联直播
日职联直播
日职联直播
日职联直播
澳超直播
澳超直播
澳超直播
阿森纳直播
阿森纳直播
阿森纳直播
足球直播
足球直播
足球直播
NBA直播
NBA直播
NBA直播
曼联直播
曼联直播
曼联直播
日职联直播
日职联直播
日职联直播
澳超直播
澳超直播
澳超直播
阿森纳直播
阿森纳直播
阿森纳直播
足球直播
足球直播
足球直播
NBA直播
NBA直播
NBA直播
曼联直播
曼联直播
曼联直播
日职联直播
日职联直播
日职联直播
澳超直播
澳超直播
澳超直播
阿森纳直播
阿森纳直播
阿森纳直播
足球直播
足球直播
足球直播
NBA直播
NBA直播
NBA直播
欧冠直播
欧冠直播
欧冠直播
欧冠直播
欧冠直播
欧冠直播
欧冠直播
欧冠直播
欧冠直播
欧冠直播
欧冠直播
欧冠直播
欧冠直播
欧冠直播
欧冠直播
欧冠直播
欧冠直播
欧冠直播
欧冠直播
欧冠直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
足球直播
足球直播
足球直播
足球直播
足球直播
英超直播
英超直播
英超直播
英超直播
英超直播
篮球直播
篮球直播
篮球直播
篮球直播
篮球直播
CBA直播
CBA直播
CBA直播
CBA直播
CBA直播
中超直播
中超直播
中超直播
中超直播
中超直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
足球直播
足球直播
足球直播
足球直播
足球直播
英超直播
英超直播
英超直播
英超直播
英超直播
篮球直播
篮球直播
篮球直播
篮球直播
篮球直播
CBA直播
CBA直播
CBA直播
CBA直播
CBA直播
中超直播
中超直播
中超直播
中超直播
中超直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播