mirror of
https://github.com/cnotch/ipchub.git
synced 2025-09-27 03:45:54 +08:00
fixed bug: sps start with 0x000001 or 0x00000001
This commit is contained in:
@@ -41,6 +41,14 @@ func TestRawSPS_Parse(t *testing.T) {
|
|||||||
float64(60000) / float64(1001*2),
|
float64(60000) / float64(1001*2),
|
||||||
false,
|
false,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"tpl500",
|
||||||
|
"AAAAAWdkAB6s0gLASaEAAAMAAQAAAwAehA==",
|
||||||
|
704,
|
||||||
|
576,
|
||||||
|
15,
|
||||||
|
false,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
|
@@ -33,6 +33,14 @@ func TestH265RawSPS_DecodeString(t *testing.T) {
|
|||||||
30,
|
30,
|
||||||
false,
|
false,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"tpl500-265",
|
||||||
|
"AAAAAUIBAQFgAAADAAADAAADAAADAJagAWggBln3ja5JMmuWMAgAAAMACAAAAwB4QA==",
|
||||||
|
2880,
|
||||||
|
1620,
|
||||||
|
15,
|
||||||
|
false,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
|
@@ -24,6 +24,11 @@ func TestH265RawVPS_DecodeString(t *testing.T) {
|
|||||||
"QAEMAf//AWAAAAMAkAAAAwAAAwBdlZgJ",
|
"QAEMAf//AWAAAAMAkAAAAwAAAwBdlZgJ",
|
||||||
false,
|
false,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"tpl500-265",
|
||||||
|
"AAAAAUABDAH//wFgAAADAAADAAADAAADAJasCQ==",
|
||||||
|
false,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
|
@@ -13,6 +13,7 @@ import (
|
|||||||
"github.com/cnotch/ipchub/av/codec/aac"
|
"github.com/cnotch/ipchub/av/codec/aac"
|
||||||
"github.com/cnotch/ipchub/av/codec/h264"
|
"github.com/cnotch/ipchub/av/codec/h264"
|
||||||
"github.com/cnotch/ipchub/av/codec/hevc"
|
"github.com/cnotch/ipchub/av/codec/hevc"
|
||||||
|
"github.com/cnotch/ipchub/utils"
|
||||||
"github.com/cnotch/ipchub/utils/scan"
|
"github.com/cnotch/ipchub/utils/scan"
|
||||||
"github.com/pixelbender/go-sdp/sdp"
|
"github.com/pixelbender/go-sdp/sdp"
|
||||||
)
|
)
|
||||||
@@ -147,13 +148,13 @@ func parseH264SpsPps(s string, video *codec.VideoMeta) {
|
|||||||
sps, err := base64.StdEncoding.DecodeString(spsStr)
|
sps, err := base64.StdEncoding.DecodeString(spsStr)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
// video.SetParameterSet(h264.ParameterSetSps, sps)
|
// video.SetParameterSet(h264.ParameterSetSps, sps)
|
||||||
video.Sps = sps
|
video.Sps = utils.RemoveNaluSeparator(sps)
|
||||||
}
|
}
|
||||||
|
|
||||||
pps, err := base64.StdEncoding.DecodeString(ppsStr)
|
pps, err := base64.StdEncoding.DecodeString(ppsStr)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
// video.SetParameterSet(h264.ParameterSetPps, pps)
|
// video.SetParameterSet(h264.ParameterSetPps, pps)
|
||||||
video.Pps = pps
|
video.Pps = utils.RemoveNaluSeparator(pps)
|
||||||
}
|
}
|
||||||
|
|
||||||
_ = h264.MetadataIsReady(video)
|
_ = h264.MetadataIsReady(video)
|
||||||
@@ -167,22 +168,20 @@ func parseH265VpsSpsPps(s string, video *codec.VideoMeta) {
|
|||||||
advance, token, continueScan = scan.Semicolon.Scan(advance)
|
advance, token, continueScan = scan.Semicolon.Scan(advance)
|
||||||
name, value, ok := scan.EqualPair.Scan(token)
|
name, value, ok := scan.EqualPair.Scan(token)
|
||||||
if ok {
|
if ok {
|
||||||
var ps *[]byte
|
var ps []byte
|
||||||
var err error
|
var err error
|
||||||
|
if ps, err = base64.StdEncoding.DecodeString(value); err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
ps = utils.RemoveNaluSeparator(ps)
|
||||||
|
|
||||||
switch name {
|
switch name {
|
||||||
case "sprop-vps":
|
case "sprop-vps":
|
||||||
ps = &video.Vps
|
video.Vps = ps
|
||||||
case "sprop-sps":
|
case "sprop-sps":
|
||||||
ps = &video.Sps
|
video.Sps = ps
|
||||||
case "sprop-pps":
|
case "sprop-pps":
|
||||||
ps = &video.Pps
|
video.Pps = ps
|
||||||
}
|
|
||||||
if ps == nil {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
if *ps, err = base64.StdEncoding.DecodeString(value); err != nil {
|
|
||||||
return
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -4,9 +4,12 @@
|
|||||||
|
|
||||||
package utils
|
package utils
|
||||||
|
|
||||||
|
import "bytes"
|
||||||
|
|
||||||
// RemoveH264or5EmulationBytes A general routine for making a copy of a (H.264 or H.265) NAL unit, removing 'emulation' bytes from the copy
|
// RemoveH264or5EmulationBytes A general routine for making a copy of a (H.264 or H.265) NAL unit, removing 'emulation' bytes from the copy
|
||||||
// copy from live555
|
// copy from live555
|
||||||
func RemoveH264or5EmulationBytes(from []byte) []byte {
|
func RemoveH264or5EmulationBytes(from []byte) []byte {
|
||||||
|
from = RemoveNaluSeparator(from)
|
||||||
to := make([]byte, len(from))
|
to := make([]byte, len(from))
|
||||||
toMaxSize := len(to)
|
toMaxSize := len(to)
|
||||||
fromSize := len(from)
|
fromSize := len(from)
|
||||||
@@ -35,3 +38,14 @@ func RemoveH264or5EmulationBytes(from []byte) []byte {
|
|||||||
return to[:toSize]
|
return to[:toSize]
|
||||||
// return bytes.Replace(from, []byte{0, 0, 3}, []byte{0, 0}, -1)
|
// return bytes.Replace(from, []byte{0, 0, 3}, []byte{0, 0}, -1)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 移除 NALU 分隔符 0x00000001 或 0x000001
|
||||||
|
func RemoveNaluSeparator(nalu []byte) []byte {
|
||||||
|
if bytes.HasPrefix(nalu, []byte{0x0, 0x0, 0x0, 0x1}) {
|
||||||
|
return nalu[4:]
|
||||||
|
}
|
||||||
|
if bytes.HasPrefix(nalu, []byte{0x0, 0x0, 0x1}) {
|
||||||
|
return nalu[3:]
|
||||||
|
}
|
||||||
|
return nalu
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user