int avformat_seek_file(AVFormatContext *s, int stream_index, int64_t min_ts, int64_t ts, int64_t max_ts, int flags)

{

    if(min_ts > ts || max_ts < ts)

        return -1;



    if (s->iformat->read_seek2) {

        int ret;

        ff_read_frame_flush(s);



        if (stream_index == -1 && s->nb_streams == 1) {

            AVRational time_base = s->streams[0]->time_base;

            ts = av_rescale_q(ts, AV_TIME_BASE_Q, time_base);

            min_ts = av_rescale_rnd(min_ts, time_base.den,

                                    time_base.num * (int64_t)AV_TIME_BASE,

                                    AV_ROUND_UP);

            max_ts = av_rescale_rnd(max_ts, time_base.den,

                                    time_base.num * (int64_t)AV_TIME_BASE,

                                    AV_ROUND_DOWN);

        }



        ret = s->iformat->read_seek2(s, stream_index, min_ts, ts, max_ts, flags);



        if (ret >= 0)

            avformat_queue_attached_pictures(s);

        return ret;

    }



    if(s->iformat->read_timestamp){

        //try to seek via read_timestamp()

    }



    //Fallback to old API if new is not implemented but old is

    //Note the old has somewhat different semantics

    if (s->iformat->read_seek || 1) {

        int dir = (ts - (uint64_t)min_ts > (uint64_t)max_ts - ts ? AVSEEK_FLAG_BACKWARD : 0);

        int ret = av_seek_frame(s, stream_index, ts, flags | dir);

        if (ret<0 && ts != min_ts && max_ts != ts) {

            ret = av_seek_frame(s, stream_index, dir ? max_ts : min_ts, flags | dir);

            if (ret >= 0)

                ret = av_seek_frame(s, stream_index, ts, flags | (dir^AVSEEK_FLAG_BACKWARD));

        }

        return ret;

    }



    // try some generic seek like seek_frame_generic() but with new ts semantics

}

int avformat_seek_file(AVFormatContext *s, int stream_index, int64_t min_ts, int64_t ts, int64_t max_ts, int flags)

{

    if(min_ts > ts || max_ts < ts)

        return -1;



    if (s->iformat->read_seek2) {

        int ret;

        ff_read_frame_flush(s);



        if (stream_index == -1 && s->nb_streams == 1) {

            AVRational time_base = s->streams[0]->time_base;

            ts = av_rescale_q(ts, AV_TIME_BASE_Q, time_base);

            min_ts = av_rescale_rnd(min_ts, time_base.den,

                                    time_base.num * (int64_t)AV_TIME_BASE,

                                    AV_ROUND_UP);

            max_ts = av_rescale_rnd(max_ts, time_base.den,

                                    time_base.num * (int64_t)AV_TIME_BASE,

                                    AV_ROUND_DOWN);

        }



        ret = s->iformat->read_seek2(s, stream_index, min_ts, ts, max_ts, flags);



        if (ret >= 0)

            avformat_queue_attached_pictures(s);

        return ret;

    }



    if(s->iformat->read_timestamp){

        

    }



    

    

    if (s->iformat->read_seek || 1) {

        int dir = (ts - (uint64_t)min_ts > (uint64_t)max_ts - ts ? AVSEEK_FLAG_BACKWARD : 0);

        int ret = av_seek_frame(s, stream_index, ts, flags | dir);

        if (ret<0 && ts != min_ts && max_ts != ts) {

            ret = av_seek_frame(s, stream_index, dir ? max_ts : min_ts, flags | dir);

            if (ret >= 0)

                ret = av_seek_frame(s, stream_index, ts, flags | (dir^AVSEEK_FLAG_BACKWARD));

        }

        return ret;

    }



    

}

                                    AV_ROUND_UP);                                     AV_ROUND_DOWN);
int FUNC_0(AVFormatContext *VAR_0, int VAR_1, int64_t VAR_2, int64_t VAR_3, int64_t VAR_4, int VAR_5)

