【问题标题】:electron app fluent-ffmpeg " Error while opening encoder for output stream #0:0 - maybe incorrect parameters such as bit_rate, rate, width or height"electron app fluent-ffmpeg “打开输出流 #0:0 的编码器时出错 - 可能参数不正确,例如 bit_rate、rate、width 或 height”
【发布时间】:2020-11-16 06:47:41
【问题描述】:

我正在尝试在我的电子应用程序中运行 ffmpeg 命令。我根据此处设置 ffmpeg 的说明创建了函数 ffmpegTest():

https://alexandercleasby.dev/blog/use-ffmpeg-electron

这里是 ffmpeg-fluent 的示例查询:

https://github.com/fluent-ffmpeg/node-fluent-ffmpeg/blob/master/examples/image2video.js

function ffmpegTest(){
    console.log('ffmpeg-test')
    //require the ffmpeg package so we can use ffmpeg using JS
    const ffmpeg = require('fluent-ffmpeg');
    //Get the paths to the packaged versions of the binaries we want to use
    const ffmpegPath = require('ffmpeg-static').replace(
        'app.asar',
        'app.asar.unpacked'
    );
    const ffprobePath = require('ffprobe-static').path.replace(
        'app.asar',
        'app.asar.unpacked'
    );
    //tell the ffmpeg package where it can find the needed binaries.
    ffmpeg.setFfmpegPath(ffmpegPath);
    ffmpeg.setFfprobePath(ffprobePath);
    
    var imgPath = "C:\\Users\\marti\\Documents\\martinradio\\uploads\\israel song festival 1979\\front.jpg"
    var outputPath = "C:\\Users\\marti\\Documents\\martinradio\\uploads\\israel song festival 1979\\output.m4v"

    // make sure you set the correct path to your video file
    var proc = ffmpeg(imgPath)
    // loop for 5 seconds
    .loop(5)
    // using 25 fps
    .fps(25)
    // setup event handlers
    .on('end', function() {
    console.log('file has been converted succesfully');
    })
    .on('error', function(err) {
    console.log('an error happened: ' + err.message);
    })
    // save to file
    .save(outputPath);

    console.log("end of ffmpeg-test")
}

它正在尝试将图像转换为视频,我的文件路径是准确的,但是当我运行这个函数时,我在控制台中得到这个输出:

ffmpeg-test
index.js:137 end of ffmpeg-test
index.js:132 an error happened: ffmpeg exited with code 1: Error initializing output stream 0:0 -- Error while opening encoder for output stream #0:0 - maybe incorrect parameters such as bit_rate, rate, width or height
Conversion failed!

错误打印出来后,我可以在输出文件夹中看到我的 output.m4v 文件,但它的大小为 0KB,无法打开。有什么方法可以在我的 fluent-ffmpeg 命令中指定我的 bit_rate / rate / width / height 以便我可以运行这个简单的 ffmpeg 命令?

谢谢

【问题讨论】:

  • 显示正在执行的 ffmpeg 命令和 complete 日志。
  • 我发布了命令 ctrl+f var proc = ffmpeg(imgPath) 完整的错误日志是我的第二个代码块 ctrl+f ffmpeg exited with code 1
  • 我正在寻找 ffmpeg 进程的完整 stderr 输出。您只包含其中一行:Error while opening encoder for output stream #0:0 - maybe incorrect parameters such as bit_rate, rate, width or height。需要查看所有日志以提供任何建议。
  • 它没有使用 nodejs 库 fluent-ffmpeg 运行像 ``$ ffmpeg stuff` 这样的 ffmpeg 命令,它只打印该输出。我尝试运行不同的命令来转换视频文件,并且有效。所以我认为库设置正确,我只是缺少一些参数,如 bit_rate,将尝试为 fluent-ffmpeg 找到 bit_rate
  • 我假设它只是 ffmpeg cli 工具的包装器。您收到的错误消息是一般错误:日志中的实际错误位于它之前。

标签: ffmpeg electron fluent-ffmpeg


【解决方案1】:

通过向命令添加额外字段来修复

var imgPath = "C:\\Users\\marti\\Documents\\martinradio\\uploads\\israel song festival 1979\\front.jpg"
var outputPath = "C:\\Users\\marti\\Documents\\martinradio\\uploads\\israel song festival 1979\\output.m4v"

// make sure you set the correct path to your video file
var proc = ffmpeg(imgPath)
// loop for 5 seconds
.loop(5)
// using 25 fps
.fps(25)
//audio bitrate 
.audioBitrate('128k')
//video bitrate 
.videoBitrate('8000k', true)
//resolution
.size('1920x1080')
// setup event handlers
.on('end', function() {
    console.log('file has been converted succesfully');
})
.on('error', function(err) {
    console.log('an error happened: ' + err.message);
})
// save to file
.save(outputPath);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-02-27
    • 2015-05-06
    • 1970-01-01
    • 2022-07-27
    相关资源
    最近更新 更多