代码之家  ›  专栏  ›  技术社区  ›  cuneyttyler

Node.js中的FFMPEG:转换失败

  •  0
  • cuneyttyler  · 技术社区  · 12 月前

    我有一个小的node.js web应用程序。我在get请求中这样使用:

    app.get('/api/voice/:gender/:voice/:pitch', function(req, res){
            if(req.params.pitch == "1" || req.params.pitch == "1.0") {
                const file = "./voices/" + req.params.gender.toLowerCase() + "/" + req.params.voice + ".mp3"
                res.download(file);
                return
            }
    
            const inputFile = "./voices/" + req.params.gender.toLowerCase() + "/" + req.params.voice + ".mp3"
            const output_file = "./Audio/Temp/" + req.params.voice + ".mp3"
            ffmpeg()
                    .input(inputFile)
                    .audioCodec('pcm_s16le') // Set the audio codec to PCM with 16-bit depth
                    .audioFrequency(44100) // Set the sample rate
                    .on('error', function(err) {
                        console.error('Error while converting:', err);
                    })
                    .on('end', function() {
                        // res.download(output_file)
                    })
                    .save(output_file);
    
        });
    

    它给 Conversion Failed 错误:

    [2024-07-11T18:11:22.880Z] Error while converting: Error: ffmpeg exited with code 1: Conversion failed!
    
        at ChildProcess.<anonymous> (d:\Dev\Anima\Client\node_modules\fluent-ffmpeg\lib\processor.js:180:22)
        at ChildProcess.emit (d:\Dev\Anima\Client\lib\events.js:519:28)
        at ChildProcess._handle.onexit (d:\Dev\Anima\Client\lib\internal\child_process.js:294:12)
        at Process.callbackTrampoline (node:internal/async_hooks:130:17) {stack: 'Error: ffmpeg exited with code 1: Conversion …Trampoline (node:internal/async_hooks:130:17)', message: 'ffmpeg exited with code 1: Conversion failed!
    '}
    

    当我在node.js桌面(.exe)应用程序中使用相同的代码时,它成功运行。当我在express.js应用程序中使用它时,它失败了。错误消息不清楚。问题是什么?

    0 回复  |  直到 12 月前