I’m trying to take an image file and a sound file and merge them together into an mp4 file. To this end, I use videoshow.js which is basically a wrapper for fluent-ffmpeg.js. For some reason, videoshow always sets the duration of the output file to 5 seconds regardless of what I set the loop parameter to. And to top it all off, it fades out the sound towards the end of the clip.

I’m happy for any solution to this even if it doesn’t include the use of videoshow or fluent-ffmpeg.

const url = require('url');
const { smartLog } = require('../services/smart-log');
const { getFile, getDuration } = require('../services/file-service');
const videoshow = require('videoshow');
const path = require('path');
const FFmpeg = require('fluent-ffmpeg');
const fs = require('fs');

const imgToMP4 = (caption, sound, image, duration, output) => {
  smartLog('info', `Converting ${image}`);
  const images = [image];

  const videoOptions = {
    fps: 10,
    loop: duration,
    transition: false,
    videoBitrate: 1024,
    videoCodec: 'libx264',
    size: '640x?',
    audioBitrate: '128k',
    audioChannels: 2,
    format: 'mp4',
    pixelFormat: 'yuv420p',
  };

  videoshow([
    {
      path: image,
    },
  ])
    .audio(sound)
    .save(output)
    .on('start', function (command) {
      smartLog('info', `ffmpeg process started: ${image}`);
    })
    .on('error', function (err) {
      smartLog('error', err);
    })
    .on('end', function (output) {
      smartLog('info', `Video created: ${output}`);
    });
};

1

There are 1 best solutions below

1
On

The only things I can see that need fixing...

  • You use muse set loop to -1 in order to repeat an image infinitely.
  • Use t to set a duration (or playing time).

Try this modified version of your code for const videoOptions:

const videoOptions = {
    fps: 10,
    loop: -1,
    t: duration,
    transition: false,
    videoBitrate: 1024,
    videoCodec: 'libx264',
    size: '640x?',
    audioBitrate: '128k',
    audioChannels: 2,
    format: 'mp4',
    pixelFormat: 'yuv420p',
  };