Im getting error when generating thumbnails using ffmpeg in firebase functions

I'm writing this code for generating thumbnail from a video uploaded to firebase storage using FFmpeg, I am saving thumbnails first in the temp directory and then uploading it to firebase storage. The thumbnails are saved in temp dir but I'm getting an error while saving it to firebase storage. (EISDIR ERROR)

const targetTempFilePath = path.join(os.tmpdir(), targetTempFileName);
const targetStorageFilePath = path.join(path.dirname(filePath), targetTempFileName);
ffmpeg.ffprobe(req.body.videoUrl, (err, metaData) => {
    if (err) {
      console.log(err);
    }

    fileDuration = metaData.format.duration;
  });

  ffmpeg(req.body.videoUrl)
    .on("filenames", (filenames) => {
      console.log("Will generate " + filenames.join(", "));
      thumbsFileUrl = "" })
    .on("end", () => {
      console.log(targetTempFilePath);
      admin
        .storage()
        .bucket()
        .upload(targetTempFilePath, {
          destination: targetStorageFilePath,
        })
        .then(() => {
          console.log("Output audio uploaded to", targetStorageFilePath);
          // fs.unlinkSync(tempLocalFile);
          return res.status(200).json({
            success: true,
            thumbsFileUrl: thumbsFileUrl,
            fileDuration: fileDuration,
          });
        })
        .catch((err) => {
          console.log(err);
          return res.json({ success: false });
        });
    })

    .screenshots({
      // Will take screens at 20%, 40%, 60% and 80% of the video
      count: 2,
      folder: targetTempFilePath,
    });