Search code examples
javascriptffmpegfluentfluent-ffmpeg

Losing audio when overlaying videos with fluent ffmpeg


I have one main video file and a dynamic number of smaller video files that need to be overlayed at specific times based on timestamps.

I was able to get the video to overlay at the correct spots but now I don't have any audio. (Note: I only need audio from the first input as the overlayed videos have no audio)

I believe it is an issue with my syntax around the inputs, but can't quite figure it out. Any help is appreciated.

Here is my code:

 const mergedVideo = ffmpeg("/tmp/orignal.mp4");
 screenShareFileNames.forEach((fileName) => mergedVideo.addInput(fileName));

 const filters = screenShareFileNames.map((fileName, index) => {
    const inputs = index === 0 ? "[0:v][1:v]" : `[tmp][${index + 1}:v]`;
    const outputs = `tmp`;
          
    return {
            filter: "overlay",
            options: { enable: `between(t,${insertPoint},${insertPoint + 5})` },
            inputs,
            outputs,
          };
  });

  mergedVideo
     .complexFilter(filters, "tmp")
     .save("/tmp/final.mp4");




Solution

  • It appears I needed to add an outputOptions that mapped the audio from the orginal video.

     mergedVideo
              .complexFilter(filters, "tmp")
              .outputOptions(["-map 0:a"])
              .output("/tmp/final.mp4")
              .run();