Skip to content

Commit

Permalink
Fix keyframe data not showing in bitrate plot
Browse files Browse the repository at this point in the history
This was observed with newer ffprobe versions, apparently flags were
extended to include also corrupt flag. Added to ffprobe in this commit:
https://git.ffmpeg.org/gitweb/ffmpeg.git/commit/18cd65998bfe9651b1bd9496bba9f641c77920cd

Also, adding unittest to cover FrameStat's UnmarshalJSON() method.
  • Loading branch information
jurisevo committed Oct 16, 2023
1 parent 28e5996 commit f67d1f9
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 1 deletion.
2 changes: 1 addition & 1 deletion internal/analysis/plot.go
Original file line number Diff line number Diff line change
Expand Up @@ -616,7 +616,7 @@ func (f *FrameStat) UnmarshalJSON(data []byte) error {
}

switch ps.Flags {
case "K_":
case "K_", "K__":
f.KeyFrame = true
default:
f.KeyFrame = false
Expand Down
50 changes: 50 additions & 0 deletions internal/analysis/plot_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,3 +217,53 @@ func Test_getDuration(t *testing.T) {
})
}
}

func Test_FrameStat_UnmarshalJSON(t *testing.T) {
type testCase struct {
given []byte
want FrameStat
}

tests := map[string]testCase{
"2 flags keyframe": {
given: []byte(`{"pts_time": "0", "duration_time": "0.04", "size": "82949", "flags": "K_" }`),
want: FrameStat{
KeyFrame: true,
DurationTime: 0.04,
PtsTime: 0,
Size: 82949,
},
},
"3 flags keyframe": {
given: []byte(`{"pts_time": "0", "duration_time": "0.04", "size": "82949", "flags": "K__" }`),
want: FrameStat{
KeyFrame: true,
DurationTime: 0.04,
PtsTime: 0,
Size: 82949,
},
},
"3 flags": {
given: []byte(`{"pts_time": "1", "duration_time": "0.04", "size": "82949", "flags": "___" }`),
want: FrameStat{
KeyFrame: false,
DurationTime: 0.04,
PtsTime: 1,
Size: 82949,
},
},
}

run := func(t *testing.T, tc testCase) {
var fs FrameStat
err := fs.UnmarshalJSON(tc.given)
assert.NoError(t, err)
assert.Equal(t, tc.want, fs)
}

for name, tc := range tests {
t.Run(name, func(t *testing.T) {
run(t, tc)
})
}
}

0 comments on commit f67d1f9

Please sign in to comment.