audio - 在 ffmpeg 中使用 -filter_complex 和批量连接数组

标签 audio ffmpeg cmd concatenation batch-processing

我在这里想做的是编写一个 ffmpeg 脚本,该脚本从文件夹中获取所有歌曲,并使用 Windows 中的命令行将它们合并到一个音频文件中。

到目前为止我已经

ffmpeg -i "pathforinput1" -i "pathforinput2" -i "pathforinputn" -filter_complex "[0:0] [1:0] concat=n=(number of songs goes here):v=0:a=1 "[a]"" -map "[a]" -acodec libmp3lame -ab 320k "output file.mp3"

我的问题是我想将它与现有脚本结合起来:

for %A in ("input folder\*.extension") do ffmpeg

创建一个使用 -i "%A" 的总脚本用于输入。我在这里遇到的问题是每个输入文件都需要数组 -filter_complex "[0:0] [1:0] 中的一个条目以及 concat=n=(number of files) 中存在的输入文件总数。我愿意使用批处理脚本来实现这一点,但我不知道如何查找文件夹中的文件总数,然后为每个文件创建一个数组(例如,如果有 7 首歌曲数组将是 [0:0] [1:0] [2:0] [3:0] [4:0] [5:0] [6:0] )。

任何使这成为可能的帮助或指示都会很棒。 this中的某人问题设法为 Unix 系统制作类似的东西,但我正在使用批处理文件,并且我不知道如何针对 Windows 修改它。

预先感谢您的帮助

好的,在第一位评论者的帮助下取得了进展。然而,我认为 ffmpeg 不喜欢我所做的。到目前为止我的代码是:

:: Give you a list of the .wav filenames in -i "filename1" -i "filename2" format

for %%a in ("C:\Users\James\Input\*.*") do call set var=%%var%% -i "%%a"
echo %var%

:: Give you the number of .mp3 files

for /f %%a in ('dir "C:\Users\James\Input\*.*" /b /a-d ^|find /c /v "" ') do set "numfiles=%%a"
echo there are "%numfiles%" files
set /a totalnum=numfiles

:: dir "C:\Users\James\Input\" /b >> C:\Users\James\Output\filelist.txt
:: print some text
set /a numfiles=numfiles-1
for /L %%b in (0,1,%numfiles%) do call set array=%%array%% [%%b:0]
:: for /L %%b in (0,1,%numfiles%) do call set array=%%array%% [0:0]
echo %array%
for /f "tokens=* delims= " %%C in ('echo %array% ') do set array=%%C
set array=%array:~0,-1%
echo %array%
:: for %%d in ("C:\Users\James\Input\*.*") do ffmpeg -i "%%d" -filter_complex "%array% concat=n=%totalnum%:v=0:a=1 "[a]"" -map "[a]" -acodec libmp3lame -ab 320k "C:\Users\James\Output\outputtestbatch1.mp3"
for %%d in ("C:\Users\James\Input\*.*") do ffmpeg -i "%%d" -filter_complex "%array% concat=n=%totalnum%:v=0:a=1 "[a]"" -map "[a]" -acodec libmp3lame -ab 320k "C:\Users\James\Output\outputtestbatch1.mp3"
pause`

我现在遇到的问题是,我认为 ffmpeg 假设每个输入文件都有音频流 [0:0],而不是一个接一个地递增它们。有没有办法用我正在使用的输入法来解决这个问题?

第二次编辑L:成功!我稍微修改了foxidrive的脚本,因为它配置稍有错误。最终产品在这里:

@echo off

for %%a in ("C:\Users\James\Input\*.*") do call set var=%%var%% -i "%%a"
:: echo %var%
:: Give you the number of files

for /f %%a in ('dir "C:\Users\James\Input\*.*" /b /a-d ^|find /c /v "" ') do set "numfiles=%%a"
echo there are "%numfiles%" files

for /L %%b in (0,%numfiles%) do call set array=%%array%% [%%b:0]
set array=%array:~1%
echo "%array%"

ffmpeg %var% -filter_complex "%array% concat=n=%numfiles%:v=0:a=1 "[a]"" -map "[a]" -acodec libmp3lame -ab 320k "C:\Users\James\Output\outputtestbatch1.mp3"

popd    
pause

最佳答案

编辑:添加了一系列文件类型:*.WAV *.MP3 *.FLAC *.M4A

这三个片段将:

:: Give you a list of the filenames in -i "filename1" -i "filename2" format

for %%a in (*.WAV *.MP3 *.FLAC *.M4A) do call set var=%%var%% -i "%%a"
echo %var%

:: Give you the number of .wav files

for /f %%a in ('dir *.WAV *.MP3 *.FLAC *.M4A /b /a-d ^|find /c /v "" ') do set "numfiles=%%a"
echo there are "%numfiles%" files

:: print some text
set /a numfiles=numfiles-1
for /L %%b in (0,1,%numfiles%) do call set array=%%array%% [%%b:0]
echo %array%
pause

注意:cmd 的许多方面都存在 8 KB 命令长度限制。

关于audio - 在 ffmpeg 中使用 -filter_complex 和批量连接数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23188742/

相关文章:

ios - 打开 Siri 停止 AVAudioPlayer

batch-file - 一行获取 Reg 查询的错误代码

windows - 从 cmd 运行 .exe 与双击它有何不同?

ios - 在不录制的情况下监控 iPhone 上的音频输入?

c# - 在 C# 中捕获声音输出

android - 用Android播放任意音

c++ - VideoWriter 不写任何东西

ffmpeg - 使用 ffmpeg concat 输出音频流的非单调 DTS

audio - 使用ffmpeg在两个音频文件之间交叉淡入淡出?

windows - 2018年4月更新后,如何在Windows 10上将 “default App”的文件扩展名设置为 “.exe”