用FFmpeg将多个音频混合成一个

huangapple go评论53阅读模式
英文:

Mix multiple audios into one with FFmpeg

问题

我有许多音频文件,我想将它们混合成一个音频文件,然后听起来就好像所有的音频都在同一时间播放。

我尝试使用最后一个命令中的 amix 滤镜,但出现错误 "在过滤器 Parsed_amix_0 上找不到匹配的未标记输入面板 1".

> inputs.txt
n=0
for file in *.mp3; do
  echo "file '$file'" >> inputs.txt
  ((n++))
done

ffmpeg -f concat -i inputs.txt -filter_complex amix=inputs=$n output.mp3

如果我手动解析输入文件(例如 2 个文件),如下所示

ffmpeg -i file1.mp3 -i file2.mp3 -filter_complex amix=inputs=2 output.mp3

该命令按预期工作。但我需要它能够处理任意数量的输入。

英文:

I have a lot of audio files I want to mix down into one audio file, that then should sound like as if all audios would play at the same time.

I tried to use the amix filter in the last command, but it fails with "Cannot find a matching stream for unlabeled input pad 1 on filter Parsed_amix_0".

> inputs.txt
n=0
for file in *.mp3; do
  echo "file '$file'" >> inputs.txt
  ((n++))
done

ffmpeg -f concat -i inputs.txt -filter_complex amix=inputs=$n output.mp3

If I manually parse the inputs files (e.g. 2 files) as follows

ffmpeg -i file1.mp3 -i file2.mp3 -filter_complex amix=inputs=2 output.mp3

the command works as intended. But I need it to work with an arbitrary amount of inputs.

答案1

得分: 0

看起来一些命令行工具更适合处理大量输入文件。

使用 sox,命令相当简单:

sox -m *.wav outputsox.wav

这里有一个使用 ffmpeg 的 Bash 脚本,它以音频/视频文件作为输入参数,将它们转换为 .wav 文件并与 amix 混合。

inputs=()
for f in "$@"; do
  ffmpeg -i "$f" -vn -acodec pcm_s16le "${f%.*}.wav"
  inputs+=("-i" "${f%.*}.wav")
done
ffmpeg "${inputs[@]}" -filter_complex amix=inputs=$# output.mp3
英文:

It seems some command line tools are easier for dealing with a large amount of input files.

Using sox, the command is rather simple:

sox -m *.wav outputsox.wav

And here is a Bash script using ffmpeg, that takes audio-/video-files as input arguments, converts them to .wav-files and mixes them with amix.

inputs=()
for f in "$@"; do
  ffmpeg -i "$f" -vn -acodec pcm_s16le "${f%.*}.wav"
  inputs+=("-i" "${f%.*}.wav")
done
ffmpeg "${inputs[@]}" -filter_complex amix=inputs=$# output.mp3

huangapple
  • 本文由 发表于 2023年3月21日 00:21:09
  • 转载请务必保留本文链接:https://go.coder-hub.com/75792819.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定