diff --git a/codec/adpcm/adpcm.go b/codec/adpcm/adpcm.go index 479f6261..b61d9fee 100644 --- a/codec/adpcm/adpcm.go +++ b/codec/adpcm/adpcm.go @@ -369,7 +369,7 @@ func capAdd16(a, b int16) int16 { // EncBytes will return the number of adpcm bytes that will be generated when encoding the given amount of pcm bytes (n). func EncBytes(n int) int { // For 'n' pcm bytes, 1 sample is left uncompressed, the rest is compressed by a factor of 4 - // and a start index and padding-flag byte are added. + // and a chunk length (4B), start index (1B) and padding-flag (1B) are added. // Also if there are an even number of samples, there will be half a byte of padding added to the last byte. if n%bytesPerEnc == 0 { return (n-byteDepth)/compFact + headSize + 1 diff --git a/container/mts/encoder.go b/container/mts/encoder.go index 7d968d5f..693b0be3 100644 --- a/container/mts/encoder.go +++ b/container/mts/encoder.go @@ -44,7 +44,7 @@ import ( const ( H264ID = 27 H265ID = 36 - audioStreamID = 0xc0 // First audio stream ID. + audioStreamID = 0xc0 // ADPCM audio stream ID. ) // Constants used to communicate which media codec will be packetized. @@ -150,10 +150,12 @@ type Encoder struct { func NewEncoder(dst io.WriteCloser, rate float64, mediaType int) *Encoder { var mPid int var sid byte + nbp := true switch mediaType { case EncodeAudio: mPid = AudioPid sid = audioStreamID + nbp = false case EncodeH265: mPid = VideoPid sid = H265ID @@ -168,7 +170,7 @@ func NewEncoder(dst io.WriteCloser, rate float64, mediaType int) *Encoder { Pil: 0, Essd: &psi.ESSD{ St: byte(sid), - Epid: 0x0100, + Epid: uint16(mPid), Esil: 0x00, }, } @@ -180,7 +182,7 @@ func NewEncoder(dst io.WriteCloser, rate float64, mediaType int) *Encoder { writePeriod: time.Duration(float64(time.Second) / rate), ptsOffset: ptsOffset, - nalBasedPSI: true, + nalBasedPSI: nbp, pktCount: 8,