Because of
metadata.streams.forEach((element) => {
video.width = element.width;
video.height = element.height;
});
streams contains both, video and audio.
So in your case, video.width and video.height are defined by the last iterration of forEach, and the last element of streams is an audio file, which doesn’t have any width and height. That’s why you get null.
Please read documantion of forEach and fluent-ffmpeg.