[FFmpeg-devel] [PATCH] matroskadec: use the last block duration to fill in missing durations
Michael Niedermayer
michaelni at gmx.at
Sun Jul 7 23:07:35 CEST 2013
This isnt strictly correct, but improves timestamps over the current
code for several matroska files.
Fixes Ticket2508
Signed-off-by: Michael Niedermayer <michaelni at gmx.at>
---
libavformat/matroskadec.c | 21 ++++++++-
tests/ref/fate/mkv | 112 ++++++++++++++++++++++-----------------------
2 files changed, 76 insertions(+), 57 deletions(-)
diff --git a/libavformat/matroskadec.c b/libavformat/matroskadec.c
index a1aa0eb..f02724f 100644
--- a/libavformat/matroskadec.c
+++ b/libavformat/matroskadec.c
@@ -172,6 +172,10 @@ typedef struct {
int64_t end_timecode;
int ms_compat;
uint64_t max_block_additional_id;
+
+ int64_t last_block_timecode;
+ int64_t last_lace_duration;
+ int last_lace_count;
} MatroskaTrack;
typedef struct {
@@ -1956,9 +1960,9 @@ static int matroska_deliver_packet(MatroskaDemuxContext *matroska,
*/
static void matroska_clear_queue(MatroskaDemuxContext *matroska)
{
+ int n;
matroska->prev_pkt = NULL;
if (matroska->packets) {
- int n;
for (n = 0; n < matroska->num_packets; n++) {
av_free_packet(matroska->packets[n]);
av_free(matroska->packets[n]);
@@ -1966,6 +1970,11 @@ static void matroska_clear_queue(MatroskaDemuxContext *matroska)
av_freep(&matroska->packets);
matroska->num_packets = 0;
}
+
+ for (n = 0; n < matroska->tracks.nb_elem; n++) {
+ MatroskaTrack *track = matroska->tracks.elem;
+ track[n].last_lace_count = 0;
+ }
}
static int matroska_parse_laces(MatroskaDemuxContext *matroska, uint8_t **buf,
@@ -2418,6 +2427,16 @@ static int matroska_parse_block(MatroskaDemuxContext *matroska, uint8_t *data,
if (res)
goto end;
+ if ( track->last_lace_count>0
+ && timecode > track->last_block_timecode)
+ track->last_lace_duration = (timecode - track->last_block_timecode)*65536 / track->last_lace_count;
+ if (timecode != AV_NOPTS_VALUE) {
+ track->last_block_timecode = timecode;
+ track->last_lace_count = laces;
+ }
+
+ if (!block_duration)
+ block_duration = track->last_lace_duration * laces / 65536;
if (!block_duration)
block_duration = track->default_duration * laces / matroska->time_scale;
diff --git a/tests/ref/fate/mkv b/tests/ref/fate/mkv
index 78440b2..bda3cb1 100644
--- a/tests/ref/fate/mkv
+++ b/tests/ref/fate/mkv
@@ -17,26 +17,26 @@
1, 179, 179, 21, 501, 0x0538fa45
1, 200, 200, 21, 521, 0xc89f06d2
0, 209, 209, 0, 2114, 0xfceafb26, F=0x0
-1, 221, 221, 21, 646, 0x8d8d3599
-1, 242, 242, 22, 661, 0x222242de
+1, 221, 221, 22, 646, 0x8d8d3599
+1, 243, 243, 21, 661, 0x222242de
0, 250, 334, 0, 63420, 0x5ca6250f, F=0x0
1, 264, 264, 21, 609, 0xc0dc255c
-1, 285, 285, 21, 619, 0x9ac52dd1
+1, 285, 285, 22, 619, 0x9ac52dd1
0, 292, 292, 0, 16751, 0xf293ab46, F=0x0
0, 292, 417, 0, 22029, 0x3696462b, F=0x0
-1, 306, 306, 21, 574, 0xf6410d4d
-1, 327, 327, 22, 565, 0xfd561191
+1, 307, 307, 21, 574, 0xf6410d4d
+1, 328, 328, 22, 565, 0xfd561191
1, 350, 350, 21, 713, 0x48425147
1, 371, 371, 21, 537, 0x09bbf515
0, 375, 375, 0, 5044, 0xa0344ae6, F=0x0
-1, 392, 392, 21, 486, 0x7946e28c
-1, 413, 413, 22, 499, 0xa770f22a
+1, 392, 392, 22, 486, 0x7946e28c
+1, 414, 414, 21, 499, 0xa770f22a
0, 417, 500, 0, 25289, 0x46f9a219, F=0x0
1, 435, 435, 21, 506, 0x355ef81d
-1, 456, 456, 21, 474, 0x6d24e2c5
+1, 456, 456, 22, 474, 0x6d24e2c5
0, 459, 459, 0, 12871, 0x23e570c4, F=0x0
-1, 477, 477, 21, 494, 0x7d77e90f
-1, 498, 498, 22, 524, 0x6c82fdd2
+1, 478, 478, 21, 494, 0x7d77e90f
+1, 499, 499, 22, 524, 0x6c82fdd2
0, 500, 584, 0, 29580, 0xd051ad0c, F=0x0
1, 520, 520, 21, 482, 0xe625f255
1, 541, 541, 21, 533, 0xed00fd16
@@ -53,39 +53,39 @@
1, 691, 691, 21, 450, 0x1c58e44b
0, 709, 709, 0, 7093, 0x3ab77cce, F=0x0
1, 712, 712, 21, 487, 0x0e5feab7
-1, 733, 733, 21, 465, 0x984adca9
+1, 733, 733, 22, 465, 0x984adca9
0, 750, 834, 0, 23210, 0xa7851bbf, F=0x0
-1, 754, 754, 22, 479, 0x0960e535
+1, 755, 755, 21, 479, 0x0960e535
1, 776, 776, 21, 489, 0x2f3ffc02
0, 792, 792, 0, 16045, 0x33039eb5, F=0x0
-1, 797, 797, 21, 505, 0x541aff95
-1, 818, 818, 21, 485, 0xb7a5e7f8
+1, 797, 797, 22, 505, 0x541aff95
+1, 819, 819, 21, 485, 0xb7a5e7f8
0, 834, 917, 0, 24859, 0x317ea0f2, F=0x0
-1, 839, 839, 22, 537, 0xb0dd1072
+1, 840, 840, 22, 537, 0xb0dd1072
1, 862, 862, 21, 485, 0x6e9eee58
0, 875, 875, 0, 7589, 0x02a8e5d5, F=0x0
1, 883, 883, 21, 480, 0x0a6fec0b
-1, 904, 904, 21, 496, 0x6ff8ee65
+1, 904, 904, 22, 496, 0x6ff8ee65
0, 917, 959, 0, 19208, 0xdfb1a109, F=0x0
-1, 925, 925, 21, 505, 0x75a308b8
-1, 946, 946, 21, 512, 0x9628f3da
+1, 926, 926, 21, 505, 0x75a308b8
+1, 947, 947, 21, 512, 0x9628f3da
0, 959, 2000, 0, 60241, 0x43fcc627
-1, 967, 967, 22, 506, 0xefc901cf
+1, 968, 968, 22, 506, 0xefc901cf
1, 990, 990, 21, 487, 0x1fd3edc8
1, 1011, 1011, 21, 485, 0x8ccde513
-1, 1993, 1993, 21, 459, 0x725ede33
+1, 1993, 1993, 501, 459, 0x725ede33
0, 2000, 2084, 0, 23528, 0xc1dd888a, F=0x0
1, 2014, 2014, 21, 481, 0x2cd7e611
1, 2035, 2035, 21, 473, 0x14f2d777
0, 2042, 2042, 0, 9206, 0x8f8cb89b, F=0x0
1, 2056, 2056, 21, 543, 0x0f6dfccf
-1, 2077, 2077, 22, 489, 0x8049f5df
+1, 2077, 2077, 21, 489, 0x8049f5df
0, 2084, 2167, 0, 34864, 0x3a343fe0, F=0x0
-1, 2099, 2099, 21, 480, 0xaa82edfc
-1, 2120, 2120, 21, 505, 0xea87f3e9
+1, 2098, 2098, 21, 480, 0xaa82edfc
+1, 2119, 2119, 21, 505, 0xea87f3e9
0, 2125, 2125, 0, 12516, 0x885c8e4d, F=0x0
-1, 2141, 2141, 21, 474, 0x0760e6a1
-1, 2162, 2162, 22, 547, 0xcde40a72
+1, 2140, 2140, 21, 474, 0x0760e6a1
+1, 2161, 2161, 21, 547, 0xcde40a72
0, 2167, 2250, 0, 21215, 0x4428040b, F=0x0
1, 2184, 2184, 21, 606, 0x4e401ec6
1, 2205, 2205, 21, 611, 0xd13e18b6
@@ -102,27 +102,27 @@
1, 2355, 2355, 21, 482, 0x2455e264
0, 2375, 2375, 0, 7254, 0xe5c672b9, F=0x0
1, 2376, 2376, 21, 471, 0xb370df1e
-1, 2397, 2397, 21, 461, 0x01addfe6
+1, 2397, 2397, 22, 461, 0x01addfe6
0, 2417, 2500, 0, 25215, 0x1149c259, F=0x0
-1, 2418, 2418, 22, 566, 0x93760a5d
+1, 2419, 2419, 21, 566, 0x93760a5d
1, 2440, 2440, 21, 618, 0x4e8e2f95
0, 2459, 2459, 0, 14257, 0x38956a4d, F=0x0
-1, 2461, 2461, 21, 612, 0xc79128bc
-1, 2482, 2482, 21, 594, 0x169d1975
+1, 2461, 2461, 22, 612, 0xc79128bc
+1, 2483, 2483, 21, 594, 0x169d1975
0, 2500, 2584, 0, 36619, 0xca6497c5, F=0x0
-1, 2503, 2503, 22, 488, 0xb218e907
+1, 2504, 2504, 22, 488, 0xb218e907
1, 2526, 2526, 21, 437, 0xb180c83f
0, 2542, 2542, 0, 13152, 0x4ea52247, F=0x0
1, 2547, 2547, 21, 432, 0x85f8cf2b
-1, 2568, 2568, 21, 469, 0x65d0e38e
+1, 2568, 2568, 22, 469, 0x65d0e38e
0, 2584, 2667, 0, 31751, 0xb0140e79, F=0x0
-1, 2589, 2589, 22, 473, 0xb4dee328
+1, 2590, 2590, 21, 473, 0xb4dee328
1, 2611, 2611, 21, 462, 0xd95cd547
0, 2625, 2625, 0, 13619, 0x97308292, F=0x0
-1, 2632, 2632, 21, 470, 0x3638f48d
-1, 2653, 2653, 21, 558, 0x93c3121b
+1, 2632, 2632, 22, 470, 0x3638f48d
+1, 2654, 2654, 21, 558, 0x93c3121b
0, 2667, 2750, 0, 32851, 0x014d2abc, F=0x0
-1, 2674, 2674, 22, 486, 0x5983ed52
+1, 2675, 2675, 22, 486, 0x5983ed52
1, 2696, 2696, 21, 507, 0x572af3c3
0, 2709, 2709, 0, 16915, 0x3597bc67, F=0x0
1, 2717, 2717, 21, 480, 0xe3b3e16c
@@ -138,27 +138,27 @@
1, 2867, 2867, 21, 499, 0xa3b5e804
0, 2875, 2875, 0, 11796, 0x0cbff503, F=0x0
1, 2888, 2888, 21, 494, 0x0970e72e
-1, 2909, 2909, 21, 484, 0x6f34da96
+1, 2909, 2909, 22, 484, 0x6f34da96
0, 2917, 2959, 0, 16638, 0x097c9345, F=0x0
-1, 2930, 2930, 21, 492, 0x5282e9aa
-1, 2951, 2951, 21, 487, 0x6f19e15e
+1, 2931, 2931, 21, 492, 0x5282e9aa
+1, 2952, 2952, 21, 487, 0x6f19e15e
0, 2959, 3000, 0, 64129, 0xc13b91ac
-1, 2972, 2972, 22, 500, 0x17aef81a
+1, 2973, 2973, 22, 500, 0x17aef81a
1, 2995, 2995, 21, 510, 0xa323f6e6
0, 3000, 3084, 0, 19338, 0xfe901382, F=0x0
1, 3016, 3016, 21, 492, 0x49d7e74f
1, 3038, 3038, 21, 483, 0xa78deadb
0, 3042, 3042, 0, 4643, 0x5a05768b, F=0x0
-1, 3059, 3059, 21, 639, 0xf2c237e9
-1, 3080, 3080, 21, 661, 0xcd604711
+1, 3059, 3059, 22, 639, 0xf2c237e9
+1, 3081, 3081, 21, 661, 0xcd604711
0, 3084, 3167, 0, 25932, 0x395e1d01, F=0x0
-1, 3101, 3101, 22, 647, 0xb8ee3acf
-1, 3123, 3123, 21, 575, 0x3303118e
+1, 3102, 3102, 22, 647, 0xb8ee3acf
+1, 3124, 3124, 21, 575, 0x3303118e
0, 3125, 3125, 0, 5301, 0x2aacb15c, F=0x0
-1, 3144, 3144, 21, 506, 0x2063eef7
-1, 3165, 3165, 21, 518, 0x7661f08e
+1, 3145, 3145, 22, 506, 0x2063eef7
0, 3167, 3250, 0, 24089, 0x5cf78354, F=0x0
-1, 3186, 3186, 22, 534, 0x2858f90e
+1, 3167, 3167, 21, 518, 0x7661f08e
+1, 3188, 3188, 22, 534, 0x2858f90e
1, 3208, 3208, 21, 520, 0xd596f460
0, 3209, 3209, 0, 5837, 0x1c16cfad, F=0x0
1, 3229, 3229, 21, 496, 0xc2a6efed
@@ -175,26 +175,26 @@
1, 3379, 3379, 21, 499, 0x6884ec30
1, 3400, 3400, 21, 496, 0x556bdc0e
0, 3417, 3500, 0, 24790, 0x71e32bae, F=0x0
-1, 3421, 3421, 21, 524, 0xa756f115
-1, 3442, 3442, 22, 505, 0xd332f37b
+1, 3421, 3421, 22, 524, 0xa756f115
+1, 3443, 3443, 21, 505, 0xd332f37b
0, 3459, 3459, 0, 9123, 0x6c72b7a3, F=0x0
1, 3464, 3464, 21, 494, 0xa380e41e
-1, 3485, 3485, 21, 513, 0xf26bf0a9
+1, 3485, 3485, 22, 513, 0xf26bf0a9
0, 3500, 3584, 0, 24706, 0x9bdd9247, F=0x0
-1, 3506, 3506, 21, 515, 0x28fffe2a
-1, 3527, 3527, 22, 506, 0xc5a2f83c
+1, 3507, 3507, 21, 515, 0x28fffe2a
+1, 3528, 3528, 22, 506, 0xc5a2f83c
0, 3542, 3542, 0, 8105, 0x85b8ff64, F=0x0
1, 3550, 3550, 21, 510, 0xa10bf9c7
1, 3571, 3571, 21, 507, 0x93d1e650
0, 3584, 3667, 0, 25402, 0xe4622ee0, F=0x0
-1, 3592, 3592, 21, 506, 0x1a36f285
-1, 3613, 3613, 22, 522, 0xd7a1f5e4
+1, 3592, 3592, 22, 506, 0x1a36f285
+1, 3614, 3614, 21, 522, 0xd7a1f5e4
0, 3625, 3625, 0, 9693, 0x910910bc, F=0x0
1, 3635, 3635, 21, 511, 0x2e79fa62
-1, 3656, 3656, 21, 516, 0xfda2ef86
+1, 3656, 3656, 22, 516, 0xfda2ef86
0, 3667, 3750, 0, 31403, 0xff9934ee, F=0x0
-1, 3677, 3677, 21, 497, 0xd65cf156
-1, 3698, 3698, 22, 480, 0xde3be560
+1, 3678, 3678, 21, 497, 0xd65cf156
+1, 3699, 3699, 22, 480, 0xde3be560
0, 3709, 3709, 0, 13936, 0x9b6aec9e, F=0x0
1, 3720, 3720, 21, 514, 0x7d8cf49f
1, 3741, 3741, 21, 667, 0x7a483dec
--
1.7.9.5
More information about the ffmpeg-devel
mailing list