@@ -723,68 +723,68 @@ export function getSampleData(
723723 const sampleCount = readUint32 ( trun , 4 ) ;
724724 const sampleIndex = trackTimes . sampleCount ;
725725 trackTimes . sampleCount += sampleCount ;
726- if ( track . type === ElementaryStreamTypes . VIDEO ) {
727- const dataOffsetPresent = trun [ 3 ] & 0x01 ;
728- const firstSampleFlagsPresent = trun [ 3 ] & 0x04 ;
729- const sampleDurationPresent = trun [ 2 ] & 0x01 ;
730- const sampleSizePresent = trun [ 2 ] & 0x02 ;
731- const sampleFlagsPresent = trun [ 2 ] & 0x04 ;
732- const sampleCompositionTimeOffsetPresent = trun [ 2 ] & 0x08 ;
733- let offset = 8 ;
734- let remaining = sampleCount ;
735- if ( dataOffsetPresent ) {
726+ // Get duration from samples
727+ const dataOffsetPresent = trun [ 3 ] & 0x01 ;
728+ const firstSampleFlagsPresent = trun [ 3 ] & 0x04 ;
729+ const sampleDurationPresent = trun [ 2 ] & 0x01 ;
730+ const sampleSizePresent = trun [ 2 ] & 0x02 ;
731+ const sampleFlagsPresent = trun [ 2 ] & 0x04 ;
732+ const sampleCompositionTimeOffsetPresent = trun [ 2 ] & 0x08 ;
733+ let offset = 8 ;
734+ let remaining = sampleCount ;
735+ if ( dataOffsetPresent ) {
736+ offset += 4 ;
737+ }
738+ if ( firstSampleFlagsPresent && sampleCount ) {
739+ const isNonSyncSample = trun [ offset + 1 ] & 0x01 ;
740+ if ( ! isNonSyncSample && trackTimes . keyFrameIndex === undefined ) {
741+ trackTimes . keyFrameIndex = sampleIndex ;
742+ }
743+ offset += 4 ;
744+ if ( sampleDurationPresent ) {
745+ sampleDuration = readUint32 ( trun , offset ) ;
736746 offset += 4 ;
747+ } else {
748+ sampleDuration = defaultSampleDuration ;
737749 }
738- if ( firstSampleFlagsPresent && sampleCount ) {
739- const isNonSyncSample = trun [ offset + 1 ] & 0x01 ;
740- if ( ! isNonSyncSample && trackTimes . keyFrameIndex === undefined ) {
741- trackTimes . keyFrameIndex = sampleIndex ;
742- }
750+ if ( sampleSizePresent ) {
743751 offset += 4 ;
744- if ( sampleDurationPresent ) {
745- sampleDuration = readUint32 ( trun , offset ) ;
746- offset += 4 ;
747- } else {
748- sampleDuration = defaultSampleDuration ;
749- }
750- if ( sampleSizePresent ) {
751- offset += 4 ;
752- }
753- if ( sampleCompositionTimeOffsetPresent ) {
754- offset += 4 ;
755- }
756- sampleDTS += sampleDuration ;
757- rawDuration += sampleDuration ;
758- remaining -- ;
759752 }
760- while ( remaining -- ) {
761- if ( sampleDurationPresent ) {
762- sampleDuration = readUint32 ( trun , offset ) ;
763- offset += 4 ;
764- } else {
765- sampleDuration = defaultSampleDuration ;
766- }
767- if ( sampleSizePresent ) {
768- offset += 4 ;
769- }
770- if ( sampleFlagsPresent ) {
771- const isNonSyncSample = trun [ offset + 1 ] & 0x01 ;
772- if ( ! isNonSyncSample ) {
773- if ( trackTimes . keyFrameIndex === undefined ) {
774- trackTimes . keyFrameIndex =
775- trackTimes . sampleCount - ( remaining + 1 ) ;
776- trackTimes . keyFrameStart = sampleDTS ;
777- }
753+ if ( sampleCompositionTimeOffsetPresent ) {
754+ offset += 4 ;
755+ }
756+ sampleDTS += sampleDuration ;
757+ rawDuration += sampleDuration ;
758+ remaining -- ;
759+ }
760+ while ( remaining -- ) {
761+ if ( sampleDurationPresent ) {
762+ sampleDuration = readUint32 ( trun , offset ) ;
763+ offset += 4 ;
764+ } else {
765+ sampleDuration = defaultSampleDuration ;
766+ }
767+ if ( sampleSizePresent ) {
768+ offset += 4 ;
769+ }
770+ if ( sampleFlagsPresent ) {
771+ const isNonSyncSample = trun [ offset + 1 ] & 0x01 ;
772+ if ( ! isNonSyncSample ) {
773+ if ( trackTimes . keyFrameIndex === undefined ) {
774+ trackTimes . keyFrameIndex =
775+ trackTimes . sampleCount - ( remaining + 1 ) ;
776+ trackTimes . keyFrameStart = sampleDTS ;
778777 }
779- offset += 4 ;
780- }
781- if ( sampleCompositionTimeOffsetPresent ) {
782- offset += 4 ;
783778 }
784- sampleDTS += sampleDuration ;
785- rawDuration += sampleDuration ;
779+ offset += 4 ;
786780 }
787- } else {
781+ if ( sampleCompositionTimeOffsetPresent ) {
782+ offset += 4 ;
783+ }
784+ sampleDTS += sampleDuration ;
785+ rawDuration += sampleDuration ;
786+ }
787+ if ( ! rawDuration && defaultSampleDuration ) {
788788 rawDuration += defaultSampleDuration * sampleCount ;
789789 }
790790 }
0 commit comments