gpt4 book ai didi

node.js - Fluent ffmpeg如何用户保存回调

转载 作者:太空宇宙 更新时间:2023-11-04 00:07:09 25 4
gpt4 key购买 nike

我正在使用 Fluent-ffmpeg GIT我想进一步处理保存的文件。但保存没有任何回调。我怎样才能有 promise 地使用保存的文件。我的代码是

ffmpeg(filename)
.toFormat('mp3')
.on('error', (err) => {
console.log('An error occurred: ' + err.message);
})
.on('progress', (progress) => {
console.log('Processing: ' + progress.targetSize + ' KB converted');
})
.on('end', () => {
console.log('Processing finished !');
})
.save(`./${newname}.mp3`)

我的问题是“保存”函数没有回调。那么如何才能再次将输出保存到 S3 上呢?

最佳答案

save 方法不需要自己的回调。正如文档所解释的,

save(filename): save the output to a file

Starts ffmpeg processing and saves the output to a file.

Note: the save() method is actually syntactic sugar for calling both output() and run().

<...>

The end event is emitted when processing has finished. Listeners receive ffmpeg standard output and standard error as arguments, except when generating thumbnails (see below), in which case they receive an array of the generated filenames.

该流可以像任何其他流一样被 promise :

new Promise((resolve, reject) => {
ffmpeg(filename)
.toFormat('mp3')
.on('error', reject)
.on('progress', (progress) => {
console.log('Processing: ' + progress.targetSize + ' KB converted');
})
.on('end', resolve)
.save(`./${newname}.mp3`)
});

关于node.js - Fluent ffmpeg如何用户保存回调,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51726845/

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