improve H264/H265 examples (#355) (#375) (#398)

This commit is contained in:
Alessandro Ros
2023-09-02 14:49:50 +02:00
committed by GitHub
parent 67af5e3840
commit 4f31866b9c
16 changed files with 757 additions and 44 deletions

View File

@@ -58,7 +58,7 @@ func (e *mpegtsMuxer) close() {
// encode encodes a H264 access unit into MPEG-TS.
func (e *mpegtsMuxer) encode(au [][]byte, pts time.Duration) error {
// prepend an AUD. This is required by some players
filteredNALUs := [][]byte{
filteredAU := [][]byte{
{byte(h264.NALUTypeAccessUnitDelimiter), 240},
}
@@ -69,11 +69,11 @@ func (e *mpegtsMuxer) encode(au [][]byte, pts time.Duration) error {
typ := h264.NALUType(nalu[0] & 0x1F)
switch typ {
case h264.NALUTypeSPS:
e.sps = append([]byte(nil), nalu...)
e.sps = nalu
continue
case h264.NALUTypePPS:
e.pps = append([]byte(nil), nalu...)
e.pps = nalu
continue
case h264.NALUTypeAccessUnitDelimiter:
@@ -86,16 +86,16 @@ func (e *mpegtsMuxer) encode(au [][]byte, pts time.Duration) error {
nonIDRPresent = true
}
filteredNALUs = append(filteredNALUs, nalu)
filteredAU = append(filteredAU, nalu)
}
au = filteredNALUs
au = filteredAU
if len(au) <= 1 || (!nonIDRPresent && !idrPresent) {
return nil
}
// add SPS and PPS before every group that contains an IDR
// add SPS and PPS before access unit that contains an IDR
if idrPresent {
au = append([][]byte{e.sps, e.pps}, au...)
}