Beispiel #1
0
static int avi_write_idx1(avi_Context* AVI, avi_RIFF *riff)
{

    int64_t idx_chunk;
    int i;
    char tag[5];


    io_Stream *stream;
    avi_Ientry* ie = 0, *tie;
    int empty, stream_id = -1;

    idx_chunk = avi_open_tag(AVI, "idx1");
    for (i=0;i<AVI->stream_list_size;i++)
    {
            stream = get_stream(AVI->stream_list, i);
            stream->entry=0;
    }

    do
    {
        empty = 1;
        for (i=0;i<AVI->stream_list_size;i++)
        {
			stream = get_stream(AVI->stream_list, i);
			avi_Index* indexes = (avi_Index*) stream->indexes;
            if (indexes->entry <= stream->entry)
                continue;

            tie = avi_get_ientry(indexes, stream->entry);
            if (empty || tie->pos < ie->pos)
            {
                ie = tie;
                stream_id = i;
            }
            empty = 0;
        }

        if (!empty)
        {
            stream = get_stream(AVI->stream_list, stream_id);
            avi_stream2fourcc(tag, stream);
            io_write_4cc(AVI->writer, tag);
            io_write_wl32(AVI->writer, ie->flags);
            io_write_wl32(AVI->writer, ie->pos);
            io_write_wl32(AVI->writer, ie->len);
            stream->entry++;
        }
    }
    while (!empty);

    avi_close_tag(AVI, idx_chunk);
	fprintf(stderr, "AVI: wrote idx1\n");
    avi_write_counters(AVI, riff);

    return 0;
}
Beispiel #2
0
static int avi_write_trailer(AVFormatContext *s)
{
    AVIContext *avi = s->priv_data;
    AVIOContext *pb = s->pb;
    int res = 0;
    int i, j, n, nb_frames;
    int64_t file_size;

    if (pb->seekable) {
        if (avi->riff_id == 1) {
            ff_end_tag(pb, avi->movi_list);
            res = avi_write_idx1(s);
            ff_end_tag(pb, avi->riff_start);
        } else {
            avi_write_ix(s);
            ff_end_tag(pb, avi->movi_list);
            ff_end_tag(pb, avi->riff_start);

            file_size = avio_tell(pb);
            avio_seek(pb, avi->odml_list - 8, SEEK_SET);
            ffio_wfourcc(pb, "LIST"); /* Making this AVI OpenDML one */
            avio_skip(pb, 16);

            for (n = nb_frames = 0; n < s->nb_streams; n++) {
                AVCodecContext *stream = s->streams[n]->codec;
                AVIStream *avist       = s->streams[n]->priv_data;

                if (stream->codec_type == AVMEDIA_TYPE_VIDEO) {
                    if (nb_frames < avist->packet_count)
                        nb_frames = avist->packet_count;
                } else {
                    if (stream->codec_id == AV_CODEC_ID_MP2 ||
                        stream->codec_id == AV_CODEC_ID_MP3)
                        nb_frames += avist->packet_count;
                }
            }
            avio_wl32(pb, nb_frames);
            avio_seek(pb, file_size, SEEK_SET);

            avi_write_counters(s, avi->riff_id);
        }
    }

    for (i = 0; i < s->nb_streams; i++) {
        AVIStream *avist = s->streams[i]->priv_data;
        for (j = 0; j < avist->indexes.ents_allocated / AVI_INDEX_CLUSTER_SIZE; j++)
            av_freep(&avist->indexes.cluster[j]);
        av_freep(&avist->indexes.cluster);
        avist->indexes.ents_allocated = avist->indexes.entry = 0;
        if (pb->seekable) {
            avio_seek(pb, avist->frames_hdr_strm + 4, SEEK_SET);
            avio_wl32(pb, avist->max_size);
        }
    }

    return res;
}
Beispiel #3
0
static int avi_write_trailer(AVFormatContext *s)
{
    AVIContext *avi = s->priv_data;
    ByteIOContext *pb = &s->pb;
    int res = 0;
    int i, j, n, nb_frames;
    offset_t file_size;

    if (!url_is_streamed(pb))
    {
    if (avi->riff_id == 1) {
        end_tag(pb, avi->movi_list);
        res = avi_write_idx1(s);
        end_tag(pb, avi->riff_start);
    } else {
        avi_write_ix(s);
        end_tag(pb, avi->movi_list);
        end_tag(pb, avi->riff_start);

        file_size = url_ftell(pb);
        url_fseek(pb, avi->odml_list - 8, SEEK_SET);
        put_tag(pb, "LIST"); /* Making this AVI OpenDML one */
        url_fskip(pb, 16);

        for (n=nb_frames=0;n<s->nb_streams;n++) {
             AVCodecContext *stream = s->streams[n]->codec;
             if (stream->codec_type == CODEC_TYPE_VIDEO) {
                 if (nb_frames < avi->packet_count[n])
                     nb_frames = avi->packet_count[n];
             } else {
                 if (stream->codec_id == CODEC_ID_MP2 || stream->codec_id == CODEC_ID_MP3) {
                     nb_frames += avi->packet_count[n];
                }
            }
        }
        put_le32(pb, nb_frames);
        url_fseek(pb, file_size, SEEK_SET);

        avi_write_counters(s, avi->riff_id);
    }
    }
    put_flush_packet(pb);

    for (i=0; i<MAX_STREAMS; i++) {
         for (j=0; j<avi->indexes[i].ents_allocated/AVI_INDEX_CLUSTER_SIZE; j++)
              av_free(avi->indexes[i].cluster[j]);
         av_free(avi->indexes[i].cluster);
         avi->indexes[i].cluster = NULL;
         avi->indexes[i].ents_allocated = avi->indexes[i].entry = 0;
    }

    return res;
}
Beispiel #4
0
int avi_close(avi_Context* AVI)
{
    int res = 0;
    int n, nb_frames;
    int64_t file_size;

    avi_RIFF* riff = avi_get_last_riff(AVI);

    if (riff->id == 1)
    {
        avi_close_tag(AVI, riff->movi_list);
        fprintf(stderr, "AVI: (%" PRIu64 ") close movi tag\n",io_get_offset(AVI->writer));
        res = avi_write_idx1(AVI, riff);
        avi_close_tag(AVI, riff->riff_start);
    }
    else
    {
        avi_write_ix(AVI);
        avi_close_tag(AVI, riff->movi_list);
        avi_close_tag(AVI, riff->riff_start);

        file_size = io_get_offset(AVI->writer);
        io_seek(AVI->writer, AVI->odml_list - 8);
        io_write_4cc(AVI->writer, "LIST"); /* Making this AVI OpenDML one */
        io_skip(AVI->writer, 16);

        for (n=nb_frames=0;n<AVI->stream_list_size;n++)
        {
            io_Stream *stream = get_stream(AVI->stream_list, n);

            if (stream->type == STREAM_TYPE_VIDEO)
            {
                if (nb_frames < stream->packet_count)
                        nb_frames = stream->packet_count;
            }
            else
            {
                if (stream->codec_id == CODEC_ID_MP2 || stream->codec_id == CODEC_ID_MP3)
                        nb_frames += stream->packet_count;
            }
        }
        io_write_wl32(AVI->writer, nb_frames);
        io_seek(AVI->writer, file_size);

        avi_write_counters(AVI, riff);
    }

	clean_indexes(AVI);

    return res;
}
Beispiel #5
0
static int avi_write_idx1(AVFormatContext *s)
{
    AVIOContext *pb = s->pb;
    AVIContext *avi = s->priv_data;
    int64_t idx_chunk;
    int i;
    char tag[5];

    if (pb->seekable) {
        AVIStream *avist;
        AVIIentry* ie = 0, *tie;
        int empty, stream_id = -1;

        idx_chunk = ff_start_tag(pb, "idx1");
        for(i=0; i<s->nb_streams; i++){
            avist= s->streams[i]->priv_data;
            avist->entry=0;
        }

        do {
            empty = 1;
            for (i=0; i<s->nb_streams; i++) {
                avist= s->streams[i]->priv_data;
                 if (avist->indexes.entry <= avist->entry)
                     continue;

                 tie = avi_get_ientry(&avist->indexes, avist->entry);
                 if (empty || tie->pos < ie->pos) {
                     ie = tie;
                     stream_id = i;
                 }
                 empty = 0;
            }
            if (!empty) {
                avist= s->streams[stream_id]->priv_data;
                avi_stream2fourcc(tag, stream_id,
                                  s->streams[stream_id]->codec->codec_type);
                ffio_wfourcc(pb, tag);
                avio_wl32(pb, ie->flags);
                avio_wl32(pb, ie->pos);
                avio_wl32(pb, ie->len);
                avist->entry++;
            }
        } while (!empty);
        ff_end_tag(pb, idx_chunk);

        avi_write_counters(s, avi->riff_id);
    }
    return 0;
}
Beispiel #6
0
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;
}