Skip to content

Commit 697fc57

Browse files
committed
fix: maybe throw Error when splitAudioSampleByTime
1 parent 585fa95 commit 697fc57

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

.changeset/crazy-moose-raise.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: maybe throw Error when splitAudioSampleByTime

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

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1359,8 +1359,20 @@ function splitVideoSampleByTime(videoSamples: ExtMP4Sample[], time: number) {
13591359
return [preSlice, postSlice];
13601360
}
13611361

1362-
function splitAudioSampleByTime(audioSamples: ExtMP4Sample[], time: number) {
1363-
if (audioSamples.length === 0) return [];
1362+
function splitAudioSampleByTime(
1363+
audioSamples: ExtMP4Sample[],
1364+
time: number,
1365+
): [ExtMP4Sample[] | undefined, ExtMP4Sample[] | undefined] {
1366+
if (audioSamples.length === 0) return [undefined, undefined];
1367+
if (audioSamples[0].cts >= time) {
1368+
return [undefined, audioSamples.map((s) => ({ ...s }))];
1369+
}
1370+
1371+
const last = audioSamples[audioSamples.length - 1];
1372+
if (last.cts < time) {
1373+
return [audioSamples.map((s) => ({ ...s })), undefined];
1374+
}
1375+
13641376
let hitIdx = -1;
13651377
for (let i = 0; i < audioSamples.length; i++) {
13661378
const s = audioSamples[i];

0 commit comments

Comments
 (0)