[FFmpeg-devel] [PATCH 18/20] mpeg12: Move finding the best frame rate to common code

Mark Thompson sw at jkqxz.net
Thu Sep 14 11:09:43 EEST 2017


On 14/09/17 01:48, Michael Niedermayer wrote:
> On Wed, Sep 13, 2017 at 12:44:08AM +0100, Mark Thompson wrote:
>> Previously in the mpeg2_metadata filter.  Also adds a test.
> [...]
>> +    for (c = 1; c <= max_code; c++) {
>> +        for (n = 1; n <= (mpeg2 ? 4 : 1); n++) {
>> +            for (d = 1; d <= (mpeg2 ? 32 : 1); d++) {
>> +                AVRational test, error;
>> +                int cmp;
>> +
>> +                test = av_mul_q(ff_mpeg12_frame_rate_tab[c],
>> +                                (AVRational) { n, d });
>> +
>> +                cmp = av_cmp_q(test, frame_rate);
>> +                if (cmp == 0) {
>> +                    best_c = c;
>> +                    best_n = n;
>> +                    best_d = d;
>> +                    goto found;
>> +                }
>> +
>> +                if (cmp < 0)
>> +                    error = av_div_q(frame_rate, test);
>> +                else
>> +                    error = av_div_q(test, frame_rate);
>> +
>> +                cmp = av_cmp_q(error, best_error);
>> +                if (cmp < 0 || (cmp == 0 && n == 1 && d == 1)) {
>> +                    best_c = c;
>> +                    best_n = n;
>> +                    best_d = d;
>> +                    best_error = error;
>> +                }
>> +            }
>> +        }
>> +    }
> [...]
>> -        for (i = 1; i < FF_ARRAY_ELEMS(frame_rate_table); i++) {
>> -            AVRational fr, error;
>> -            int n, d, cmp;
>> -            for (n = 1; n <= 4; n++) {
>> -                for (d = 1; d <= 32; d++) {
>> -                    fr = av_mul_q(frame_rate_table[i],
>> -                                  (AVRational) { n, d });
>> -                    cmp = av_cmp_q(fr, ctx->frame_rate);
>> -                    if (cmp == 0) {
>> -                        code  = i;
>> -                        ext_n = n;
>> -                        ext_d = d;
>> -                        goto found_frame_rate;
>> -                    }
>> -                    if (cmp < 0)
>> -                        error = av_div_q(ctx->frame_rate, fr);
>> -                    else
>> -                        error = av_div_q(fr, ctx->frame_rate);
>> -                    cmp = av_cmp_q(error, best_error);
>> -                    if (cmp < 0 || (cmp == 0 && n == 1 && d == 1)) {
>> -                        code  = i;
>> -                        ext_n = n;
>> -                        ext_d = d;
>> -                        best_error = error;
>> -                    }
>> -                }
>> -            }
>> -        }
> 
> This doesnt just move the code, it also changes it
> (this makes it harder to determine if the chnages are just cosmetic or
>  not)

I'll rearrange the patches so that the common part gets applied first and never changed.

- Mark


More information about the ffmpeg-devel mailing list