diff mbox series

[FFmpeg-devel,2/2] avformat/matroskadec: adjust the cluster time to the track timebase

Message ID 20201115085948.26003-2-robux4@ycbcr.xyz
State Accepted
Commit 3a2b786db0fe52ccdcb4a3276758c8ddd4887ce6
Headers show
Series [FFmpeg-devel,1/2] avformat/matroskadec: add a warning when the track TimestampScale won't be used
Related show

Checks

Context Check Description
andriy/x86_make success Make finished
andriy/x86_make_fate success Make fate finished
andriy/PPC64_make success Make finished
andriy/PPC64_make_fate success Make fate finished

Commit Message

Steve Lhomme Nov. 15, 2020, 8:59 a.m. UTC
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.
---
 libavformat/matroskadec.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

Comments

Anton Khirnov Nov. 19, 2020, 8:08 a.m. UTC | #1
Quoting Steve Lhomme (2020-11-15 09:59:48)
> 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.
> ---
>  libavformat/matroskadec.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/libavformat/matroskadec.c b/libavformat/matroskadec.c
> index ba0e2956df..137674c068 100644
> --- a/libavformat/matroskadec.c
> +++ b/libavformat/matroskadec.c
> @@ -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 */
> -- 
> 2.26.2
> 

Set makes sense I suppose.
diff mbox series

Patch

diff --git a/libavformat/matroskadec.c b/libavformat/matroskadec.c
index ba0e2956df..137674c068 100644
--- a/libavformat/matroskadec.c
+++ b/libavformat/matroskadec.c
@@ -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 */