screenInputs: [
{
filePath: '/mnt/myfileshare/recordings/a98faaef_1728057913707/XYkWwbXu70bq65xyT4d3yciCZ3o1_screen_1728057921776.mp4',
timestamp: 1728057921776,
duration: 82.541667,
delay: 7.748
},
{
filePath: '/mnt/myfileshare/recordings/a98faaef_1728057913707/XYkWwbXu70bq65xyT4d3yciCZ3o1_screen_1728058028800.mp4',
timestamp: 1728058028800,
duration: 123.958333,
delay: 114.772
}
]
cameraInputs [
{
filePath: '/mnt/myfileshare/recordings/a98faaef_1728057913707/XYkWwbXu70bq65xyT4d3yciCZ3o1_camera_1728057921870.mp4',
timestamp: 1728057921870,
duration: 82.208333,
delay: 7.842
},
{
filePath: '/mnt/myfileshare/recordings/a98faaef_1728057913707/XYkWwbXu70bq65xyT4d3yciCZ3o1_camera_1728058028895.mp4',
timestamp: 1728058028895,
duration: 123.708333,
delay: 114.867
}
]


let command = ["-y", "-hwaccel", "cuda", "-hwaccel_output_format", "cuda"];

// Add input files
[...audioInputs, ...screenInputs, ...cameraInputs].forEach((input) => {
  command.push("-c:v", "h264_cuvid", "-i", input.filePath);
});

// Filter complex
let filterComplex = [];
let audioMerge = [];
let videoMerge = [];

// Process audio inputs
audioInputs.forEach((audio, index) => {
  filterComplex.push(
    `[${index}]adelay=${Math.round(audio.delay * 1000)}|${Math.round(
      audio.delay * 1000
    )}[a${index}]`
  );
  audioMerge.push(`[a${index}]`);
});

// Merge audio
if (audioMerge.length > 0) {
  filterComplex.push(
    `${audioMerge.join("")}amix=inputs=${
      audioMerge.length
    }:duration=longest[aout]`
  );
}

// Process screen input
if (screenInputs.length > 0) {
  const screenIndex = audioInputs.length;
  filterComplex.push(
    `[${screenIndex}]scale=iw:720:force_original_aspect_ratio=decrease,setpts=PTS-STARTPTS+${screenInputs[0].delay}/TB[screen_scaled]`,
    `[screen_scaled]pad=iw:720:(ow-iw)/2:(oh-ih)/2[screen]`
  );
  videoMerge.push("[screen]");
}

// Process camera inputs
cameraInputs.forEach((camera, index) => {
  const inputIndex = audioInputs.length + screenInputs.length + index;
  filterComplex.push(
    `[${inputIndex}]scale=480:-1:force_original_aspect_ratio=1,setpts=PTS-STARTPTS+${camera.delay}/TB[cam${index}]`
  );
  videoMerge.push(`[cam${index}]`);
});

// Merge video
if (videoMerge.length > 0) {
  filterComplex.push(
    `${videoMerge.join("")}xstack=inputs=${
      videoMerge.length
    }:layout=0_0|w0_0[vout]`
  );
}

// Add filter complex to command
if (filterComplex.length > 0) {
  command.push("-filter_complex", filterComplex.join(";"));
}

// Output options
if (audioMerge.length > 0) command.push("-map", "[aout]");
if (videoMerge.length > 0) command.push("-map", "[vout]");

command.push(
  "-c:v",
  "h264_nvenc",
  "-preset",
  "p4",
  "-b:v",
  "5M",
  "-maxrate",
  "10M",
  "-bufsize",
  "15M",
  "-c:a",
  "aac",
  "-b:a",
  "192k",
  "-shortest",
  outputFilePath
);
what i am trying to do:

merge the inputs into one output file as per their delay.

if no screen or camera input is available for certain duration i want to input blank screen in that place
right now the inputs are automatially scaled as per their original aspect ratio. i am providing the width only.
the camera input is stacked right to the screen input.

i am getthing this error:
[Parsed_xstack_16 @ 0x7399f4040f40] Failed to configure output pad on Parsed_xstack_16
[fc#0 @ 0x5673d1d61e80] Error reinitializing filters!

please give the correct code in one output