fixed bug: sps start with 0x000001 or 0x00000001

This commit is contained in:
cnotch
2024-11-27 10:12:10 +08:00
parent 1c57f1bec4
commit d0bf5dc46d
5 changed files with 47 additions and 13 deletions

View File

@@ -4,9 +4,12 @@
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
// copy from live555
func RemoveH264or5EmulationBytes(from []byte) []byte {
from = RemoveNaluSeparator(from)
to := make([]byte, len(from))
toMaxSize := len(to)
fromSize := len(from)
@@ -35,3 +38,14 @@ func RemoveH264or5EmulationBytes(from []byte) []byte {
return to[:toSize]
// 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
}