Skip to content

Commit

Permalink
fix: When the audio duration is relatively larger than the image dura…
Browse files Browse the repository at this point in the history
…tion, there might be a single flicker in the video. #68
hughfenghen committed Apr 3, 2024

Unverified

This commit is not signed, but one or more authors requires that any commit attributed to them is signed.
1 parent c234636 commit c36975e
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions packages/av-cliper/src/combinator.ts
Original file line number Diff line number Diff line change
@@ -9,6 +9,7 @@ interface IComItem {
offset: number;
duration: number;
sprite: OffscreenSprite;
expired: boolean;
/**
* main 资源时间结束时会终结合并流程;
* 比如合并 mp4(main) + mp3 + img, 所有资源可以缺省持续时间(duration);
@@ -150,6 +151,7 @@ export class Combinator {
offset: (opts.offset ?? 0) * 1e6,
duration: opts.duration == null ? sprite.duration : opts.duration * 1e6,
main: opts.main ?? false,
expired: false,
});
this.#comItems.sort((a, b) => a.sprite.zIndex - b.sprite.zIndex);
}
@@ -249,9 +251,9 @@ export class Combinator {
ctx.fillRect(0, 0, width, height);

const audios: Float32Array[][] = [];
for (let i = 0; !stoped && i < this.#comItems.length; i++) {
const it = this.#comItems[i];
if (ts < it.offset) continue;
for (const it of this.#comItems) {
if (stoped) break;
if (ts < it.offset || it.expired) continue;

ctx.save();
const { audio, done } = await it.sprite.offscreenRender(
@@ -270,7 +272,7 @@ export class Combinator {
}

it.sprite.destroy();
this.#comItems.splice(i, 1);
it.expired = true;
}
}

0 comments on commit c36975e

Please sign in to comment.