ffmpegwasm / ffmpegwasm/ffmpeg.wasm
memory access out of bounds
- Dominant language
- C
- Stars
- 17.8k
- Forks
- 1.1k
- PR merge metrics
- No merged PRs in 30d
Description
**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 :
```javascript
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;
};
```
Contributor guide
Assessment
This issue has not been assessed yet.