Skip to content

Commit

Permalink
Feat/add picture type for AVC (#13)
Browse files Browse the repository at this point in the history
* feat: add img type for AVC
  • Loading branch information
Wkkkkk authored Jan 23, 2024
1 parent fcd7f90 commit f023955
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 33 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Added

- Print image type (I, P, B) for AVC streams
- Calculate GoP duration based on RAI-marker or IDR distance
- Calculate frame-rate based on DTS/PTS and print out in JSON format
- Enable NALU/SEI printing by option
Expand Down
10 changes: 8 additions & 2 deletions internal/avc/avc.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,14 @@ func ParseAVCPES(jp *internal.JsonPrinter, d *astits.DemuxerData, ps *AvcPS, o i
}
}
seiMsg = strings.Join(seiTexts, ", ")
case avc.NALU_IDR:
ps.Statistics.IDRPTS = append(ps.Statistics.IDRPTS, pts.Base)
case avc.NALU_IDR, avc.NALU_NON_IDR:
if naluType == avc.NALU_IDR {
ps.Statistics.IDRPTS = append(ps.Statistics.IDRPTS, pts.Base)
}
sliceType, err := avc.GetSliceTypeFromNALU(nalu)
if err == nil {
nfd.ImgType = fmt.Sprintf("[%s]", sliceType)
}
}
nfd.NALUS = append(nfd.NALUS, internal.NaluData{
Type: naluType.String(),
Expand Down
52 changes: 26 additions & 26 deletions internal/avc/testdata/golden_bbb_1s.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,33 @@
{"pid":257,"codec":"AAC","type":"audio"}
{"pid":256,"parameterSet":"SPS","nr":0,"hex":"6764001facd9405005bb011000000300100000030300f1831960","length":26}
{"pid":256,"parameterSet":"PPS","nr":0,"hex":"68ebecb22c","length":5}
{"pid":256,"rai":true,"pts":133500,"dts":126000,"nalus":[{"type":"AUD_9","len":2},{"type":"SEI_6","len":701},{"type":"SPS_7","len":26},{"type":"PPS_8","len":5},{"type":"IDR_5","len":209}]}
{"pid":256,"rai":false,"pts":144750,"dts":129750,"nalus":[{"type":"AUD_9","len":2},{"type":"NonIDR_1","len":34}]}
{"pid":256,"rai":false,"pts":137250,"dts":133500,"nalus":[{"type":"AUD_9","len":2},{"type":"NonIDR_1","len":32}]}
{"pid":256,"rai":false,"pts":141000,"dts":137250,"nalus":[{"type":"AUD_9","len":2},{"type":"NonIDR_1","len":32}]}
{"pid":256,"rai":false,"pts":148500,"dts":141000,"nalus":[{"type":"AUD_9","len":2},{"type":"NonIDR_1","len":48}]}
{"pid":256,"rai":false,"pts":152250,"dts":144750,"nalus":[{"type":"AUD_9","len":2},{"type":"NonIDR_1","len":145}]}
{"pid":256,"rai":false,"pts":156000,"dts":148500,"nalus":[{"type":"AUD_9","len":2},{"type":"NonIDR_1","len":204}]}
{"pid":256,"rai":false,"pts":163500,"dts":152250,"nalus":[{"type":"AUD_9","len":2},{"type":"NonIDR_1","len":143}]}
{"pid":256,"rai":false,"pts":159750,"dts":156000,"nalus":[{"type":"AUD_9","len":2},{"type":"NonIDR_1","len":150}]}
{"pid":256,"rai":false,"pts":167250,"dts":159750,"nalus":[{"type":"AUD_9","len":2},{"type":"NonIDR_1","len":315}]}
{"pid":256,"rai":false,"pts":171000,"dts":163500,"nalus":[{"type":"AUD_9","len":2},{"type":"NonIDR_1","len":679}]}
{"pid":256,"rai":true,"pts":133500,"dts":126000,"imgType":"[I]","nalus":[{"type":"AUD_9","len":2},{"type":"SEI_6","len":701},{"type":"SPS_7","len":26},{"type":"PPS_8","len":5},{"type":"IDR_5","len":209}]}
{"pid":256,"rai":false,"pts":144750,"dts":129750,"imgType":"[P]","nalus":[{"type":"AUD_9","len":2},{"type":"NonIDR_1","len":34}]}
{"pid":256,"rai":false,"pts":137250,"dts":133500,"imgType":"[B]","nalus":[{"type":"AUD_9","len":2},{"type":"NonIDR_1","len":32}]}
{"pid":256,"rai":false,"pts":141000,"dts":137250,"imgType":"[B]","nalus":[{"type":"AUD_9","len":2},{"type":"NonIDR_1","len":32}]}
{"pid":256,"rai":false,"pts":148500,"dts":141000,"imgType":"[P]","nalus":[{"type":"AUD_9","len":2},{"type":"NonIDR_1","len":48}]}
{"pid":256,"rai":false,"pts":152250,"dts":144750,"imgType":"[P]","nalus":[{"type":"AUD_9","len":2},{"type":"NonIDR_1","len":145}]}
{"pid":256,"rai":false,"pts":156000,"dts":148500,"imgType":"[P]","nalus":[{"type":"AUD_9","len":2},{"type":"NonIDR_1","len":204}]}
{"pid":256,"rai":false,"pts":163500,"dts":152250,"imgType":"[P]","nalus":[{"type":"AUD_9","len":2},{"type":"NonIDR_1","len":143}]}
{"pid":256,"rai":false,"pts":159750,"dts":156000,"imgType":"[B]","nalus":[{"type":"AUD_9","len":2},{"type":"NonIDR_1","len":150}]}
{"pid":256,"rai":false,"pts":167250,"dts":159750,"imgType":"[P]","nalus":[{"type":"AUD_9","len":2},{"type":"NonIDR_1","len":315}]}
{"pid":256,"rai":false,"pts":171000,"dts":163500,"imgType":"[P]","nalus":[{"type":"AUD_9","len":2},{"type":"NonIDR_1","len":679}]}
{"SDT":[{"serviceId":1,"descriptors":[{"serviceName":"ts-info","providerName":"Eyevinn Technology"}]}]}
{"pid":256,"rai":false,"pts":174750,"dts":167250,"nalus":[{"type":"AUD_9","len":2},{"type":"NonIDR_1","len":1718}]}
{"pid":256,"rai":false,"pts":182250,"dts":171000,"nalus":[{"type":"AUD_9","len":2},{"type":"NonIDR_1","len":918}]}
{"pid":256,"rai":false,"pts":178500,"dts":174750,"nalus":[{"type":"AUD_9","len":2},{"type":"NonIDR_1","len":506}]}
{"pid":256,"rai":false,"pts":189750,"dts":178500,"nalus":[{"type":"AUD_9","len":2},{"type":"NonIDR_1","len":1342}]}
{"pid":256,"rai":false,"pts":186000,"dts":182250,"nalus":[{"type":"AUD_9","len":2},{"type":"NonIDR_1","len":704}]}
{"pid":256,"rai":false,"pts":201000,"dts":186000,"nalus":[{"type":"AUD_9","len":2},{"type":"NonIDR_1","len":6516}]}
{"pid":256,"rai":false,"pts":193500,"dts":189750,"nalus":[{"type":"AUD_9","len":2},{"type":"NonIDR_1","len":1073}]}
{"pid":256,"rai":false,"pts":197250,"dts":193500,"nalus":[{"type":"AUD_9","len":2},{"type":"NonIDR_1","len":1739}]}
{"pid":256,"rai":false,"pts":204750,"dts":197250,"nalus":[{"type":"AUD_9","len":2},{"type":"NonIDR_1","len":12196}]}
{"pid":256,"rai":false,"pts":219750,"dts":201000,"nalus":[{"type":"AUD_9","len":2},{"type":"NonIDR_1","len":18657}]}
{"pid":256,"rai":false,"pts":212250,"dts":204750,"nalus":[{"type":"AUD_9","len":2},{"type":"NonIDR_1","len":7371}]}
{"pid":256,"rai":false,"pts":208500,"dts":208500,"nalus":[{"type":"AUD_9","len":2},{"type":"NonIDR_1","len":3435}]}
{"pid":256,"rai":false,"pts":216000,"dts":212250,"nalus":[{"type":"AUD_9","len":2},{"type":"NonIDR_1","len":4061}]}
{"pid":256,"rai":false,"pts":174750,"dts":167250,"imgType":"[I]","nalus":[{"type":"AUD_9","len":2},{"type":"NonIDR_1","len":1718}]}
{"pid":256,"rai":false,"pts":182250,"dts":171000,"imgType":"[P]","nalus":[{"type":"AUD_9","len":2},{"type":"NonIDR_1","len":918}]}
{"pid":256,"rai":false,"pts":178500,"dts":174750,"imgType":"[B]","nalus":[{"type":"AUD_9","len":2},{"type":"NonIDR_1","len":506}]}
{"pid":256,"rai":false,"pts":189750,"dts":178500,"imgType":"[P]","nalus":[{"type":"AUD_9","len":2},{"type":"NonIDR_1","len":1342}]}
{"pid":256,"rai":false,"pts":186000,"dts":182250,"imgType":"[B]","nalus":[{"type":"AUD_9","len":2},{"type":"NonIDR_1","len":704}]}
{"pid":256,"rai":false,"pts":201000,"dts":186000,"imgType":"[P]","nalus":[{"type":"AUD_9","len":2},{"type":"NonIDR_1","len":6516}]}
{"pid":256,"rai":false,"pts":193500,"dts":189750,"imgType":"[B]","nalus":[{"type":"AUD_9","len":2},{"type":"NonIDR_1","len":1073}]}
{"pid":256,"rai":false,"pts":197250,"dts":193500,"imgType":"[B]","nalus":[{"type":"AUD_9","len":2},{"type":"NonIDR_1","len":1739}]}
{"pid":256,"rai":false,"pts":204750,"dts":197250,"imgType":"[P]","nalus":[{"type":"AUD_9","len":2},{"type":"NonIDR_1","len":12196}]}
{"pid":256,"rai":false,"pts":219750,"dts":201000,"imgType":"[P]","nalus":[{"type":"AUD_9","len":2},{"type":"NonIDR_1","len":18657}]}
{"pid":256,"rai":false,"pts":212250,"dts":204750,"imgType":"[B]","nalus":[{"type":"AUD_9","len":2},{"type":"NonIDR_1","len":7371}]}
{"pid":256,"rai":false,"pts":208500,"dts":208500,"imgType":"[B]","nalus":[{"type":"AUD_9","len":2},{"type":"NonIDR_1","len":3435}]}
{"pid":256,"rai":false,"pts":216000,"dts":212250,"imgType":"[B]","nalus":[{"type":"AUD_9","len":2},{"type":"NonIDR_1","len":4061}]}
{"pid":256,"parameterSet":"SPS","nr":0,"hex":"6764001facd9405005bb011000000300100000030300f1831960","length":26}
{"pid":256,"parameterSet":"PPS","nr":0,"hex":"68ebecb22c","length":5}
{"pid":256,"rai":true,"pts":223500,"dts":216000,"nalus":[{"type":"AUD_9","len":2},{"type":"SPS_7","len":26},{"type":"PPS_8","len":5},{"type":"IDR_5","len":12975}]}
{"pid":256,"rai":false,"pts":234750,"dts":219750,"nalus":[{"type":"AUD_9","len":2},{"type":"NonIDR_1","len":24332}]}
{"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}]}
{"pid":256,"rai":false,"pts":234750,"dts":219750,"imgType":"[P]","nalus":[{"type":"AUD_9","len":2},{"type":"NonIDR_1","len":24332}]}
{"streamType":"AVC","pid":256,"frameRate":24,"RAIGoPDuration":1,"IDRGoPDuration":1}
2 changes: 2 additions & 0 deletions internal/avc/testdata/golden_bbb_1s_indented.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"rai": true,
"pts": 133500,
"dts": 126000,
"imgType": "[I]",
"nalus": [
{
"type": "AUD_9",
Expand Down Expand Up @@ -55,6 +56,7 @@
"rai": false,
"pts": 144750,
"dts": 129750,
"imgType": "[P]",
"nalus": [
{
"type": "AUD_9",
Expand Down
11 changes: 6 additions & 5 deletions internal/nalu.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package internal

type NaluFrameData struct {
PID uint16 `json:"pid"`
RAI bool `json:"rai"`
PTS int64 `json:"pts"`
DTS int64 `json:"dts,omitempty"`
NALUS []NaluData `json:"nalus,omitempty"`
PID uint16 `json:"pid"`
RAI bool `json:"rai"`
PTS int64 `json:"pts"`
DTS int64 `json:"dts,omitempty"`
ImgType string `json:"imgType,omitempty"`
NALUS []NaluData `json:"nalus,omitempty"`
}

type NaluData struct {
Expand Down

0 comments on commit f023955

Please sign in to comment.