[FFmpeg-devel] [PATCH] matroskaenc.c DefaultDuration wrong value on stream copy

Martin Tessarek mt
Wed Jan 12 14:36:40 CET 2011

Am 12.01.2011 um 13:54 schrieb Aurelien Jacobs:

> According to the Matroska spec, track default_duration is:
>  Number of nanoseconds (i.e. not scaled) per frame.
> So if it's really set to 1000, the player should interpret this as
> 1000000 fps (which is obviously wrong).

mediainfo reports it as 1000 fps.

> This is not OK.
> The matroska encoder shouldn't care whether it is a stream copy or not.
> Now, the problem we have is that codec->time_base is not really a
> representation of the frame duration. It might be OK to use it with
> constant frame rate sources, but not with variable frame rate.
> In case of variable frame rate it might be better to try to use
> avg_frame_rate to compute a default_duration, or even simpler, don't set
> default_duration at all (it is not a mandatory mkv element).
> It is also possible to add a sanity check. For example, just don't write
> default_duration when codec->time_base is <5ms.

The problem originates from ffmpeg.c line 2150:
            if(av_q2d(icodec->time_base)*icodec->ticks_per_frame > av_q2d(ist->st->time_base) && av_q2d(ist->st->time_base) < 1.0/1000){
                codec->time_base = icodec->time_base;
                codec->time_base.num *= icodec->ticks_per_frame;
                av_reduce(&codec->time_base.num, &codec->time_base.den,
                          codec->time_base.num, codec->time_base.den, INT_MAX);
                codec->time_base = ist->st->time_base;

icodec->time_base would have the correct value but the comparison fails and ist->st->time_base is taken.

More information about the ffmpeg-devel mailing list