如何在 bash 中使用 ffmpeg 从一堆单声道文件制作一堆立体声文件?

发布于 2025-01-11 14:34:20 字数 428 浏览 3 评论 0原文

我有两个文件夹“左通道”和“右通道”。每个文件夹都包含具有相同名称的单声道文件。示例:“左声道”包含“A.wav”、“B.wav”、“C.wav”,“右声道”包含“A.wav”、“B.wav”、“C.wav”。我需要为每个单声道文件制作立体声文件。

所以我必须结合起来

ffmpeg -i left.mp3 -i right.mp3 -filter_complex "[0:a][1:a]join=inputs=2:channel_layout=stereo[a]" -map "[a]" output.mp3 

for file in /dir/* do ffmpeg -i ...; done

如何在 bash 中使用 ffmpeg 遍历所有单声道文件并从这些单声道文件中制作一堆立体声文件?

I have two folders "Left channel" and "Right channel". Each folder contains mono files with same names. Example: "Left channel" contains "A.wav", "B.wav", "C.wav" and "Right channel" contains "A.wav", "B.wav", "C.wav". I need to make stereo files for each mono files.

So I have to combine

ffmpeg -i left.mp3 -i right.mp3 -filter_complex "[0:a][1:a]join=inputs=2:channel_layout=stereo[a]" -map "[a]" output.mp3 

and

for file in /dir/* do ffmpeg -i ...; done

How can I go through all mono files and make bunch of stereo files from these mono files with ffmpeg in bash?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

墨小墨 2025-01-18 14:34:20

请您尝试以下操作:

#!/bin/bash

lch="Left channel"; rch="Right channel" # directory names of wav files
for f in "dir/$lch/"*.wav; do
    fname=${f##*/}                      # filename such as "A.wav"
    outfile="output_${fname%.*}.mp3"    # output filename such as "output_A.mp3"
    if [[ -f dir/$lch/$fname && dir/$rch/$fname ]]; then
        echo ffmpeg -i "dir/$lch/$fname" -i "dir/$rch/$fname" -filter_complex "[0:a][1:a]join=inputs=2:channel_layout=stereo[a]" -map "[a]" "$outfile"
    fi
done

它只是将命令行输出为空运行。如果输出看起来不错,请删除 echo 并再次运行。
请注意 echo 的输出删除了文件名周围的双引号。如果复制echo的输出并在命令行上执行它,则效果不佳。

Would you please try the following:

#!/bin/bash

lch="Left channel"; rch="Right channel" # directory names of wav files
for f in "dir/$lch/"*.wav; do
    fname=${f##*/}                      # filename such as "A.wav"
    outfile="output_${fname%.*}.mp3"    # output filename such as "output_A.mp3"
    if [[ -f dir/$lch/$fname && dir/$rch/$fname ]]; then
        echo ffmpeg -i "dir/$lch/$fname" -i "dir/$rch/$fname" -filter_complex "[0:a][1:a]join=inputs=2:channel_layout=stereo[a]" -map "[a]" "$outfile"
    fi
done

It just outputs the command line as a dry run. If the output looks good, drop echo and run again.
Please note the output of echo removes the double quotes around the filenames. If you copy the output of echo and execute it on the command line, it will not work well.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文