@@ -726,9 +726,10 @@ export const soundSampleDescription = (
726726) => {
727727 let version = 0 ;
728728 let contents : NestedNumberArray ;
729-
730729 let sampleSizeInBits = 16 ;
731- if ( ( PCM_AUDIO_CODECS as readonly AudioCodec [ ] ) . includes ( trackData . track . source . _codec ) ) {
730+
731+ const isPcmCodec = ( PCM_AUDIO_CODECS as readonly AudioCodec [ ] ) . includes ( trackData . track . source . _codec ) ;
732+ if ( isPcmCodec ) {
732733 const codec = trackData . track . source . _codec as PcmAudioCodec ;
733734 const { sampleSize } = parsePcmCodec ( codec ) ;
734735 sampleSizeInBits = 8 * sampleSize ;
@@ -738,6 +739,10 @@ export const soundSampleDescription = (
738739 }
739740 }
740741
742+ if ( trackData . muxer . isQuickTime ) {
743+ version = 1 ;
744+ }
745+
741746 if ( version === 0 ) {
742747 contents = [
743748 Array ( 6 ) . fill ( 0 ) , // Reserved
@@ -753,6 +758,8 @@ export const soundSampleDescription = (
753758 u16 ( 0 ) , // Sample rate (lower)
754759 ] ;
755760 } else {
761+ const compressionId = isPcmCodec ? 0 : - 2 ;
762+
756763 contents = [
757764 Array ( 6 ) . fill ( 0 ) , // Reserved
758765 u16 ( 1 ) , // Data reference index
@@ -761,13 +768,21 @@ export const soundSampleDescription = (
761768 u32 ( 0 ) , // Vendor
762769 u16 ( trackData . info . numberOfChannels ) , // Number of channels
763770 u16 ( Math . min ( sampleSizeInBits , 16 ) ) , // Sample size (bits)
764- u16 ( 0 ) , // Compression ID
771+ i16 ( compressionId ) , // Compression ID
765772 u16 ( 0 ) , // Packet size
766773 u16 ( trackData . info . sampleRate < 2 ** 16 ? trackData . info . sampleRate : 0 ) , // Sample rate (upper)
767774 u16 ( 0 ) , // Sample rate (lower)
768- u32 ( 1 ) , // Samples per packet (must be 1 for uncompressed formats)
769- u32 ( sampleSizeInBits / 8 ) , // Bytes per packet
770- u32 ( trackData . info . numberOfChannels * sampleSizeInBits / 8 ) , // Bytes per frame
775+ isPcmCodec
776+ ? [
777+ u32 ( 1 ) , // Samples per packet (must be 1 for uncompressed formats)
778+ u32 ( sampleSizeInBits / 8 ) , // Bytes per packet
779+ u32 ( trackData . info . numberOfChannels * sampleSizeInBits / 8 ) , // Bytes per frame
780+ ]
781+ : [
782+ u32 ( 0 ) , // Samples per packet (don't bother, still works with 0)
783+ u32 ( 0 ) , // Bytes per packet (variable)
784+ u32 ( 0 ) , // Bytes per frame (variable)
785+ ] ,
771786 u32 ( 2 ) , // Bytes per sample (constant in FFmpeg)
772787 ] ;
773788 }
0 commit comments