ffmpeg.wasm icon indicating copy to clipboard operation
ffmpeg.wasm copied to clipboard

memory access out of bounds

Open soheilhasanjani opened this issue 1 year ago • 5 comments

Describe the bug Hello, I have a nextjs project based on typescript, I wrote a function that takes a video file and draws a few rectangles in each frame and takes snapshots from those frames and outputs it. It is ok for low data, but when the number of data increases, it gives this error.

error : Uncaught (in promise) RuntimeError: memory access out of bounds

my function :

const process = async (
    inputFile: any,
    frames: Frame[],
    showRectangles: boolean = false
  ) => {
    //
    const ffmpeg = ffmpegRef.current;
    //
    await ffmpeg.load();
    //
    ffmpeg.writeFile("file.mp4", await fetchFile(inputFile));
    //
    const snapshotUrls: string[] = [];
    // Loop through rectangles and draw on specific frames
    for (const frameItem of frames) {
      //
      const { frame, rectangles } = frameItem;
      //
      const outputFileName = `output_${frame}.mp4`;
      if (showRectangles === false) {
        await ffmpeg.exec(["-i", "file.mp4", "-frames:v", "1", outputFileName]);
      } else {
        await ffmpeg.exec([
          "-i",
          "file.mp4",
          "-vf",
          rectangles
            .map(
              (rec) =>
                `drawbox=x=${rec.x}:y=${rec.y}:w=${rec.width}:h=${rec.height}:color=red`
            )
            .join(","),
          "-frames:v",
          "1",
          outputFileName,
        ]);
      }
      await ffmpeg.exec([
        "-i",
        outputFileName,
        "-vframes",
        "1",
        `snapshot_${frame}.png`,
      ]);
      // Read the snapshot file and add its URL to the array
      const snapshotData = await ffmpeg.readFile(`snapshot_${frame}.png`);
      const snapshotUrl = URL.createObjectURL(
        new Blob([snapshotData], { type: "image/png" })
      );
      snapshotUrls.push(snapshotUrl);
      // Clean up temporary files
      ffmpeg.deleteFile(outputFileName);
      ffmpeg.deleteFile(`snapshot_${frame}.png`);
    }
    // Clean up input file
    ffmpeg.deleteFile("file.mp4");
    //
    setIsProcess(false);
    //
    return snapshotUrls;
  };

soheilhasanjani avatar Jan 16 '24 14:01 soheilhasanjani

I have same error for just one single jpg image.

My page:

https://github.com/jumpjack/ffmpeg.wasm-gh-pages/blob/main/public/transcode-002.html

@ffmpeg/core v0.12.5 @ffmpeg/ffmpeg v0.12.6 @ffmpeg/util v0.12.0

jumpjack avatar Mar 06 '24 14:03 jumpjack

The same here. Right before grabbing first frame, and after " cpb: bitrate max/min/avg: 0/0/200000 buffer size: 0 vbv_delay: N/A": RuntimeError: memory access out of bounds

ejnu avatar Mar 13 '24 07:03 ejnu

I get the same error when trying to export the video as .webm. It works just fine with mp4 and mov.

FlopCoat avatar May 21 '24 18:05 FlopCoat