{

    if(VAR_2 > VAR_3 || VAR_4 < VAR_3)

        return -1;



    if (VAR_0->iformat->read_seek2) {

        int VAR_8;

        ff_read_frame_flush(VAR_0);



        if (VAR_1 == -1 && VAR_0->nb_streams == 1) {

            AVRational time_base = VAR_0->streams[0]->time_base;

            VAR_3 = av_rescale_q(VAR_3, AV_TIME_BASE_Q, time_base);

            VAR_2 = av_rescale_rnd(VAR_2, time_base.den,

                                    time_base.num * (int64_t)AV_TIME_BASE,

                                    AV_ROUND_UP);

            VAR_4 = av_rescale_rnd(VAR_4, time_base.den,

                                    time_base.num * (int64_t)AV_TIME_BASE,

                                    AV_ROUND_DOWN);

        }



        VAR_8 = VAR_0->iformat->read_seek2(VAR_0, VAR_1, VAR_2, VAR_3, VAR_4, VAR_5);



        if (VAR_8 >= 0)

            avformat_queue_attached_pictures(VAR_0);

        return VAR_8;

    }



    if(VAR_0->iformat->read_timestamp){

        

    }



    

    

    if (VAR_0->iformat->read_seek || 1) {

        int VAR_7 = (VAR_3 - (uint64_t)VAR_2 > (uint64_t)VAR_4 - VAR_3 ? AVSEEK_FLAG_BACKWARD : 0);

        int VAR_8 = av_seek_frame(VAR_0, VAR_1, VAR_3, VAR_5 | VAR_7);

        if (VAR_8<0 && VAR_3 != VAR_2 && VAR_4 != VAR_3) {

            VAR_8 = av_seek_frame(VAR_0, VAR_1, VAR_7 ? VAR_4 : VAR_2, VAR_5 | VAR_7);

            if (VAR_8 >= 0)

                VAR_8 = av_seek_frame(VAR_0, VAR_1, VAR_3, VAR_5 | (VAR_7^AVSEEK_FLAG_BACKWARD));

        }

        return VAR_8;

    }



    

}

int FUNC_0(AVFormatContext *VAR_0, int VAR_1, int64_t VAR_2, int64_t VAR_3, int64_t VAR_4, int VAR_5)
{ if(VAR_2 > VAR_3 || VAR_4 < VAR_3)
return -1; if (VAR_0->iformat->read_seek2) { int VAR_8; ff_read_frame_flush(VAR_0); if (VAR_1 == -1 && VAR_0->nb_streams == 1) { AVRational time_base = VAR_0->streams[0]->time_base; VAR_3 = av_rescale_q(VAR_3, AV_TIME_BASE_Q, time_base); VAR_2 = av_rescale_rnd(VAR_2, time_base.den,
time_base.num * (int64_t)AV_TIME_BASE,
AV_ROUND_UP); VAR_4 = av_rescale_rnd(VAR_4, time_base.den,
time_base.num * (int64_t)AV_TIME_BASE,
AV_ROUND_DOWN); } VAR_8 = VAR_0->iformat->read_seek2(VAR_0, VAR_1, VAR_2, VAR_3, VAR_4, VAR_5); if (VAR_8 >= 0)
avformat_queue_attached_pictures(VAR_0); return VAR_8; } if(VAR_0->iformat->read_timestamp){ } if (VAR_0->iformat->read_seek || 1) { int VAR_7 = (VAR_3 - (uint64_t)VAR_2 > (uint64_t)VAR_4 - VAR_3 ? AVSEEK_FLAG_BACKWARD : 0); int VAR_8 = av_seek_frame(VAR_0, VAR_1, VAR_3, VAR_5 | VAR_7); if (VAR_8<0 && VAR_3 != VAR_2 && VAR_4 != VAR_3) { VAR_8 = av_seek_frame(VAR_0, VAR_1, VAR_7 ? VAR_4 : VAR_2, VAR_5 | VAR_7); if (VAR_8 >= 0)
VAR_8 = av_seek_frame(VAR_0, VAR_1, VAR_3, VAR_5 | (VAR_7^AVSEEK_FLAG_BACKWARD)); } return VAR_8; } }