ffmpegwasm / ffmpeg.wasm

FFmpeg for browser, powered by WebAssembly
https://ffmpegwasm.netlify.app
MIT License
13.47k stars 776 forks source link

memory access out of bounds #673

Open soheilhassanjani opened 5 months ago

soheilhassanjani commented 5 months ago

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;
  };
jumpjack commented 4 months ago

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

ejnu commented 3 months ago

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

FlopCoat commented 1 month ago

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