mirror of
https://github.com/arcodange-org/mediabunny.git
synced 2026-09-27 02:43:48 +02:00
Fix incorrect GOP timestamp verification logic for first GOP (fixes #321)
This commit is contained in:
+1
-1
@@ -189,7 +189,7 @@
|
|||||||
},
|
},
|
||||||
trim: {
|
trim: {
|
||||||
//start: 0,
|
//start: 0,
|
||||||
//end: 10
|
end: 10
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
console.log(conversion);
|
console.log(conversion);
|
||||||
|
|||||||
+5
-1
@@ -21,7 +21,11 @@
|
|||||||
const sink = new Mediabunny.EncodedPacketSink(videoTrack);
|
const sink = new Mediabunny.EncodedPacketSink(videoTrack);
|
||||||
|
|
||||||
for await (const packet of sink.packets()) {
|
for await (const packet of sink.packets()) {
|
||||||
console.log(packet.timestamp);
|
console.log(packet.type, packet.timestamp);
|
||||||
|
|
||||||
|
if (packet.timestamp >= 5) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|||||||
+21
-18
@@ -46,12 +46,16 @@ export abstract class Muxer {
|
|||||||
|
|
||||||
private trackTimestampInfo = new WeakMap<OutputTrack, {
|
private trackTimestampInfo = new WeakMap<OutputTrack, {
|
||||||
maxTimestamp: number;
|
maxTimestamp: number;
|
||||||
maxTimestampBeforeLastKeyPacket: number;
|
maxTimestampBeforeLastKeyPacket: number | null;
|
||||||
}>();
|
}>();
|
||||||
|
|
||||||
protected validateAndNormalizeTimestamp(track: OutputTrack, timestampInSeconds: number, isKeyPacket: boolean) {
|
protected validateAndNormalizeTimestamp(track: OutputTrack, timestampInSeconds: number, isKeyPacket: boolean) {
|
||||||
timestampInSeconds += track.source._timestampOffset;
|
timestampInSeconds += track.source._timestampOffset;
|
||||||
|
|
||||||
|
if (timestampInSeconds < 0) {
|
||||||
|
throw new Error(`Timestamps must be non-negative (got ${timestampInSeconds}s).`);
|
||||||
|
}
|
||||||
|
|
||||||
let timestampInfo = this.trackTimestampInfo.get(track);
|
let timestampInfo = this.trackTimestampInfo.get(track);
|
||||||
if (!timestampInfo) {
|
if (!timestampInfo) {
|
||||||
if (!isKeyPacket) {
|
if (!isKeyPacket) {
|
||||||
@@ -60,29 +64,28 @@ export abstract class Muxer {
|
|||||||
|
|
||||||
timestampInfo = {
|
timestampInfo = {
|
||||||
maxTimestamp: timestampInSeconds,
|
maxTimestamp: timestampInSeconds,
|
||||||
maxTimestampBeforeLastKeyPacket: timestampInSeconds,
|
maxTimestampBeforeLastKeyPacket: null,
|
||||||
};
|
};
|
||||||
this.trackTimestampInfo.set(track, timestampInfo);
|
this.trackTimestampInfo.set(track, timestampInfo);
|
||||||
}
|
} else {
|
||||||
|
if (isKeyPacket) {
|
||||||
|
timestampInfo.maxTimestampBeforeLastKeyPacket = timestampInfo.maxTimestamp;
|
||||||
|
}
|
||||||
|
|
||||||
if (timestampInSeconds < 0) {
|
if (
|
||||||
throw new Error(`Timestamps must be non-negative (got ${timestampInSeconds}s).`);
|
timestampInfo.maxTimestampBeforeLastKeyPacket !== null
|
||||||
}
|
&& timestampInSeconds < timestampInfo.maxTimestampBeforeLastKeyPacket
|
||||||
|
) {
|
||||||
|
throw new Error(
|
||||||
|
`Timestamps cannot be smaller than the largest timestamp of the previous GOP (a GOP begins with a`
|
||||||
|
+ ` key packet and ends right before the next key packet). Got ${timestampInSeconds}s, but largest`
|
||||||
|
+ ` timestamp is ${timestampInfo.maxTimestampBeforeLastKeyPacket}s.`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
if (isKeyPacket) {
|
timestampInfo.maxTimestamp = Math.max(timestampInfo.maxTimestamp, timestampInSeconds);
|
||||||
timestampInfo.maxTimestampBeforeLastKeyPacket = timestampInfo.maxTimestamp;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (timestampInSeconds < timestampInfo.maxTimestampBeforeLastKeyPacket) {
|
|
||||||
throw new Error(
|
|
||||||
`Timestamps cannot be smaller than the largest timestamp of the previous GOP (a GOP begins with a key`
|
|
||||||
+ ` packet and ends right before the next key packet). Got ${timestampInSeconds}s, but largest`
|
|
||||||
+ ` timestamp is ${timestampInfo.maxTimestampBeforeLastKeyPacket}s.`,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
timestampInfo.maxTimestamp = Math.max(timestampInfo.maxTimestamp, timestampInSeconds);
|
|
||||||
|
|
||||||
return timestampInSeconds;
|
return timestampInSeconds;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user