static int img_read_packet(AVFormatContext *s1, AVPacket *pkt)
{
    VideoDemuxData *s = s1->priv_data;
    char filename[1024];
    int i, res;
    int size[3]           = { 0 }, ret[3] = { 0 };
    AVIOContext *f[3]     = { NULL };
    AVCodecContext *codec = s1->streams[0]->codec;
    if (!s->is_pipe) {
        if (s->loop && s->img_number > s->img_last) {
            s->img_number = s->img_first;
        }
        if (s->img_number > s->img_last)
            return AVERROR_EOF;
        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 (s1->io_open(s1, &f[i], filename, AVIO_FLAG_READ, NULL) < 0) {
                if (i >= 1)
                    break;
                av_log(s1, AV_LOG_ERROR, "Could not open file : %s\n",
                       filename);
                return AVERROR(EIO);
            }
            size[i] = avio_size(f[i]);
            if (codec->codec_id != AV_CODEC_ID_RAWVIDEO)
                break;
            filename[strlen(filename) - 1] = 'U' + i;
        }
        if (codec->codec_id == AV_CODEC_ID_RAWVIDEO && !codec->width)
            infer_size(&codec->width, &codec->height, size[0]);
    } else {
        f[0] = s1->pb;
        if (f[0]->eof_reached)
            return AVERROR(EIO);
        size[0] = 4096;
    }
    res = av_new_packet(pkt, size[0] + size[1] + size[2]);
    if (res < 0)
        return res;
    pkt->stream_index = 0;
    pkt->flags       |= AV_PKT_FLAG_KEY;
    pkt->size = 0;
    for (i = 0; i < 3; i++) {
        if (f[i]) {
            ret[i] = avio_read(f[i], pkt->data + pkt->size, size[i]);
            if (!s->is_pipe)
                ff_format_io_close(s1, &f[i]);
            if (ret[i] > 0)
                pkt->size += ret[i];
        }
    }
    if (ret[0] <= 0 || ret[1] < 0 || ret[2] < 0) {
        av_packet_unref(pkt);
        return AVERROR(EIO);
    } else {
        s->img_count++;
        s->img_number++;
        return 0;
    }
}
['static int img_read_packet(AVFormatContext *s1, AVPacket *pkt)\n{\n    VideoDemuxData *s = s1->priv_data;\n    char filename[1024];\n    int i, res;\n    int size[3]           = { 0 }, ret[3] = { 0 };\n    AVIOContext *f[3]     = { NULL };\n    AVCodecContext *codec = s1->streams[0]->codec;\n    if (!s->is_pipe) {\n        if (s->loop && s->img_number > s->img_last) {\n            s->img_number = s->img_first;\n        }\n        if (s->img_number > s->img_last)\n            return AVERROR_EOF;\n        if (av_get_frame_filename(filename, sizeof(filename),\n                                  s->path,\n                                  s->img_number) < 0 && s->img_number > 1)\n            return AVERROR(EIO);\n        for (i = 0; i < 3; i++) {\n            if (s1->io_open(s1, &f[i], filename, AVIO_FLAG_READ, NULL) < 0) {\n                if (i >= 1)\n                    break;\n                av_log(s1, AV_LOG_ERROR, "Could not open file : %s\\n",\n                       filename);\n                return AVERROR(EIO);\n            }\n            size[i] = avio_size(f[i]);\n            if (codec->codec_id != AV_CODEC_ID_RAWVIDEO)\n                break;\n            filename[strlen(filename) - 1] = \'U\' + i;\n        }\n        if (codec->codec_id == AV_CODEC_ID_RAWVIDEO && !codec->width)\n            infer_size(&codec->width, &codec->height, size[0]);\n    } else {\n        f[0] = s1->pb;\n        if (f[0]->eof_reached)\n            return AVERROR(EIO);\n        size[0] = 4096;\n    }\n    res = av_new_packet(pkt, size[0] + size[1] + size[2]);\n    if (res < 0)\n        return res;\n    pkt->stream_index = 0;\n    pkt->flags       |= AV_PKT_FLAG_KEY;\n    pkt->size = 0;\n    for (i = 0; i < 3; i++) {\n        if (f[i]) {\n            ret[i] = avio_read(f[i], pkt->data + pkt->size, size[i]);\n            if (!s->is_pipe)\n                ff_format_io_close(s1, &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_packet_unref(pkt);\n        return AVERROR(EIO);\n    } else {\n        s->img_count++;\n        s->img_number++;\n        return 0;\n    }\n}']