nb_frames = 0; for(n=0;n<s->nb_streams;n++) { if (avi->frames_hdr_strm[n] != 0) { stream = &s->streams[n]->codec; url_fseek(pb, avi->frames_hdr_strm[n], SEEK_SET); if (stream->codec_type == CODEC_TYPE_VIDEO) { put_le32(pb, stream->frame_number); if (nb_frames < stream->frame_number) nb_frames = stream->frame_number; } else { if (stream->codec_id == CODEC_ID_MP2) { put_le32(pb, stream->frame_number); nb_frames += stream->frame_number; } else { parse_specific_params(stream, &au_byterate, &au_ssize, &au_scale); put_le32(pb, avi->audio_strm_length[n] / au_ssize); } } } } if (avi->frames_hdr_all != 0) { url_fseek(pb, avi->frames_hdr_all, SEEK_SET); put_le32(pb, nb_frames); }
static int avi_write_trailer(AVFormatContext *s){    ByteIOContext *pb = &s->pb;    AVIContext *avi = s->priv_data;    offset_t file_size, idx_chunk;    AVIIndex *idx;    if (!url_is_streamed(&s->pb)) {        end_tag(pb, avi->movi_list);        idx_chunk = start_tag(pb, "idx1");        idx = avi->first;        while (idx != NULL) {            put_buffer(pb, idx->tag, 4);            put_le32(pb, idx->flags);            put_le32(pb, idx->pos);            put_le32(pb, idx->len);            idx = idx->next;        }        end_tag(pb, idx_chunk);                /* update file size */        file_size = url_ftell(pb);        url_fseek(pb, 4, SEEK_SET);        put_le32(pb, (UINT32)(file_size - 8));        url_fseek(pb, file_size, SEEK_SET);    }    put_flush_packet(pb);    free(avi);    return 0;}