Skip to content

Commit

Permalink
fix: The output video has a corrupted image (artifacting)
Browse files Browse the repository at this point in the history
  • Loading branch information
hughfenghen committed Sep 12, 2024
1 parent 3b93dd9 commit 21ffb44
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/big-jokes-reflect.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@webav/av-cliper': patch
---

fix: The output video has a corrupted image (artifacting)
2 changes: 1 addition & 1 deletion packages/av-cliper/demo/concat-media.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ document.querySelector('#mp4-img')?.addEventListener('click', () => {
const spr1 = new OffscreenSprite(
new MP4Clip((await fetch(resList[0])).body!),
);
spr1.time.duration = 3e6;
// spr1.time.duration = 3e6;

const spr2 = new OffscreenSprite(
new ImgClip(
Expand Down
8 changes: 6 additions & 2 deletions packages/av-cliper/src/mp4-utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ function encodeVideoTrack(
let lastAddedSampleTime = 0;
// 双编码器交替消费,保证帧的顺序
// 小于期望帧间隔帧判定为连续的
const deltaTime = Math.floor((1000 / opts.expectFPS) * 1e6);
const deltaTime = Math.floor((1000 / opts.expectFPS) * 1e3);
function checkCache() {
if (!audioReady) return;
const nextEncId = curEncId === 'encoder1' ? 'encoder0' : 'encoder1';
Expand All @@ -231,7 +231,11 @@ function encodeVideoTrack(
// 检测是否需要切换消费队列
const nextFirst = nextCache[0];
// 另一个队列跟已消费的最后一帧是连续的,则需要切换
if (nextFirst != null && nextFirst.cts - lastAddedSampleTime < deltaTime) {
if (
nextFirst != null &&
nextFirst.is_sync &&
nextFirst.cts - lastAddedSampleTime < deltaTime
) {
curEncId = nextEncId;
// 说明另一个队列有数据,尽快消费
checkCache();
Expand Down

0 comments on commit 21ffb44

Please sign in to comment.