int ff_rfps_add_frame(AVFormatContext *ic, AVStream *st, int64_t ts)

{

    int i, j;

    int64_t last = st->info->last_dts;



    if(   ts != AV_NOPTS_VALUE && last != AV_NOPTS_VALUE && ts > last

       && ts - (uint64_t)last < INT64_MAX){

        double dts= (is_relative(ts) ?  ts - RELATIVE_TS_BASE : ts) * av_q2d(st->time_base);

        int64_t duration= ts - last;



        if (!st->info->duration_error)

            st->info->duration_error = av_mallocz(sizeof(st->info->duration_error[0])*2);

        if (!st->info->duration_error)

            return AVERROR(ENOMEM);



//         if(st->codec->codec_type == AVMEDIA_TYPE_VIDEO)

//             av_log(NULL, AV_LOG_ERROR, "%f\n", dts);

        for (i=0; i<MAX_STD_TIMEBASES; i++) {

            if (st->info->duration_error[0][1][i] < 1e10) {

                int framerate= get_std_framerate(i);

                double sdts= dts*framerate/(1001*12);

                for(j=0; j<2; j++){

                    int64_t ticks= llrint(sdts+j*0.5);

                    double error= sdts - ticks + j*0.5;

                    st->info->duration_error[j][0][i] += error;

                    st->info->duration_error[j][1][i] += error*error;

                }

            }

        }

        st->info->duration_count++;




        if (st->info->duration_count % 10 == 0) {

            int n = st->info->duration_count;

            for (i=0; i<MAX_STD_TIMEBASES; i++) {

                if (st->info->duration_error[0][1][i] < 1e10) {

                    double a0     = st->info->duration_error[0][0][i] / n;

                    double error0 = st->info->duration_error[0][1][i] / n - a0*a0;

                    double a1     = st->info->duration_error[1][0][i] / n;

                    double error1 = st->info->duration_error[1][1][i] / n - a1*a1;

                    if (error0 > 0.04 && error1 > 0.04) {

                        st->info->duration_error[0][1][i] = 2e10;

                        st->info->duration_error[1][1][i] = 2e10;

                    }

                }

            }

        }



        // ignore the first 4 values, they might have some random jitter

        if (st->info->duration_count > 3 && is_relative(ts) == is_relative(last))

            st->info->duration_gcd = av_gcd(st->info->duration_gcd, duration);

    }

    if (ts != AV_NOPTS_VALUE)

        st->info->last_dts = ts;



    return 0;

}
int ff_rfps_add_frame(AVFormatContext *ic, AVStream *st, int64_t ts)

{

    int i, j;

    int64_t last = st->info->last_dts;



    if(   ts != AV_NOPTS_VALUE && last != AV_NOPTS_VALUE && ts > last

       && ts - (uint64_t)last < INT64_MAX){

        double dts= (is_relative(ts) ?  ts - RELATIVE_TS_BASE : ts) * av_q2d(st->time_base);

        int64_t duration= ts - last;



        if (!st->info->duration_error)

            st->info->duration_error = av_mallocz(sizeof(st->info->duration_error[0])*2);

        if (!st->info->duration_error)

            return AVERROR(ENOMEM);







        for (i=0; i<MAX_STD_TIMEBASES; i++) {

            if (st->info->duration_error[0][1][i] < 1e10) {

                int framerate= get_std_framerate(i);

                double sdts= dts*framerate/(1001*12);

                for(j=0; j<2; j++){

                    int64_t ticks= llrint(sdts+j*0.5);

                    double error= sdts - ticks + j*0.5;

                    st->info->duration_error[j][0][i] += error;

                    st->info->duration_error[j][1][i] += error*error;

                }

            }

        }

        st->info->duration_count++;




        if (st->info->duration_count % 10 == 0) {

            int n = st->info->duration_count;

            for (i=0; i<MAX_STD_TIMEBASES; i++) {

                if (st->info->duration_error[0][1][i] < 1e10) {

                    double a0     = st->info->duration_error[0][0][i] / n;

                    double error0 = st->info->duration_error[0][1][i] / n - a0*a0;

                    double a1     = st->info->duration_error[1][0][i] / n;

                    double error1 = st->info->duration_error[1][1][i] / n - a1*a1;

                    if (error0 > 0.04 && error1 > 0.04) {

                        st->info->duration_error[0][1][i] = 2e10;

                        st->info->duration_error[1][1][i] = 2e10;

                    }

                }

            }

        }



        

        if (st->info->duration_count > 3 && is_relative(ts) == is_relative(last))

            st->info->duration_gcd = av_gcd(st->info->duration_gcd, duration);

    }

    if (ts != AV_NOPTS_VALUE)

        st->info->last_dts = ts;



    return 0;

}
int FUNC_0(AVFormatContext *VAR_0, AVStream *VAR_1, int64_t VAR_2)

