我正在Firebase的node.js中使用fluent-ffmpeg库压缩用户通过android应用上传的视频,但是以下代码会产生错误:
ffmpeg(tempFilePath).videoBitrate('1000k', true)
.on('error', function(err) {
console.log('An error occurred: ' + err.message);
})
.on('end', function() {
console.log('Processing finished !');
})
.save(compressedVideoFilePath);
错误是:
TypeError: Bad argument
at TypeError (native)
at ChildProcess.spawn (internal/child_process.js:303:26)
at exports.spawn (child_process.js:370:9)
at /user_code/node_modules/fluent-ffmpeg/lib/processor.js:152:24
at FfmpegCommand.proto._getFfmpegPath (/user_code/node_modules/fluent-ffmpeg/lib/capabilities.js:90:14)
at FfmpegCommand.proto._spawnFfmpeg (/user_code/node_modules/fluent-ffmpeg/lib/processor.js:132:10)
at FfmpegCommand.proto.availableFormats.proto.getAvailableFormats (/user_code/node_modules/fluent-ffmpeg/lib/capabilities.js:517:10)
at /user_code/node_modules/fluent-ffmpeg/lib/capabilities.js:568:14
at nextTask (/user_code/node_modules/fluent-ffmpeg/node_modules/async/dist/async.js:5324:14)
at Object.waterfall (/user_code/node_modules/fluent-ffmpeg/node_modules/async/dist/async.js:5334:5)
tempFilePath是将用户上传的文件下载到firebase的temp文件夹中的(/tmp/test-4d68b02f-a6ef-4ff3-a5c9-52687fd3f0c4.mp4):
const tempFilePath = path.join(os.tmpdir(), filePath);
destBucket.file(filePath).download({
destination: tempFilePath // Download the file to destFilePath
}
compressedVideoFilePath是目标位置,我希望保存压缩文件(/tmp/compressed-test-4d68b02f-a6ef-4ff3-a5c9-52687fd3f0c4.mp4):
var compressedVideoFilePath = path.join(path.dirname(tempFilePath),"compressed-" + path.basename(tempFilePath));
保存压缩文件后,我将文件上传到Firebase存储(但可能不是导致错误的地方):
destBucket.upload(compressedVideoFilePath, {
destination: 'compressed-' + path.basename(filePath),
metadata: metadata
})
我不知道如何解决它,有人知道为什么这种情况持续发生吗?谢谢。 :)