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