core icon indicating copy to clipboard operation
core copied to clipboard

Cannot load video composition when there're too many clips

Open whentao opened this issue 11 months ago • 1 comments

Hey Diffusion studio team, thank you for the amazing work.

I got an error for many clips and doesn't find any way to get around with it.

When there're many clips, the composition will crash at one certain number based on the file size, even though I only take 1 frame for the clip. For example,

const composition = new core.Composition({ background: "#76b7f5" });

setupControls(composition);
setupTimeline(composition);
const videoSource = await core.VideoSource.from("/video1.mp4");

for (let i = 0; i < 200; i++) {
  console.log("goto:", i);
  const videoClip = await composition.add(
    new core.VideoClip(videoSource, {
      position: "center",
      height: "100%",
      muted: true,
    }).subclip(0, 1)
  );
}

My video size is 78MB. This logic would always throw error at i == 128 no matter how many frames I take into clips. The error is

MediaError {code: 4, message: 'DECODER_ERROR_NOT_SUPPORTED: video decoder initial…led with DecoderStatus::Codes::kUnsupportedConfig'}
code : 4
message : "DECODER_ERROR_NOT_SUPPORTED: video decoder initialization failed with DecoderStatus::Codes::kUnsupportedConfig"

After some testing from my side, one possible reason is that, the browser element could only hold a certain size of video cache. Since I tried the following logic

for (let i = 0; i < 100; i++) {
  ....
}

composition.removeTracks(core.Track);
composition.removeTracks(core.VideoTrack);

await delay(5000);

for (let i = 0; i < 100; i++) {
  ....
}

This doesn't solve the crash. I have to manually clean up video element using this code inside video clip when removeTracks to avoid the error. If I don't reset the src, the error doesn't go away.

  public removeSelf(): void {
    this.element.removeAttribute("src");
    this.element.load();
    this.element.src = "";
    this.element.srcObject = null;
    this.element.remove();
  }

Any ideas to reuse as any as possible about the video element?

whentao avatar Jan 07 '25 00:01 whentao

Hey! Thanks for reaching out.

Try V2, just released—it includes major improvements in memory management and should fix this issue. Let us know if you need any help!

k9p5 avatar Feb 04 '25 11:02 k9p5