From 116764e6c318ff265ecd290a649d090e9267f08a Mon Sep 17 00:00:00 2001 From: nareix Date: Fri, 1 Jul 2016 18:02:43 +0800 Subject: [PATCH] add CheckNALUsType() --- h264parser/parser.go | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/h264parser/parser.go b/h264parser/parser.go index fd30e7c..cfceb21 100644 --- a/h264parser/parser.go +++ b/h264parser/parser.go @@ -215,6 +215,25 @@ func WalkNALUsAVCC(nalus [][]byte, write func([]byte)) { } } +func CheckNALUsType(b []byte) int { + if len(b) < 4 { + return NALU_RAW + } + + val3 := bits.GetUIntBE(b, 24) + val4 := bits.GetUIntBE(b, 32) + + if val4+4 == uint(len(b)) { + return NALU_AVCC + } + + if val4 == 1 || val3 == 1 { + return NALU_ANNEXB + } + + return NALU_RAW +} + const ( NALU_RAW = iota NALU_AVCC