{

    int VAR_3, VAR_4;

    int64_t last = VAR_1->info->last_dts;



    if(   VAR_2 != AV_NOPTS_VALUE && last != AV_NOPTS_VALUE && VAR_2 > last

       && VAR_2 - (uint64_t)last < INT64_MAX){

        double VAR_5= (is_relative(VAR_2) ?  VAR_2 - RELATIVE_TS_BASE : VAR_2) * av_q2d(VAR_1->time_base);

        int64_t duration= VAR_2 - last;



        if (!VAR_1->info->duration_error)

            VAR_1->info->duration_error = av_mallocz(sizeof(VAR_1->info->duration_error[0])*2);

        if (!VAR_1->info->duration_error)

            return AVERROR(ENOMEM);







        for (VAR_3=0; VAR_3<MAX_STD_TIMEBASES; VAR_3++) {

            if (VAR_1->info->duration_error[0][1][VAR_3] < 1e10) {

                int framerate= get_std_framerate(VAR_3);

                double sdts= VAR_5*framerate/(1001*12);

                for(VAR_4=0; VAR_4<2; VAR_4++){

                    int64_t ticks= llrint(sdts+VAR_4*0.5);

                    double error= sdts - ticks + VAR_4*0.5;

                    VAR_1->info->duration_error[VAR_4][0][VAR_3] += error;

                    VAR_1->info->duration_error[VAR_4][1][VAR_3] += error*error;

                }

            }

        }

        VAR_1->info->duration_count++;




        if (VAR_1->info->duration_count % 10 == 0) {

            int VAR_6 = VAR_1->info->duration_count;

            for (VAR_3=0; VAR_3<MAX_STD_TIMEBASES; VAR_3++) {

                if (VAR_1->info->duration_error[0][1][VAR_3] < 1e10) {

                    double a0     = VAR_1->info->duration_error[0][0][VAR_3] / VAR_6;

                    double error0 = VAR_1->info->duration_error[0][1][VAR_3] / VAR_6 - a0*a0;

                    double a1     = VAR_1->info->duration_error[1][0][VAR_3] / VAR_6;

                    double error1 = VAR_1->info->duration_error[1][1][VAR_3] / VAR_6 - a1*a1;

                    if (error0 > 0.04 && error1 > 0.04) {

                        VAR_1->info->duration_error[0][1][VAR_3] = 2e10;

                        VAR_1->info->duration_error[1][1][VAR_3] = 2e10;

                    }

                }

            }

        }



        

        if (VAR_1->info->duration_count > 3 && is_relative(VAR_2) == is_relative(last))

            VAR_1->info->duration_gcd = av_gcd(VAR_1->info->duration_gcd, duration);

    }

    if (VAR_2 != AV_NOPTS_VALUE)

        VAR_1->info->last_dts = VAR_2;



    return 0;

}
int FUNC_0(AVFormatContext *VAR_0, AVStream *VAR_1, int64_t VAR_2)
{ int VAR_3, VAR_4; int64_t last = VAR_1->info->last_dts; if(   VAR_2 != AV_NOPTS_VALUE && last != AV_NOPTS_VALUE && VAR_2 > last
&& VAR_2 - (uint64_t)last < INT64_MAX){ double VAR_5= (is_relative(VAR_2) ?  VAR_2 - RELATIVE_TS_BASE : VAR_2) * av_q2d(VAR_1->time_base); int64_t duration= VAR_2 - last; if (!VAR_1->info->duration_error)
VAR_1->info->duration_error = av_mallocz(sizeof(VAR_1->info->duration_error[0])*2); if (!VAR_1->info->duration_error)
return AVERROR(ENOMEM); for (VAR_3=0; VAR_3<MAX_STD_TIMEBASES; VAR_3++) { if (VAR_1->info->duration_error[0][1][VAR_3] < 1e10) { int framerate= get_std_framerate(VAR_3); double sdts= VAR_5*framerate/(1001*12); for(VAR_4=0; VAR_4<2; VAR_4++){ int64_t ticks= llrint(sdts+VAR_4*0.5); double error= sdts - ticks + VAR_4*0.5; VAR_1->info->duration_error[VAR_4][0][VAR_3] += error; VAR_1->info->duration_error[VAR_4][1][VAR_3] += error*error; } } } VAR_1->info->duration_count++; if (VAR_1->info->duration_count % 10 == 0) { int VAR_6 = VAR_1->info->duration_count; for (VAR_3=0; VAR_3<MAX_STD_TIMEBASES; VAR_3++) { if (VAR_1->info->duration_error[0][1][VAR_3] < 1e10) { double a0     = VAR_1->info->duration_error[0][0][VAR_3] / VAR_6; double error0 = VAR_1->info->duration_error[0][1][VAR_3] / VAR_6 - a0*a0; double a1     = VAR_1->info->duration_error[1][0][VAR_3] / VAR_6; double error1 = VAR_1->info->duration_error[1][1][VAR_3] / VAR_6 - a1*a1; if (error0 > 0.04 && error1 > 0.04) { VAR_1->info->duration_error[0][1][VAR_3] = 2e10; VAR_1->info->duration_error[1][1][VAR_3] = 2e10; } } } } if (VAR_1->info->duration_count > 3 && is_relative(VAR_2) == is_relative(last))
VAR_1->info->duration_gcd = av_gcd(VAR_1->info->duration_gcd, duration); } if (VAR_2 != AV_NOPTS_VALUE)
VAR_1->info->last_dts = VAR_2; return 0; }