Concat multiple videos with diferent audio and subtitle streams count using ffmpeg

Solution 1:

Use

ffmpeg -i intro.mp4 -i input.mkv -itsoffset 4.5 -i input.mkv -i logo.png
  -filter_complex
     "[0:v] scale=480:270,setdar=16/9 [a];
      [1:v] scale=480:270,setdar=16/9 [b];
      [3:0] scale=480:270 [wm];
      [b][wm] overlay[ov];
      [a][0:a:0][0:a:0] [ov][1:a:0][1:a:1] concat=n=2:v=1:a=2 [vd] [a0] [a1]"
  -map "[vd]" -map "[a0]" -map "[a1]" -map 2:s? -c:s copy -y output.mkv

Once you specify any map statements, only those mapped streams are included. So, you have to explicitly map any subtitle streams. Since there may not be one, I've added a trailing ? to indicate conditional assignment.

I've fed the input video twice, because the subtitle timestamps will be wrong in the output as the intro now precedes the video. A timestamp offset is added to the 2nd input and the subtitle is mapped from that feed. The itsoffset value should be equal to the duration of the intro (in seconds). There shouldn't be any need to transcode the subtitles.