节点 ffmpeg 以编程方式构建命令列表(?)

node ffmpeg programmatically built list(?) of commands

我正在做一个 ffmpeg wasm 项目,我让它与这个代码一起工作:

        await ffmpeg.run(
            '-loop', '1',
            '-framerate', '2',
            "-i", inputFileNames[0], 
            "-i", inputFileNames[1],
            "-i", inputFileNames[2],
            "-c:a", "libmp3lame", 
            "-b:a", "320k", 
            "-filter_complex", "concat=n=2:v=0:a=1",
            "-vcodec", "libx264", 
            "-bufsize", "3M", 
            "-filter:v", "scale=w=1920:h=1930,pad=ceil(iw/2)*2:ceil(ih/2)*2", 
            "-crf", "18", 
            "-pix_fmt", "yuv420p", 
            "-shortest", "", 
            "-tune", "stillimage", 
            "-t", "13", 
            outputFileName
        );

https://github.com/MartinBarker/ffmpeg-wasm-node

如您所见,await ffmpeg.run() 命令将 args / vars 列表获取到 运行。 我将其静态设置为现在接受三个文件输入 (-i),但我需要动态设置这些输入,因为 inputFileNames[] 列表中有许多字符串。

我试过给 await ffmpeg.run(myListArgs) 一个包含相同参数列表的 var,但这不起作用,但这会导致错误,因为它只 运行s 最后一个 var outputFIlename 所以下面这个不工作:

        let ffmpegArgs=('-loop', '1',
        '-framerate', '2',
        "-i", inputFileNames[0], 
        "-i", inputFileNames[1],
        "-i", inputFileNames[2],
        "-c:a", "libmp3lame", 
        "-b:a", "320k", 
        "-filter_complex", "concat=n=2:v=0:a=1",
        "-vcodec", "libx264", 
        "-bufsize", "3M", 
        "-filter:v", "scale=w=1920:h=1930,pad=ceil(iw/2)*2:ceil(ih/2)*2", 
        "-crf", "18", 
        "-pix_fmt", "yuv420p", 
        "-shortest", "", 
        "-tune", "stillimage", 
        "-t", "13", 
        outputFileName)

        await ffmpeg.run(
            ffmpegArgs
        );

我试过像这样在一行中包含多个输入,但它会导致错误:


        await ffmpeg.run(
            '-loop', '1',
            '-framerate', '2',
            `-i ${inputFileNames[0]} -i ${inputFileNames[1]} -i ${inputFileNames[2]}`,
            "-c:a", "libmp3lame", 
            "-b:a", "320k", 
            "-filter_complex", "concat=n=2:v=0:a=1",
            "-vcodec", "libx264", 
            "-bufsize", "3M", 
            "-filter:v", "scale=w=1920:h=1930,pad=ceil(iw/2)*2:ceil(ih/2)*2", 
            "-crf", "18", 
            "-pix_fmt", "yuv420p", 
            "-shortest", "", 
            "-tune", "stillimage", 
            "-t", "13", 
            outputFileName
        );

[fferr] Unrecognized option 'i input-file-0 -i input-file-1 -i input-file-2'.
[fferr] Error splitting the argument list: Option not found
[ffout] FFMPEG_END

我试过只将输入作为列表,并使用 ... 在函数调用中展开它,但这会导致错误,而且逗号包含在命令中(它们不应该是)

        let ffmpegInputs=[
            "-i", inputFileNames[0], 
            "-i", inputFileNames[1],
            "-i", inputFileNames[2]
        ]
        await ffmpeg.run(
            '-loop', '1',
            '-framerate', '2',
            [...ffmpegInputs],
            "-c:a", "libmp3lame", 
            "-b:a", "320k", 
            "-filter_complex", "concat=n=2:v=0:a=1",
            "-vcodec", "libx264", 
            "-bufsize", "3M", 
            "-filter:v", "scale=w=1920:h=1930,pad=ceil(iw/2)*2:ceil(ih/2)*2", 
            "-crf", "18", 
            "-pix_fmt", "yuv420p", 
            "-shortest", "", 
            "-tune", "stillimage", 
            "-t", "13", 
            outputFileName
        );

[info] run ffmpeg command: -loop 1 -framerate 2 -i,input-file-0,-i,input-file-1,-i,input-file-2 -c:a libmp3lame -b:a 320k -filter_complex concat=n=2:v=0:a=1 -vcodec libx264 -bufsize 3M -filter:v scale=w=1920:h=1930,pad=ceil(iw/2)*2:ceil(ih/2)*2 -crf 18 -pix_fmt yuv420p -shortest  -tune stillimage -t 13 cool-output-video.mp4
TypeError: a.charCodeAt is not a function

如何动态创建我的 ffmpeg args 以适用于任意数量的输入?

已修复语法如下:

            '-framerate', '2',
            ...ffmpegInputs,
            "-c:a", "libmp3lame",