Skip to content

Commit 14f3cf9

Browse files
committed
fix: compatible frame type incorrect
1 parent 113d186 commit 14f3cf9

5 files changed

Lines changed: 30 additions & 14 deletions

File tree

.changeset/kind-camels-smell.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@webav/av-cliper': patch
3+
---
4+
5+
fix: compatible frame type incorrect
373 KB
Binary file not shown.

packages/av-cliper/src/av-utils.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,16 @@
33
import { workerTimer } from '@webav/internal-utils';
44
import * as waveResampler from 'wave-resampler';
55

6+
import { Log } from '@webav/internal-utils';
7+
8+
if (import.meta.env?.DEV) {
9+
Log.setLogLevel(Log.debug);
10+
}
11+
12+
if (import.meta.env?.MODE === 'test') {
13+
Log.setLogLevel(Log.warn);
14+
}
15+
616
/**
717
* 合并(串联)多个 Float32Array,通常用于合并 PCM 数据
818
*/

packages/av-cliper/src/clips/__tests__/mp4-clip.test.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1+
import mp4box, { MP4ArrayBuffer } from '@webav/mp4box.js';
2+
import { file, write } from 'opfs-tools';
13
import { expect, test, vi } from 'vitest';
24
import { MP4Clip } from '../mp4-clip';
3-
import { file, write } from 'opfs-tools';
4-
import mp4box, { MP4ArrayBuffer } from '@webav/mp4box.js';
55

66
const mp4_123 = `//${location.host}/video/123.mp4`;
7+
const incorrectFrameTypeMp4 = `//${location.host}/video/incorrect-frame-type.mp4`;
78

89
async function fastestDecode(clip: MP4Clip) {
910
let time = 0;
@@ -169,3 +170,13 @@ test('get file header data', async () => {
169170
);
170171
expect(boxfile.moov?.mvhd.matrix.length).toBe(9);
171172
});
173+
174+
test('decode incorrectFrameTypeMp4', async () => {
175+
const clip = new MP4Clip((await fetch(incorrectFrameTypeMp4)).body!);
176+
await clip.ready;
177+
console.log(clip.meta.duration);
178+
expect(Math.round(clip.meta.duration / 1e6)).toBe(5);
179+
const { state, video } = await clip.tick(clip.meta.duration - 30e3);
180+
expect(state).toBe('success');
181+
expect(video?.timestamp).toBe(5e6);
182+
});

packages/av-cliper/src/clips/mp4-clip.ts

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -527,6 +527,7 @@ async function mp4FileToSamples(otFile: OPFSToolFile, opts: MP4ClipOpts = {}) {
527527

528528
let videoDeltaTS = -1;
529529
let audioDeltaTS = -1;
530+
let findedFirstSync = false;
530531
const reader = await otFile.createReader();
531532
await quickParseMP4File(
532533
reader,
@@ -560,7 +561,6 @@ async function mp4FileToSamples(otFile: OPFSToolFile, opts: MP4ClipOpts = {}) {
560561
(_, type, samples) => {
561562
if (type === 'video') {
562563
if (videoDeltaTS === -1) videoDeltaTS = samples[0].dts;
563-
let findedFirstSync = false;
564564
for (let i = 0; i < samples.length; i++) {
565565
const s = samples[i];
566566
if (!findedFirstSync && s.is_sync) {
@@ -1329,17 +1329,7 @@ function decodeGoP(
13291329
},
13301330
) {
13311331
if (dec.state !== 'configured') return;
1332-
try {
1333-
for (let i = 0; i < chunks.length; i++) dec.decode(chunks[i]);
1334-
} catch (err) {
1335-
if (
1336-
err instanceof Error &&
1337-
err.name === 'DataError' &&
1338-
opts.onDecodingError != null
1339-
) {
1340-
opts.onDecodingError(err);
1341-
}
1342-
}
1332+
for (let i = 0; i < chunks.length; i++) dec.decode(chunks[i]);
13431333

13441334
// todo:flush 之后下一帧必须是 IDR 帧,是否可以根据情况再决定调用 flush?
13451335
// windows 某些设备 flush 可能不会被 resolved,所以不能 await flush

0 commit comments

Comments
 (0)