Add more relaxed rules for edit lists

This commit is contained in:
Vanilagy
2025-02-16 18:55:47 +01:00
parent a4c5ab4a8c
commit 873dae00c1
2 changed files with 17 additions and 3 deletions
+16 -1
View File
@@ -57,6 +57,9 @@ type InternalTrack = {
fragmentLookupTable: FragmentLookupTableEntry[] | null; fragmentLookupTable: FragmentLookupTableEntry[] | null;
currentFragmentState: FragmentTrackState | null; currentFragmentState: FragmentTrackState | null;
fragments: Fragment[]; fragments: Fragment[];
/** The segment durations of all edit list entries leading up to the main one (from which the offset is taken.) */
editListPreviousSegmentDurations: number;
/** The media time offset of the main edit list entry (with media time !== -1) */
editListOffset: number; editListOffset: number;
} & ({ } & ({
info: null; info: null;
@@ -253,6 +256,14 @@ export class IsobmffDemuxer extends Demuxer {
); );
this.readContiguousBoxes(boxInfo.contentSize); this.readContiguousBoxes(boxInfo.contentSize);
for (const track of this.tracks) {
// Modify the edit list offset based on the previous segment durations. They are in different
// timescales, so we first convert to seconds and then into the track timescale.
const previousSegmentDurationsInSeconds
= track.editListPreviousSegmentDurations / this.movieTimescale;
track.editListOffset -= Math.round(previousSegmentDurationsInSeconds * track.timescale);
}
break; break;
} }
@@ -584,6 +595,7 @@ export class IsobmffDemuxer extends Demuxer {
fragmentLookupTable: null, fragmentLookupTable: null,
currentFragmentState: null, currentFragmentState: null,
fragments: [], fragments: [],
editListPreviousSegmentDurations: 0,
editListOffset: 0, editListOffset: 0,
} satisfies InternalTrack as InternalTrack; } satisfies InternalTrack as InternalTrack;
this.currentTrack = track; this.currentTrack = track;
@@ -665,6 +677,7 @@ export class IsobmffDemuxer extends Demuxer {
this.metadataReader.pos += 3; // Flags this.metadataReader.pos += 3; // Flags
let relevantEntryFound = false; let relevantEntryFound = false;
let previousSegmentDurations = 0;
const entryCount = this.metadataReader.readU32(); const entryCount = this.metadataReader.readU32();
for (let i = 0; i < entryCount; i++) { for (let i = 0; i < entryCount; i++) {
@@ -686,13 +699,15 @@ export class IsobmffDemuxer extends Demuxer {
} }
if (mediaTime === -1) { if (mediaTime === -1) {
throw new Error('Unsupported edit list: no empty edits allowed.'); previousSegmentDurations += segmentDuration;
continue;
} }
if (mediaRate !== 1) { if (mediaRate !== 1) {
throw new Error('Unsupported edit list: media rate must be 1.'); throw new Error('Unsupported edit list: media rate must be 1.');
} }
track.editListPreviousSegmentDurations = previousSegmentDurations;
track.editListOffset = mediaTime; track.editListOffset = mediaTime;
relevantEntryFound = true; relevantEntryFound = true;
} }
+1 -2
View File
@@ -1,4 +1,3 @@
- onHeader, etc callbacks for Matroska - onHeader, etc callbacks for Matroska
- https://github.com/Vanilagy/mp4-muxer/issues/83 tell him it's possible now - https://github.com/Vanilagy/mp4-muxer/issues/83 tell him it's possible now
- is this fixed? https://github.com/Vanilagy/webm-muxer/issues/50 - is this fixed? https://github.com/Vanilagy/webm-muxer/issues/50
- decode and flush abstract in custom coders