fluent-ffmpeg video has stretched image

70
November 22, 2020, at 3:10 PM

I have an mp3 audio file and a jpg image file. I want to combine these two files into a new mp4. I have a working fluent-ffmpeg command that does exactly what I want, except somethings an image will be stretched in the final output video. It seems to happen consistently with jpgs I export from photoshop.

Is there any way I can specify in my ffmpeg command to keep the same resolution of my image and not to stretch it?

My function below:

async function debugFunction() {
    console.log('debugFunction()')
    //begin setting up ffmpeg
    const ffmpeg = require('fluent-ffmpeg');
    //Get the paths to the packaged versions of the binaries we want to use
    var ffmpegPath = require('ffmpeg-static-electron').path;
    ffmpegPath = ffmpegPath.replace('app.asar', 'app.asar.unpacked')
    var ffprobePath = require('ffprobe-static-electron').path;
    ffprobePath = ffprobePath.replace('app.asar', 'app.asar.unpacked')
    //tell the ffmpeg package where it can find the needed binaries.
    ffmpeg.setFfmpegPath(ffmpegPath);
    ffmpeg.setFfprobePath(ffprobePath);
    //end setting ffmpeg
    let imgPath = "C:\\Users\\marti\\Documents\\martinradio\\image.jpg";
    let audioPath = "C:\\Users\\marti\\Documents\\martinradio\\audio.mp3";
    let vidPath = "C:\\Users\\marti\\Documents\\martinradio\\video.mp4";
    //create ffmpeg command
    ffmpeg()
    //set rendering options
    .input(imgPath)
    .loop()
    .addInputOption('-framerate 2')
    .input(audioPath)
    .videoCodec('libx264')
    .audioCodec('copy')
    .audioBitrate('320k')
    .videoBitrate('8000k', true)
    .size('1920x1080')
    .outputOptions([
        '-preset medium',
        '-tune stillimage',
        '-crf 18',
        '-pix_fmt yuv420p',
        '-shortest'
    ])
    //set status events
    .on('progress', function (progress) {
        if (progress.percent) {
            console.log(`Rendering: ${progress.percent}% done`)
        }
    })
    .on('codecData', function (data) {
        console.log('codecData=', data);
    })
    .on('end', function () {
        console.log('Video has been converted succesfully');
    })
    .on('error', function (err) {
        console.log('errer rendering video: ' + err.message);
    })
    //run ffmpeg command
    .output(vidPath).run()
}

renders successfully if I give it an audio file and this image:

But the output video looks like this:

You can see that the image was squished and stretched out like a rectangle, while I would like to keep it a cube.

Rent Charter Buses Company
READ ALSO
Getting 503 Application Error when turning my web app into a worker

Getting 503 Application Error when turning my web app into a worker

I am new in Heroku and after multiple app crashes due to frequent request timeout errors in my node js/express app, I am seeking to switch to a workerSo, I edited my Procfile from web: node index

99
how to catch request in express + nodejs?

how to catch request in express + nodejs?

could you please tell me how to catch request in express + nodejs ? I want to catch all request like /in/docs ,/es/docs,/fr/docs

101
nodejs serve blob(base64) as image

nodejs serve blob(base64) as image

I know there's two other similar questions, but mine just isn't working and I'm not sure why

114