Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Getting video frame memory leak #13

Open
royibernthal opened this issue Jan 24, 2024 · 0 comments
Open

Getting video frame memory leak #13

royibernthal opened this issue Jan 24, 2024 · 0 comments

Comments

@royibernthal
Copy link

I'm getting the following errors on my NodeJS server when trying to get a video's frame:
Error [RuntimeError]: operation does not support unaligned accesses
Error [RuntimeError]: memory access out of bounds

It seems like the memory is not being cleared between consequtive operations, so memory that remains from a previous operation adds up to the current one, until it crashes.

It only happens when running on AWS (linux), locally (windows 10) it works as expected. I can increase the instance size on AWS, but it seems like a memory leak so it might not be the right way to tackle this.

I'm using @ffmpeg.wasm/main version 0.12.0

  1. Is there a way to properly clear the memory in between operations? (operation = getting a new frame from a new video)

  2. Is there a way to extract frames from videos without consuming so much memory?

Here's how I'm doing it right now:

private async getVideoFrameBuffer(
    time: string,
    name: string,
    buffer: Buffer,
  ) {
    this.ffmpeg.FS(
      'writeFile',
      name,
      new Uint8Array(buffer.buffer, 0, buffer.buffer.byteLength),
    );

    const frameName = name + '-frame.jpeg';

    await this.ffmpeg.run(
      '-i',
      name,
      '-ss',
      time,
      '-frames:v',
      '1',
      frameName,
    );

    const frameBuffer: Uint8Array = this.ffmpeg.FS('readFile', frameName);

    this.ffmpeg.FS('unlink', name);
    this.ffmpeg.FS('unlink', frameName);

    return frameBuffer;
  }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant