static int gxf_seek(AVFormatContext *s, int stream_index, int64_t timestamp, int flags) {

    int res = 0;

    uint64_t pos;

    uint64_t maxlen = 100 * 1024 * 1024;

    AVStream *st = s->streams[0];

    int64_t start_time = s->streams[stream_index]->start_time;

    int64_t found;

    int idx;

    if (timestamp < start_time) timestamp = start_time;

    idx = av_index_search_timestamp(st, timestamp - start_time,

                                    AVSEEK_FLAG_ANY | AVSEEK_FLAG_BACKWARD);

    if (idx < 0)

        return -1;

    pos = st->index_entries[idx].pos;

    if (idx < st->nb_index_entries - 2)

        maxlen = st->index_entries[idx + 2].pos - pos;

    maxlen = FFMAX(maxlen, 200 * 1024);

    res = avio_seek(s->pb, pos, SEEK_SET);

    if (res < 0)

        return res;

    found = gxf_resync_media(s, maxlen, -1, timestamp);

    if (FFABS(found - timestamp) > 4)

        return -1;

    return 0;

}

static int gxf_seek(AVFormatContext *s, int stream_index, int64_t timestamp, int flags) {

    int res = 0;

    uint64_t pos;

    uint64_t maxlen = 100 * 1024 * 1024;

    AVStream *st = s->streams[0];

    int64_t start_time = s->streams[stream_index]->start_time;

    int64_t found;

    int idx;

    if (timestamp < start_time) timestamp = start_time;

    idx = av_index_search_timestamp(st, timestamp - start_time,

                                    AVSEEK_FLAG_ANY | AVSEEK_FLAG_BACKWARD);

    if (idx < 0)

        return -1;

    pos = st->index_entries[idx].pos;

    if (idx < st->nb_index_entries - 2)

        maxlen = st->index_entries[idx + 2].pos - pos;

    maxlen = FFMAX(maxlen, 200 * 1024);

    res = avio_seek(s->pb, pos, SEEK_SET);

    if (res < 0)

        return res;

    found = gxf_resync_media(s, maxlen, -1, timestamp);

    if (FFABS(found - timestamp) > 4)

        return -1;

    return 0;

}

    int res = 0;
static int FUNC_0(AVFormatContext *VAR_0, int VAR_1, int64_t VAR_2, int VAR_3) {

    int VAR_4 = 0;

    uint64_t pos;

    uint64_t maxlen = 100 * 1024 * 1024;

    AVStream *st = VAR_0->streams[0];

    int64_t start_time = VAR_0->streams[VAR_1]->start_time;

    int64_t found;

    int VAR_5;

    if (VAR_2 < start_time) VAR_2 = start_time;

    VAR_5 = av_index_search_timestamp(st, VAR_2 - start_time,

                                    AVSEEK_FLAG_ANY | AVSEEK_FLAG_BACKWARD);

    if (VAR_5 < 0)

        return -1;

    pos = st->index_entries[VAR_5].pos;

    if (VAR_5 < st->nb_index_entries - 2)

        maxlen = st->index_entries[VAR_5 + 2].pos - pos;

    maxlen = FFMAX(maxlen, 200 * 1024);

    VAR_4 = avio_seek(VAR_0->pb, pos, SEEK_SET);

    if (VAR_4 < 0)

        return VAR_4;

    found = gxf_resync_media(VAR_0, maxlen, -1, VAR_2);

    if (FFABS(found - VAR_2) > 4)

        return -1;

    return 0;

}

static int FUNC_0(AVFormatContext *VAR_0, int VAR_1, int64_t VAR_2, int VAR_3) { int VAR_4 = 0; uint64_t pos; uint64_t maxlen = 100 * 1024 * 1024; AVStream *st = VAR_0->streams[0]; int64_t start_time = VAR_0->streams[VAR_1]->start_time; int64_t found; int VAR_5; if (VAR_2 < start_time) VAR_2 = start_time; VAR_5 = av_index_search_timestamp(st, VAR_2 - start_time,
AVSEEK_FLAG_ANY | AVSEEK_FLAG_BACKWARD); if (VAR_5 < 0)
return -1; pos = st->index_entries[VAR_5].pos; if (VAR_5 < st->nb_index_entries - 2)
maxlen = st->index_entries[VAR_5 + 2].pos - pos; maxlen = FFMAX(maxlen, 200 * 1024); VAR_4 = avio_seek(VAR_0->pb, pos, SEEK_SET); if (VAR_4 < 0)
return VAR_4; found = gxf_resync_media(VAR_0, maxlen, -1, VAR_2); if (FFABS(found - VAR_2) > 4)
return -1; return 0; }