gpt4 book ai didi

javascript - Node ffmpeg 以编程方式构建的命令列表(?)

转载 作者:行者123 更新时间:2023-12-04 23:18:05 24 4
gpt4 key购买 nike

我正在开发一个 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() command 需要一个 args/vars 列表来运行。
我现在将其静态设置为采用三个文件输入( -i),但我需要动态设置这些输入,因为 inputFileNames[] 列表中有许多字符串。
我试过给 await ffmpeg.run(myListArgs)一个 var 包含相同参数的列表,但它不起作用,但这会导致错误,因为它只运行最后一个 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 参数以适用于任意数量的输入?

最佳答案

使用如下语法修复:

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

关于javascript - Node ffmpeg 以编程方式构建的命令列表(?),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72252783/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com