Search code examples
ffmpegfluent-ffmpeg

How to add multiple subtitle in fluent FFMPEG nodejs


I searched and found some commands that using FFmpeg commands, but I cannot convert to work in the fluent FFmpeg, so requesting to help me.

This is the command I found on another answer

ffmpeg -i $movie.mov -i $sub_en.srt -i $sub_de.srt \
-map 0:v -map 0:a -map 1 -map 2 \
-c:v copy -c:a copy -c:s srt \
-metadata:s:s:0 language=eng -metadata:s:s:1 language=ger \
$output.mkv

This is how I added subtitle stream on fluent FFmpeg.

ffmpeg()
    .addInput("./sample3.mp4")
    .addInput("merged.wav")
    .outputOptions(
      "-vf subtitles=./subt/114.srt:force_style='Alignment=10,FontName=QCF2604,Fontsize=18,MarginL=5,MarginV=25,Outline=0'"
    )
    .outputOptions(
      "-vf subtitles=dd.srt:force_style='Alignment=1,FontName=QCF2604,Fontsize=18,MarginL=5,MarginV=25,Outline=0'"
    )
    .outputOptions("-shortest")

    .output("./test.mp4")
    .on("end", function () {
      console.log("conversion ended");
      callback(null);
    })
    .on("error", function (e) {
      console.log("error: ", e.code, e.msg, e);
      callback(e);
    })
    .run();
}

But by this way, only the second subtitle is appearing on the video. Thank you.


Solution

  • I found a way!

    ffmpeg()
        .addInput("./sample3.mp4")
        .addInput("./ayahs/114.png")
        .addInput("merged.wav")
    
        .addInput("color=black:s=600x1000:r=25") // Background Overlay
        .inputFormat("lavfi")
    
        .complexFilter([
          subtitles=./subt/114.srt:force_style='Alignment=10,FontName=QCF2604,Fontsize=14,MarginL=5,MarginV=25,Outline=0'[subt1]", // arabic subtitle
          "[subt1]subtitles=./subt/114_trans.srt:force_style='Alignment=2,FontName=FML-Leela,Fontsize=8,MarginL=15,MarginV=115,Outline=0'", // malayalam subtitle
        ])
    
        .outputOptions("-shortest")
        .output("./test.mp4")
        .on("end", function () {
          console.log("conversion ended");
          callback(null);
        })
        .on("error", function (e) {
          console.log("error: ", e.code, e.msg, e);
          callback(e);
        })
        .run();
    }