static int avi_write_idx1(AVFormatContext *s)
{
    ByteIOContext *pb = s->pb;
    AVIContext *avi = s->priv_data;
    offset_t idx_chunk;
    int i;
    char tag[5];
    if (!url_is_streamed(pb)) {
        AVIIentry* ie = 0, *tie;
        int entry[MAX_STREAMS];
        int empty, stream_id = -1;
        idx_chunk = start_tag(pb, "idx1");
        memset(&entry[0], 0, sizeof(entry));
        do {
            empty = 1;
            for (i=0; i<s->nb_streams; i++) {
                 if (avi->indexes[i].entry <= entry[i])
                     continue;
                 tie = avi_get_ientry(&avi->indexes[i], entry[i]);
                 if (empty || tie->pos < ie->pos) {
                     ie = tie;
                     stream_id = i;
                 }
                 empty = 0;
            }
            if (!empty) {
                avi_stream2fourcc(&tag[0], stream_id,
                                  s->streams[stream_id]->codec->codec_type);
                put_tag(pb, &tag[0]);
                put_le32(pb, ie->flags);
                put_le32(pb, ie->pos);
                put_le32(pb, ie->len);
                entry[stream_id]++;
            }
        } while (!empty);
        end_tag(pb, idx_chunk);
        avi_write_counters(s, avi->riff_id);
    }
    return 0;
}
['static int avi_write_idx1(AVFormatContext *s)\n{\n    ByteIOContext *pb = s->pb;\n    AVIContext *avi = s->priv_data;\n    offset_t idx_chunk;\n    int i;\n    char tag[5];\n    if (!url_is_streamed(pb)) {\n        AVIIentry* ie = 0, *tie;\n        int entry[MAX_STREAMS];\n        int empty, stream_id = -1;\n        idx_chunk = start_tag(pb, "idx1");\n        memset(&entry[0], 0, sizeof(entry));\n        do {\n            empty = 1;\n            for (i=0; i<s->nb_streams; i++) {\n                 if (avi->indexes[i].entry <= entry[i])\n                     continue;\n                 tie = avi_get_ientry(&avi->indexes[i], entry[i]);\n                 if (empty || tie->pos < ie->pos) {\n                     ie = tie;\n                     stream_id = i;\n                 }\n                 empty = 0;\n            }\n            if (!empty) {\n                avi_stream2fourcc(&tag[0], stream_id,\n                                  s->streams[stream_id]->codec->codec_type);\n                put_tag(pb, &tag[0]);\n                put_le32(pb, ie->flags);\n                put_le32(pb, ie->pos);\n                put_le32(pb, ie->len);\n                entry[stream_id]++;\n            }\n        } while (!empty);\n        end_tag(pb, idx_chunk);\n        avi_write_counters(s, avi->riff_id);\n    }\n    return 0;\n}']