0

I am trying to run an ffmpeg command in my electron app. I have created the function ffmpegTest() based off instructions for setting up ffmpeg here:

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

and the example query for ffmpeg-fluent here:

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")
}

it is trying to convert an image to a video, my filepaths are accurate, but when I run this function, I get this output in console:

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!

After the error prints out, I can see my output.m4v file inside my output folder, but it is 0KB in size and wont open. Is there some way I can specify my bit_rate / rate / width / height in my fluent-ffmpeg command so I can run this simple ffmpeg command?

thanks

Martin
  • 1,336
  • 4
  • 32
  • 69
  • Show the ffmpeg command being executed and the **complete** log. – llogan Jul 26 '20 at 23:40
  • I posted the command, ctrl+f ```var proc = ffmpeg(imgPath)``` and the full error log is my second code block, ctrl+f ```ffmpeg exited with code 1``` – Martin Jul 26 '20 at 23:45
  • I'm looking for the complete stderr output from the ffmpeg process. You only included one line from it: `Error while opening encoder for output stream #0:0 - maybe incorrect parameters such as bit_rate, rate, width or height`. Need to see all of the log to provide any suggestions. – llogan Jul 26 '20 at 23:47
  • its not running an ffmpeg command like ``$ ffmpeg stuff` im using the nodejs library fluent-ffmpeg , which only prints that output. I tried running a different command to convert a video file and that worked. so i think the library is setup correctly, im just missing some paramenters like bit_rate, going to try and find bit_rate for fluent-ffmpeg – Martin Jul 27 '20 at 00:00
  • I was assuming it was just a wrapper to the ffmpeg cli tool. The error message you received is a generic error: the actual error precedes it in the log. – llogan Jul 27 '20 at 00:05
  • thx i was able to fix it, turns out the example code i linked from github is outdated, fixed by adding resoltuon/video fields – Martin Jul 27 '20 at 00:06

1 Answers1

0

fixed by adding extra fields to command

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);
Martin
  • 1,336
  • 4
  • 32
  • 69