h265: fix DTS extractor regression after #245 (#247)

IDR frames which are also B-frames are supported again.
This commit is contained in:
Alessandro Ros
2025-09-18 10:34:04 +02:00
committed by GitHub
parent e1eba3d81e
commit 3882df8df1
2 changed files with 98 additions and 17 deletions

View File

@@ -156,6 +156,7 @@ func (d *DTSExtractor) extractInner(au [][]byte, pts int64) (int64, error) {
for _, nalu := range au {
typ := NALUType((nalu[0] >> 1) & 0b111111)
switch typ {
case NALUType_SPS_NUT:
if !bytes.Equal(d.sps, nalu) {
@@ -231,13 +232,27 @@ func (d *DTSExtractor) extractInner(au [][]byte, pts int64) (int64, error) {
if d.pause > 0 {
d.pause--
if !d.prevDTSFilled {
return pts, nil
var timeDiff int64
if d.spsp.VUI != nil && d.spsp.VUI.TimingInfo != nil && d.spsp.VUI.TimingInfo.TimeScale != 0 {
timeDiff = int64(ptsDTSDiff) * 90000 *
int64(d.spsp.VUI.TimingInfo.NumUnitsInTick) / int64(d.spsp.VUI.TimingInfo.TimeScale)
} else {
timeDiff = 9000
}
return pts - timeDiff, nil
}
return d.prevDTS + 90, nil
}
if !d.prevDTSFilled {
return pts, nil
var timeDiff int64
if d.spsp.VUI != nil && d.spsp.VUI.TimingInfo != nil && d.spsp.VUI.TimingInfo.TimeScale != 0 {
timeDiff = int64(ptsDTSDiff) * 90000 *
int64(d.spsp.VUI.TimingInfo.NumUnitsInTick) / int64(d.spsp.VUI.TimingInfo.TimeScale)
} else {
timeDiff = 9000
}
return pts - timeDiff, nil
}
return d.prevDTS + (pts-d.prevDTS)/(int64(ptsDTSDiff)+1), nil

View File

@@ -45,7 +45,7 @@ var casesDTSExtractor = []struct {
},
},
0,
0,
-6000,
},
{
[][]byte{{ // TRAIL_R
@@ -54,7 +54,7 @@ var casesDTSExtractor = []struct {
0x54, 0x57, 0x4e, 0x0a,
}},
9000,
90,
-5910,
},
{
[][]byte{{ // TRAIL_R
@@ -63,7 +63,7 @@ var casesDTSExtractor = []struct {
0x26, 0x5f, 0x10, 0x9c,
}},
5999,
2059,
-1941,
},
{
[][]byte{{ // TRAIL_N
@@ -132,7 +132,7 @@ var casesDTSExtractor = []struct {
},
},
100,
100,
-4400,
},
{
[][]byte{
@@ -143,7 +143,7 @@ var casesDTSExtractor = []struct {
},
},
6130,
3115,
865,
},
{
[][]byte{
@@ -154,7 +154,7 @@ var casesDTSExtractor = []struct {
},
},
9100,
6107,
4982,
},
},
},
@@ -199,7 +199,7 @@ var casesDTSExtractor = []struct {
},
},
182999,
182999,
179999,
},
{
[][]byte{
@@ -217,7 +217,7 @@ var casesDTSExtractor = []struct {
},
},
188999,
183089,
180089,
},
{
[][]byte{
@@ -235,7 +235,7 @@ var casesDTSExtractor = []struct {
},
},
185999,
184059,
182059,
},
{
[][]byte{
@@ -293,7 +293,7 @@ var casesDTSExtractor = []struct {
},
},
0,
0,
-9000,
},
{
[][]byte{
@@ -313,7 +313,7 @@ var casesDTSExtractor = []struct {
},
},
12000,
90,
-8910,
},
{
[][]byte{
@@ -333,7 +333,7 @@ var casesDTSExtractor = []struct {
},
},
6000,
2060,
-3940,
},
{
[][]byte{
@@ -429,7 +429,7 @@ var casesDTSExtractor = []struct {
},
},
0,
0,
-6000,
},
{
[][]byte{
@@ -460,7 +460,7 @@ var casesDTSExtractor = []struct {
},
},
15000,
90,
-5910,
},
{
[][]byte{
@@ -475,7 +475,7 @@ var casesDTSExtractor = []struct {
},
},
9000,
2317,
-2183,
},
{
[][]byte{
@@ -494,6 +494,72 @@ var casesDTSExtractor = []struct {
},
},
},
{
"b-frame IDR",
[]sequenceSample{
{
[][]byte{
{
0x40, 0x01, 0x0c, 0x01, 0xff, 0xff, 0x01, 0x60,
0x00, 0x00, 0x03, 0x00, 0x90, 0x00, 0x00, 0x03,
0x00, 0x00, 0x03, 0x00, 0x78, 0x95, 0x98, 0x09,
},
{
0x42, 0x01, 0x01, 0x01, 0x60, 0x00, 0x00, 0x03,
0x00, 0x90, 0x00, 0x00, 0x03, 0x00, 0x00, 0x03,
0x00, 0x78, 0xa0, 0x03, 0xc0, 0x80, 0x32, 0x16,
0x59, 0x59, 0xa4, 0x93, 0x2b, 0xc0, 0x5a, 0x80,
0x80, 0x80, 0x82, 0x00, 0x00, 0x07, 0xd2, 0x00,
0x00, 0xbb, 0x80, 0x10,
},
{
0x44, 0x01, 0xc1, 0x72, 0xb4, 0x62, 0x40,
},
{
0x2a, 0x01, 0xae, 0x44, 0x59, 0x48, 0xc9, 0xd4,
0x68, 0xd1, 0x64, 0x7c, 0x76, 0x77, 0xce, 0x07,
0x54, 0xca, 0x8f, 0x8d, 0x90, 0x33, 0x64, 0x52,
0x7c, 0x48, 0x16, 0xc0, 0x9c, 0x80, 0xf8, 0x81,
0x5b, 0xff, 0xf8, 0x76, 0x7c, 0x92, 0xd6, 0xb7,
0xa8, 0x55, 0x9c, 0x20, 0xc0, 0x9b, 0x30, 0x11,
0xdb, 0x80,
},
},
2466180,
2443658,
},
{
[][]byte{
{
0x12, 0x01, 0xf1, 0xe2, 0x27, 0x52, 0xd7, 0xdc,
0x21, 0xa3, 0x45, 0x03, 0x0c, 0x14, 0x30, 0x41,
0x16, 0xe1, 0xa9, 0x46, 0x12, 0x06, 0xc1, 0xe0,
0x14, 0x03, 0xc0, 0x92, 0x00, 0x8c, 0xb0, 0x66,
0xc2, 0x1c, 0xf7, 0x66, 0xad, 0xf4, 0xcb, 0x6a,
0x81, 0x90, 0xcc, 0xe9, 0xac, 0xc8, 0xec, 0x8d,
0x3f, 0x30,
},
},
2458710,
2443748,
},
{
[][]byte{
{
0x10, 0x01, 0xf1, 0xa6, 0xf5, 0x55, 0xf4, 0x89,
0x04, 0x06, 0x89, 0x0e, 0xb7, 0xff, 0xa5, 0x33,
0xa8, 0x5c, 0xee, 0x18, 0x0b, 0x06, 0xc1, 0x20,
0x78, 0x91, 0x00, 0xce, 0xc0, 0xd7, 0x1c, 0x8d,
0x93, 0x89, 0x2c, 0xb3, 0x03, 0xe8, 0xd1, 0xc3,
0x4c, 0xe2, 0x9c, 0xee, 0xa9, 0xc2, 0x57, 0xc3,
0x1c, 0x68,
},
},
2451240,
2451240,
},
},
},
}
func TestDTSExtractor(t *testing.T) {