]> git.sesse.net Git - ffmpeg/commitdiff
avformat/matroskadec: adjust the cluster time to the track timebase
authorSteve Lhomme <robux4@ycbcr.xyz>
Sun, 15 Nov 2020 08:59:48 +0000 (09:59 +0100)
committerAnton Khirnov <anton@khirnov.net>
Fri, 20 Nov 2020 14:20:24 +0000 (15:20 +0100)
The Block timestamp read in matroska_parse_block() is in track timebase and is
passed on as such to the AVPacket which uses this timebase.

In the normal case the Cluster and Track timebases are the same because the
track->time_scale is 1.0. But when it is not the case, the values in Cluster
timebase need to be transformed in Track timebase so they can be added
together.

Signed-off-by: Anton Khirnov <anton@khirnov.net>
libavformat/matroskadec.c

index ba0e2956df6416a90842ce78a0b1ecd04c6548ee..137674c06822520eaab037112e9c0e781c7448a7 100644 (file)
@@ -3581,7 +3581,8 @@ static int matroska_parse_block(MatroskaDemuxContext *matroska, AVBufferRef *buf
 
     if (cluster_time != (uint64_t) -1 &&
         (block_time >= 0 || cluster_time >= -block_time)) {
-        timecode = cluster_time + block_time - track->codec_delay_in_track_tb;
+        uint64_t timecode_cluster_in_track_tb = (double) cluster_time / track->time_scale;
+        timecode = timecode_cluster_in_track_tb + block_time - track->codec_delay_in_track_tb;
         if (track->type == MATROSKA_TRACK_TYPE_SUBTITLE &&
             timecode < track->end_timecode)
             is_keyframe = 0;  /* overlapping subtitles are not key frame */