Skip to content

matroska-mux: Fix incorrect rounding of timestamps

Previously we saved the buffer_timestamp straight into mux->cluster_time. Since the cluster time saved into the file does not have as high precision as GstClockTime depending on the timecodescale the rounding of relative_timestamp was invalid as mux->cluster_time which it was calculated relative to was not equal to the cluster time written to the matroska file.

Example of "mkvinfo -v" of how it looks before and after this change in an scenario where previously timestamps got out of order because of this issue.

Notice the timestamp of the SimpleBlock right before and right after the Cluster now being in order. The consequence of this however is that the cluster timestamp is not necessarily the same as the timestamp of the first buffer in the cluster however (in case it's rounded up).

Before

| + SimpleBlock (track number 1, 1 frame(s), timecode 126.922s = 00:02:06.922)
|  + Frame with size 432
| + SimpleBlock (track number 2, 1 frame(s), timecode 126.933s = 00:02:06.933)
|  + Frame with size 329
| + SimpleBlock (track number 2, 1 frame(s), timecode 126.955s = 00:02:06.955)
|  + Frame with size 333
|+ Cluster
| + Cluster timecode: 126.954s
| + Cluster previous size: 97344
| + SimpleBlock (key, track number 1, 1 frame(s), timecode 126.954s = 00:02:06.954)
|  + Frame with size 61239
| + SimpleBlock (track number 2, 1 frame(s), timecode 126.975s = 00:02:06.975)
|  + Frame with size 338

After

| + SimpleBlock (track number 1, 1 frame(s), timecode 135.456s = 00:02:15.456)
|  + Frame with size 2260
| + SimpleBlock (track number 2, 1 frame(s), timecode 135.468s = 00:02:15.468)
|  + Frame with size 332
| + SimpleBlock (track number 2, 1 frame(s), timecode 135.490s = 00:02:15.490)
|  + Frame with size 335
|+ Cluster
| + Cluster timecode: 135.489s
| + Cluster previous size: 158758
| + SimpleBlock (key, track number 1, 1 frame(s), timecode 135.490s = 00:02:15.490)
|  + Frame with size 88070
| + SimpleBlock (track number 2, 1 frame(s), timecode 135.511s = 00:02:15.511)
|  + Frame with size 336
Edited by Johan Bjäreholt

Merge request reports