int av_seek_frame_binary(AVFormatContext *s, int stream_index, int64_t target_ts, int flags){
    AVInputFormat *avif= s->iformat;
    int64_t pos_min, pos_max, pos, pos_limit;
    int64_t ts_min, ts_max, ts;
    int index;
    AVStream *st;
    if (stream_index < 0)
        return -1;
#ifdef DEBUG_SEEK
    av_log(s, AV_LOG_DEBUG, "read_seek: %d %"PRId64"\n", stream_index, target_ts);
#endif
    ts_max=
    ts_min= AV_NOPTS_VALUE;
    pos_limit= -1;
    st= s->streams[stream_index];
    if(st->index_entries){
        AVIndexEntry *e;
        index= av_index_search_timestamp(st, target_ts, flags | AVSEEK_FLAG_BACKWARD);
        index= FFMAX(index, 0);
        e= &st->index_entries[index];
        if(e->timestamp <= target_ts || e->pos == e->min_distance){
            pos_min= e->pos;
            ts_min= e->timestamp;
#ifdef DEBUG_SEEK
        av_log(s, AV_LOG_DEBUG, "using cached pos_min=0x%"PRIx64" dts_min=%"PRId64"\n",
               pos_min,ts_min);
#endif
        }else{
            assert(index==0);
        }
        index= av_index_search_timestamp(st, target_ts, flags & ~AVSEEK_FLAG_BACKWARD);
        assert(index < st->nb_index_entries);
        if(index >= 0){
            e= &st->index_entries[index];
            assert(e->timestamp >= target_ts);
            pos_max= e->pos;
            ts_max= e->timestamp;
            pos_limit= pos_max - e->min_distance;
#ifdef DEBUG_SEEK
        av_log(s, AV_LOG_DEBUG, "using cached pos_max=0x%"PRIx64" pos_limit=0x%"PRIx64" dts_max=%"PRId64"\n",
               pos_max,pos_limit, ts_max);
#endif
        }
    }
    pos= av_gen_search(s, stream_index, target_ts, pos_min, pos_max, pos_limit, ts_min, ts_max, flags, &ts, avif->read_timestamp);
    if(pos<0)
        return -1;
    url_fseek(s->pb, pos, SEEK_SET);
    av_update_cur_dts(s, st, ts);
    return 0;
}
['int av_seek_frame_binary(AVFormatContext *s, int stream_index, int64_t target_ts, int flags){\n    AVInputFormat *avif= s->iformat;\n    int64_t pos_min, pos_max, pos, pos_limit;\n    int64_t ts_min, ts_max, ts;\n    int index;\n    AVStream *st;\n    if (stream_index < 0)\n        return -1;\n#ifdef DEBUG_SEEK\n    av_log(s, AV_LOG_DEBUG, "read_seek: %d %"PRId64"\\n", stream_index, target_ts);\n#endif\n    ts_max=\n    ts_min= AV_NOPTS_VALUE;\n    pos_limit= -1;\n    st= s->streams[stream_index];\n    if(st->index_entries){\n        AVIndexEntry *e;\n        index= av_index_search_timestamp(st, target_ts, flags | AVSEEK_FLAG_BACKWARD);\n        index= FFMAX(index, 0);\n        e= &st->index_entries[index];\n        if(e->timestamp <= target_ts || e->pos == e->min_distance){\n            pos_min= e->pos;\n            ts_min= e->timestamp;\n#ifdef DEBUG_SEEK\n        av_log(s, AV_LOG_DEBUG, "using cached pos_min=0x%"PRIx64" dts_min=%"PRId64"\\n",\n               pos_min,ts_min);\n#endif\n        }else{\n            assert(index==0);\n        }\n        index= av_index_search_timestamp(st, target_ts, flags & ~AVSEEK_FLAG_BACKWARD);\n        assert(index < st->nb_index_entries);\n        if(index >= 0){\n            e= &st->index_entries[index];\n            assert(e->timestamp >= target_ts);\n            pos_max= e->pos;\n            ts_max= e->timestamp;\n            pos_limit= pos_max - e->min_distance;\n#ifdef DEBUG_SEEK\n        av_log(s, AV_LOG_DEBUG, "using cached pos_max=0x%"PRIx64" pos_limit=0x%"PRIx64" dts_max=%"PRId64"\\n",\n               pos_max,pos_limit, ts_max);\n#endif\n        }\n    }\n    pos= av_gen_search(s, stream_index, target_ts, pos_min, pos_max, pos_limit, ts_min, ts_max, flags, &ts, avif->read_timestamp);\n    if(pos<0)\n        return -1;\n    url_fseek(s->pb, pos, SEEK_SET);\n    av_update_cur_dts(s, st, ts);\n    return 0;\n}']