Skip to content

Commit 7b8c8b6

Browse files
committed
feat: report POC and slice QP per picture in mp2ts-nallister
1 parent e612fb7 commit 7b8c8b6

8 files changed

Lines changed: 109 additions & 65 deletions

File tree

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
### Added
11+
12+
- mp2ts-nallister now prints per-picture POC (`pic_order_cnt_lsb`) and slice QP (initial SliceQPY) for AVC and HEVC, parsed from the first slice (segment) of each picture
13+
1014
### Changed
1115

1216
- mp2ts-pslister now always shows verbose parameter set info (removed `-ps` flag)

internal/avc.go

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -152,9 +152,29 @@ func ParseAVCPES(jp *JsonPrinter, d *astits.DemuxerData, ps *AvcPS, o Options) (
152152
if naluType == avc.NALU_IDR {
153153
ps.Statistics.IDRPTS = append(ps.Statistics.IDRPTS, pts.Base)
154154
}
155-
sliceType, err := avc.GetSliceTypeFromNALU(nalu)
156-
if err == nil {
157-
nfd.ImgType = fmt.Sprintf("[%s]", sliceType)
155+
if ps.hasPS() {
156+
if sh, err := avc.ParseSliceHeader(nalu, ps.spss, ps.ppss); err == nil {
157+
sliceType := sh.SliceType
158+
if sliceType >= 5 {
159+
sliceType -= 5
160+
}
161+
if nfd.ImgType == "" {
162+
nfd.ImgType = fmt.Sprintf("[%s]", sliceType)
163+
}
164+
if sh.FirstMBInSlice == 0 && nfd.POC == nil {
165+
pps := ps.ppss[sh.PicParamID]
166+
poc := int(sh.PicOrderCntLsb)
167+
qp := 26 + pps.PicInitQpMinus26 + int(sh.SliceQPDelta)
168+
nfd.POC = &poc
169+
nfd.QP = &qp
170+
}
171+
} else if sliceType, err := avc.GetSliceTypeFromNALU(nalu); err == nil {
172+
nfd.ImgType = fmt.Sprintf("[%s]", sliceType)
173+
}
174+
} else {
175+
if sliceType, err := avc.GetSliceTypeFromNALU(nalu); err == nil {
176+
nfd.ImgType = fmt.Sprintf("[%s]", sliceType)
177+
}
158178
}
159179
}
160180
nfd.NALUS = append(nfd.NALUS, NaluData{

internal/hevc.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,17 @@ func ParseHEVCPES(jp *JsonPrinter, d *astits.DemuxerData, ps *HevcPS, o Options)
148148
if hevc.IsVideoNaluType(naluType) {
149149
sliceHeader, err := hevc.ParseSliceHeader(nalu, ps.spss, ps.ppss)
150150
if err == nil {
151-
nfd.ImgType = fmt.Sprintf("[%s]", sliceHeader.SliceType)
151+
if nfd.ImgType == "" {
152+
nfd.ImgType = fmt.Sprintf("[%s]", sliceHeader.SliceType)
153+
}
154+
if sliceHeader.FirstSliceSegmentInPicFlag && nfd.POC == nil {
155+
if pps, ok := ps.ppss[sliceHeader.PicParameterSetId]; ok {
156+
poc := int(sliceHeader.PicOrderCntLsb)
157+
qp := 26 + int(pps.InitQpMinus26) + sliceHeader.QpDelta
158+
nfd.POC = &poc
159+
nfd.QP = &qp
160+
}
161+
}
152162
}
153163
}
154164
nfd.NALUS = append(nfd.NALUS, NaluData{

internal/nalu.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ type NaluFrameData struct {
66
PTS int64 `json:"pts"`
77
DTS int64 `json:"dts,omitempty"`
88
ImgType string `json:"imgType,omitempty"`
9+
POC *int `json:"poc,omitempty"`
10+
QP *int `json:"qp,omitempty"`
911
NALUS []NaluData `json:"nalus,omitempty"`
1012
}
1113

internal/testdata/golden_bbb_1s.txt

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2,31 +2,31 @@
22
{"pid":257,"codec":"AAC","type":"audio"}
33
{"pid":256,"parameterSet":"SPS","nr":0,"hex":"6764001facd9405005bb011000000300100000030300f1831960","length":26}
44
{"pid":256,"parameterSet":"PPS","nr":0,"hex":"68ebecb22c","length":5}
5-
{"pid":256,"rai":true,"pts":133500,"dts":126000,"imgType":"[I]","nalus":[{"type":"AUD_9","len":2},{"type":"SEI_6","len":701,"data":[{"msg":"SEIUserDataUnregisteredType (5)","payload":{"UUID":"3EXpvebZSLeWLNgg2SPu7w=="}}]},{"type":"SPS_7","len":26},{"type":"PPS_8","len":5},{"type":"IDR_5","len":209}]}
6-
{"pid":256,"rai":false,"pts":144750,"dts":129750,"imgType":"[P]","nalus":[{"type":"AUD_9","len":2},{"type":"NonIDR_1","len":34}]}
7-
{"pid":256,"rai":false,"pts":137250,"dts":133500,"imgType":"[B]","nalus":[{"type":"AUD_9","len":2},{"type":"NonIDR_1","len":32}]}
8-
{"pid":256,"rai":false,"pts":141000,"dts":137250,"imgType":"[B]","nalus":[{"type":"AUD_9","len":2},{"type":"NonIDR_1","len":32}]}
9-
{"pid":256,"rai":false,"pts":148500,"dts":141000,"imgType":"[P]","nalus":[{"type":"AUD_9","len":2},{"type":"NonIDR_1","len":48}]}
10-
{"pid":256,"rai":false,"pts":152250,"dts":144750,"imgType":"[P]","nalus":[{"type":"AUD_9","len":2},{"type":"NonIDR_1","len":145}]}
11-
{"pid":256,"rai":false,"pts":156000,"dts":148500,"imgType":"[P]","nalus":[{"type":"AUD_9","len":2},{"type":"NonIDR_1","len":204}]}
12-
{"pid":256,"rai":false,"pts":163500,"dts":152250,"imgType":"[P]","nalus":[{"type":"AUD_9","len":2},{"type":"NonIDR_1","len":143}]}
13-
{"pid":256,"rai":false,"pts":159750,"dts":156000,"imgType":"[B]","nalus":[{"type":"AUD_9","len":2},{"type":"NonIDR_1","len":150}]}
14-
{"pid":256,"rai":false,"pts":167250,"dts":159750,"imgType":"[P]","nalus":[{"type":"AUD_9","len":2},{"type":"NonIDR_1","len":315}]}
15-
{"pid":256,"rai":false,"pts":171000,"dts":163500,"imgType":"[P]","nalus":[{"type":"AUD_9","len":2},{"type":"NonIDR_1","len":679}]}
5+
{"pid":256,"rai":true,"pts":133500,"dts":126000,"imgType":"[I]","poc":0,"qp":20,"nalus":[{"type":"AUD_9","len":2},{"type":"SEI_6","len":701,"data":[{"msg":"SEIUserDataUnregisteredType (5)","payload":{"UUID":"3EXpvebZSLeWLNgg2SPu7w=="}}]},{"type":"SPS_7","len":26},{"type":"PPS_8","len":5},{"type":"IDR_5","len":209}]}
6+
{"pid":256,"rai":false,"pts":144750,"dts":129750,"imgType":"[P]","poc":6,"qp":23,"nalus":[{"type":"AUD_9","len":2},{"type":"NonIDR_1","len":34}]}
7+
{"pid":256,"rai":false,"pts":137250,"dts":133500,"imgType":"[B]","poc":2,"qp":22,"nalus":[{"type":"AUD_9","len":2},{"type":"NonIDR_1","len":32}]}
8+
{"pid":256,"rai":false,"pts":141000,"dts":137250,"imgType":"[B]","poc":4,"qp":23,"nalus":[{"type":"AUD_9","len":2},{"type":"NonIDR_1","len":32}]}
9+
{"pid":256,"rai":false,"pts":148500,"dts":141000,"imgType":"[P]","poc":8,"qp":22,"nalus":[{"type":"AUD_9","len":2},{"type":"NonIDR_1","len":48}]}
10+
{"pid":256,"rai":false,"pts":152250,"dts":144750,"imgType":"[P]","poc":10,"qp":21,"nalus":[{"type":"AUD_9","len":2},{"type":"NonIDR_1","len":145}]}
11+
{"pid":256,"rai":false,"pts":156000,"dts":148500,"imgType":"[P]","poc":12,"qp":22,"nalus":[{"type":"AUD_9","len":2},{"type":"NonIDR_1","len":204}]}
12+
{"pid":256,"rai":false,"pts":163500,"dts":152250,"imgType":"[P]","poc":16,"qp":22,"nalus":[{"type":"AUD_9","len":2},{"type":"NonIDR_1","len":143}]}
13+
{"pid":256,"rai":false,"pts":159750,"dts":156000,"imgType":"[B]","poc":14,"qp":22,"nalus":[{"type":"AUD_9","len":2},{"type":"NonIDR_1","len":150}]}
14+
{"pid":256,"rai":false,"pts":167250,"dts":159750,"imgType":"[P]","poc":18,"qp":21,"nalus":[{"type":"AUD_9","len":2},{"type":"NonIDR_1","len":315}]}
15+
{"pid":256,"rai":false,"pts":171000,"dts":163500,"imgType":"[P]","poc":20,"qp":22,"nalus":[{"type":"AUD_9","len":2},{"type":"NonIDR_1","len":679}]}
1616
{"SDT":[{"serviceId":1,"descriptors":[{"serviceName":"ts-info","providerName":"Eyevinn Technology"}]}]}
17-
{"pid":256,"rai":false,"pts":174750,"dts":167250,"imgType":"[I]","nalus":[{"type":"AUD_9","len":2},{"type":"NonIDR_1","len":1718}]}
18-
{"pid":256,"rai":false,"pts":182250,"dts":171000,"imgType":"[P]","nalus":[{"type":"AUD_9","len":2},{"type":"NonIDR_1","len":918}]}
19-
{"pid":256,"rai":false,"pts":178500,"dts":174750,"imgType":"[B]","nalus":[{"type":"AUD_9","len":2},{"type":"NonIDR_1","len":506}]}
20-
{"pid":256,"rai":false,"pts":189750,"dts":178500,"imgType":"[P]","nalus":[{"type":"AUD_9","len":2},{"type":"NonIDR_1","len":1342}]}
21-
{"pid":256,"rai":false,"pts":186000,"dts":182250,"imgType":"[B]","nalus":[{"type":"AUD_9","len":2},{"type":"NonIDR_1","len":704}]}
22-
{"pid":256,"rai":false,"pts":201000,"dts":186000,"imgType":"[P]","nalus":[{"type":"AUD_9","len":2},{"type":"NonIDR_1","len":6516}]}
23-
{"pid":256,"rai":false,"pts":193500,"dts":189750,"imgType":"[B]","nalus":[{"type":"AUD_9","len":2},{"type":"NonIDR_1","len":1073}]}
24-
{"pid":256,"rai":false,"pts":197250,"dts":193500,"imgType":"[B]","nalus":[{"type":"AUD_9","len":2},{"type":"NonIDR_1","len":1739}]}
25-
{"pid":256,"rai":false,"pts":204750,"dts":197250,"imgType":"[P]","nalus":[{"type":"AUD_9","len":2},{"type":"NonIDR_1","len":12196}]}
26-
{"pid":256,"rai":false,"pts":219750,"dts":201000,"imgType":"[P]","nalus":[{"type":"AUD_9","len":2},{"type":"NonIDR_1","len":18657}]}
27-
{"pid":256,"rai":false,"pts":212250,"dts":204750,"imgType":"[B]","nalus":[{"type":"AUD_9","len":2},{"type":"NonIDR_1","len":7371}]}
28-
{"pid":256,"rai":false,"pts":208500,"dts":208500,"imgType":"[B]","nalus":[{"type":"AUD_9","len":2},{"type":"NonIDR_1","len":3435}]}
29-
{"pid":256,"rai":false,"pts":216000,"dts":212250,"imgType":"[B]","nalus":[{"type":"AUD_9","len":2},{"type":"NonIDR_1","len":4061}]}
30-
{"pid":256,"rai":true,"pts":223500,"dts":216000,"imgType":"[I]","nalus":[{"type":"AUD_9","len":2},{"type":"SPS_7","len":26},{"type":"PPS_8","len":5},{"type":"IDR_5","len":12975}]}
31-
{"pid":256,"rai":false,"pts":234750,"dts":219750,"imgType":"[P]","nalus":[{"type":"AUD_9","len":2},{"type":"NonIDR_1","len":24332}]}
17+
{"pid":256,"rai":false,"pts":174750,"dts":167250,"imgType":"[I]","poc":22,"qp":19,"nalus":[{"type":"AUD_9","len":2},{"type":"NonIDR_1","len":1718}]}
18+
{"pid":256,"rai":false,"pts":182250,"dts":171000,"imgType":"[P]","poc":26,"qp":21,"nalus":[{"type":"AUD_9","len":2},{"type":"NonIDR_1","len":918}]}
19+
{"pid":256,"rai":false,"pts":178500,"dts":174750,"imgType":"[B]","poc":24,"qp":21,"nalus":[{"type":"AUD_9","len":2},{"type":"NonIDR_1","len":506}]}
20+
{"pid":256,"rai":false,"pts":189750,"dts":178500,"imgType":"[P]","poc":30,"qp":21,"nalus":[{"type":"AUD_9","len":2},{"type":"NonIDR_1","len":1342}]}
21+
{"pid":256,"rai":false,"pts":186000,"dts":182250,"imgType":"[B]","poc":28,"qp":21,"nalus":[{"type":"AUD_9","len":2},{"type":"NonIDR_1","len":704}]}
22+
{"pid":256,"rai":false,"pts":201000,"dts":186000,"imgType":"[P]","poc":36,"qp":13,"nalus":[{"type":"AUD_9","len":2},{"type":"NonIDR_1","len":6516}]}
23+
{"pid":256,"rai":false,"pts":193500,"dts":189750,"imgType":"[B]","poc":32,"qp":18,"nalus":[{"type":"AUD_9","len":2},{"type":"NonIDR_1","len":1073}]}
24+
{"pid":256,"rai":false,"pts":197250,"dts":193500,"imgType":"[B]","poc":34,"qp":16,"nalus":[{"type":"AUD_9","len":2},{"type":"NonIDR_1","len":1739}]}
25+
{"pid":256,"rai":false,"pts":204750,"dts":197250,"imgType":"[P]","poc":38,"qp":4,"nalus":[{"type":"AUD_9","len":2},{"type":"NonIDR_1","len":12196}]}
26+
{"pid":256,"rai":false,"pts":219750,"dts":201000,"imgType":"[P]","poc":46,"qp":11,"nalus":[{"type":"AUD_9","len":2},{"type":"NonIDR_1","len":18657}]}
27+
{"pid":256,"rai":false,"pts":212250,"dts":204750,"imgType":"[B]","poc":42,"qp":6,"nalus":[{"type":"AUD_9","len":2},{"type":"NonIDR_1","len":7371}]}
28+
{"pid":256,"rai":false,"pts":208500,"dts":208500,"imgType":"[B]","poc":40,"qp":6,"nalus":[{"type":"AUD_9","len":2},{"type":"NonIDR_1","len":3435}]}
29+
{"pid":256,"rai":false,"pts":216000,"dts":212250,"imgType":"[B]","poc":44,"qp":11,"nalus":[{"type":"AUD_9","len":2},{"type":"NonIDR_1","len":4061}]}
30+
{"pid":256,"rai":true,"pts":223500,"dts":216000,"imgType":"[I]","poc":0,"qp":13,"nalus":[{"type":"AUD_9","len":2},{"type":"SPS_7","len":26},{"type":"PPS_8","len":5},{"type":"IDR_5","len":12975}]}
31+
{"pid":256,"rai":false,"pts":234750,"dts":219750,"imgType":"[P]","poc":6,"qp":4,"nalus":[{"type":"AUD_9","len":2},{"type":"NonIDR_1","len":24332}]}
3232
{"streamType":"AVC","pid":256,"frameRate":24,"RAIGoPDuration":1,"IDRGoPDuration":1}

internal/testdata/golden_bbb_1s_indented.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828
"pts": 133500,
2929
"dts": 126000,
3030
"imgType": "[I]",
31+
"poc": 0,
32+
"qp": 20,
3133
"nalus": [
3234
{
3335
"type": "AUD_9",
@@ -65,6 +67,8 @@
6567
"pts": 144750,
6668
"dts": 129750,
6769
"imgType": "[P]",
70+
"poc": 6,
71+
"qp": 23,
6872
"nalus": [
6973
{
7074
"type": "AUD_9",

0 commit comments

Comments
 (0)