static int img_read_packet(AVFormatContext *s1, AVPacket *pkt)
{
    VideoData *s = s1->priv_data;
    char filename[1024];
    int i;
    int size[3]={0}, ret[3]={0};
    ByteIOContext *f[3];
    AVCodecContext *codec= s1->streams[0]->codec;
    if (!s->is_pipe) {
        if (s1->loop_input && s->img_number > s->img_last) {
            s->img_number = s->img_first;
        }
        if (av_get_frame_filename(filename, sizeof(filename),
                                  s->path, s->img_number)<0 && s->img_number > 1)
            return AVERROR(EIO);
        for(i=0; i<3; i++){
            if (url_fopen(&f[i], filename, URL_RDONLY) < 0)
                return AVERROR(EIO);
            size[i]= url_fsize(f[i]);
            if(codec->codec_id != CODEC_ID_RAWVIDEO)
                break;
            filename[ strlen(filename) - 1 ]= 'U' + i;
        }
        if(codec->codec_id == CODEC_ID_RAWVIDEO && !codec->width)
            infer_size(&codec->width, &codec->height, size[0]);
    } else {
        f[0] = s1->pb;
        if (url_feof(f[0]))
            return AVERROR(EIO);
        size[0]= 4096;
    }
    av_new_packet(pkt, size[0] + size[1] + size[2]);
    pkt->stream_index = 0;
    pkt->flags |= PKT_FLAG_KEY;
    pkt->size= 0;
    for(i=0; i<3; i++){
        if(size[i]){
            ret[i]= get_buffer(f[i], pkt->data + pkt->size, size[i]);
            if (!s->is_pipe)
                url_fclose(f[i]);
            if(ret[i]>0)
                pkt->size += ret[i];
        }
    }
    if (ret[0] <= 0 || ret[1]<0 || ret[2]<0) {
        av_free_packet(pkt);
        return AVERROR(EIO);
    } else {
        s->img_count++;
        s->img_number++;
        return 0;
    }
}
["static int img_read_packet(AVFormatContext *s1, AVPacket *pkt)\n{\n    VideoData *s = s1->priv_data;\n    char filename[1024];\n    int i;\n    int size[3]={0}, ret[3]={0};\n    ByteIOContext *f[3];\n    AVCodecContext *codec= s1->streams[0]->codec;\n    if (!s->is_pipe) {\n        if (s1->loop_input && s->img_number > s->img_last) {\n            s->img_number = s->img_first;\n        }\n        if (av_get_frame_filename(filename, sizeof(filename),\n                                  s->path, s->img_number)<0 && s->img_number > 1)\n            return AVERROR(EIO);\n        for(i=0; i<3; i++){\n            if (url_fopen(&f[i], filename, URL_RDONLY) < 0)\n                return AVERROR(EIO);\n            size[i]= url_fsize(f[i]);\n            if(codec->codec_id != CODEC_ID_RAWVIDEO)\n                break;\n            filename[ strlen(filename) - 1 ]= 'U' + i;\n        }\n        if(codec->codec_id == CODEC_ID_RAWVIDEO && !codec->width)\n            infer_size(&codec->width, &codec->height, size[0]);\n    } else {\n        f[0] = s1->pb;\n        if (url_feof(f[0]))\n            return AVERROR(EIO);\n        size[0]= 4096;\n    }\n    av_new_packet(pkt, size[0] + size[1] + size[2]);\n    pkt->stream_index = 0;\n    pkt->flags |= PKT_FLAG_KEY;\n    pkt->size= 0;\n    for(i=0; i<3; i++){\n        if(size[i]){\n            ret[i]= get_buffer(f[i], pkt->data + pkt->size, size[i]);\n            if (!s->is_pipe)\n                url_fclose(f[i]);\n            if(ret[i]>0)\n                pkt->size += ret[i];\n        }\n    }\n    if (ret[0] <= 0 || ret[1]<0 || ret[2]<0) {\n        av_free_packet(pkt);\n        return AVERROR(EIO);\n    } else {\n        s->img_count++;\n        s->img_number++;\n        return 0;\n    }\n}"]