mirror of
https://github.com/cnotch/ipchub.git
synced 2025-09-26 19:41:18 +08:00
fixed bug: sps start with 0x000001 or 0x00000001
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
Reference in New Issue
Block a user