img_size = lseek((int)h->priv_data, 0, SEEK_END);
img_size = url_seek(h, 0, SEEK_END);
static int img_read_header(AVFormatContext *s1, AVFormatParameters *ap){    VideoData *s;    int i, h;    char buf[1024];    char buf1[32];    ByteIOContext pb1, *f = &pb1;    AVStream *st;    s = malloc(sizeof(VideoData));    if (!s)        return -ENOMEM;    s1->priv_data = s;    s1->nb_streams = 1;    st = av_mallocz(sizeof(AVStream));    if (!st) {        free(s);        return -ENOMEM;    }    s1->streams[0] = st;        strcpy(s->path, s1->filename);    s->img_number = 0;    /* find format */    if (s1->format->flags & AVFMT_NOFILE)        s->is_pipe = 0;    else        s->is_pipe = 1;            if (s1->format == &pgmyuvpipe_format ||        s1->format == &pgmyuv_format)        s->img_fmt = IMGFMT_PGMYUV;    else if (s1->format == &pgmpipe_format ||             s1->format == &pgm_format)        s->img_fmt = IMGFMT_PGM;    else if (s1->format == &imgyuv_format)        s->img_fmt = IMGFMT_YUV;    else if (s1->format == &ppmpipe_format ||             s1->format == &ppm_format)        s->img_fmt = IMGFMT_PPM;    else        goto fail;    if (!s->is_pipe) {        /* try to find the first image */        for(i=0;i<5;i++) {            snprintf(buf, sizeof(buf), s->path, s->img_number);            if (url_fopen(f, buf, URL_RDONLY) >= 0)                break;            s->img_number++;        }        if (i == 5)            goto fail;    } else {        f = &s1->pb;    }        /* find the image size */    /* XXX: use generic file format guessing, as mpeg */    switch(s->img_fmt) {    case IMGFMT_PGM:    case IMGFMT_PGMYUV:    case IMGFMT_PPM:        pnm_get(f, buf1, sizeof(buf1));        pnm_get(f, buf1, sizeof(buf1));        s->width = atoi(buf1);        pnm_get(f, buf1, sizeof(buf1));        h = atoi(buf1);        if (s->img_fmt == IMGFMT_PGMYUV)            h = (h * 2) / 3;        s->height = h;        if (s->width <= 0 ||            s->height <= 0 ||            (s->width % 2) != 0 ||            (s->height % 2) != 0) {            goto fail1;        }        break;    case IMGFMT_YUV:        /* infer size by using the file size. */        {            int img_size;            URLContext *h;            /* XXX: hack hack */            h = url_fileno(f);            img_size = lseek((int)h->priv_data, 0, SEEK_END);            if (infer_size(&s->width, &s->height, img_size) < 0) {                goto fail1;            }        }        break;    }    if (!s->is_pipe) {        url_fclose(f);    } else {        url_fseek(f, 0, SEEK_SET);    }        st->codec.codec_type = CODEC_TYPE_VIDEO;    st->codec.codec_id = CODEC_ID_RAWVIDEO;    st->codec.width = s->width;    st->codec.height = s->height;    if (s->img_fmt == IMGFMT_PPM) {        st->codec.pix_fmt = PIX_FMT_RGB24;        s->img_size = (s->width * s->height * 3);    } else {        st->codec.pix_fmt = PIX_FMT_YUV420P;        s->img_size = (s->width * s->height * 3) / 2;    }    if (!ap || !ap->frame_rate)        st->codec.frame_rate = 25 * FRAME_RATE_BASE;    else        st->codec.frame_rate = ap->frame_rate;        return 0; fail1:    if (!s->is_pipe)        url_fclose(f); fail:    free(s);    return -EIO;}