Update muxer.

This commit is contained in:
Сергей Петров 2025-04-07 10:10:12 +05:00
parent cfca075ba5
commit 77a91c1086

View File

@ -31,6 +31,9 @@ type MpegTSMuxer struct {
H264Format *format.H264
Mpeg4AudioFormat *format.MPEG4Audio
idrFrame [][]byte
idrChecker bool
f *os.File
b *bufio.Writer
w *mpegts.Writer
@ -61,6 +64,8 @@ func (e *MpegTSMuxer) Initialize() error {
e.w = mpegts.NewWriter(e.b, []*mpegts.Track{e.h264Track, e.mpeg4AudioTrack})
e.idrChecker = false
return nil
}
@ -99,6 +104,7 @@ func (e *MpegTSMuxer) WriteH264(pts int64, au [][]byte) error {
case h264.NALUTypeIDR:
idrPresent = true
j++
e.idrFrame = append([][]byte{e.H264Format.SPS, e.H264Format.PPS}, nalu)
case h264.NALUTypeNonIDR:
nonIDRPresent = true
@ -111,14 +117,20 @@ func (e *MpegTSMuxer) WriteH264(pts int64, au [][]byte) error {
au = filteredAU
if au == nil || (!nonIDRPresent && !idrPresent) {
if !e.idrChecker {
au = append(e.idrFrame, au...)
e.idrChecker = true
//mux.frameChecker = true
}
if au == nil || ((!nonIDRPresent && !idrPresent) && e.idrFrame == nil) {
return nil
}
// Add SPS and PPS before access unit that contains an IDR.
if idrPresent {
au = append([][]byte{e.H264Format.SPS, e.H264Format.PPS}, au...)
}
//if idrPresent {
// au = append([][]byte{e.H264Format.SPS, e.H264Format.PPS}, au...)
//}
if e.dtsExtractor == nil {
// Skip samples silently until we find one with an IDR.