int av_write_trailer(AVFormatContext *s)

{

    int ret, i;



    for (;; ) {

        AVPacket pkt;

        ret = interleave_packet(s, &pkt, NULL, 1);

        if (ret < 0) //FIXME cleanup needed for ret<0 ?

            goto fail;

        if (!ret)

            break;



        ret = s->oformat->write_packet(s, &pkt);

        if (ret >= 0)

            s->streams[pkt.stream_index]->nb_frames++;



        av_free_packet(&pkt);



        if (ret < 0)

            goto fail;

    }



    if (s->oformat->write_trailer)

        ret = s->oformat->write_trailer(s);



    if (!(s->oformat->flags & AVFMT_NOFILE))

        avio_flush(s->pb);



fail:

    for (i = 0; i < s->nb_streams; i++) {

        av_freep(&s->streams[i]->priv_data);

        av_freep(&s->streams[i]->index_entries);

    }

    if (s->oformat->priv_class)

        av_opt_free(s->priv_data);

    av_freep(&s->priv_data);

    return ret;

}

int av_write_trailer(AVFormatContext *s)

{

    int ret, i;



    for (;; ) {

        AVPacket pkt;

        ret = interleave_packet(s, &pkt, NULL, 1);

        if (ret < 0) 

            goto fail;

        if (!ret)

            break;



        ret = s->oformat->write_packet(s, &pkt);

        if (ret >= 0)

            s->streams[pkt.stream_index]->nb_frames++;



        av_free_packet(&pkt);



        if (ret < 0)

            goto fail;

    }



    if (s->oformat->write_trailer)

        ret = s->oformat->write_trailer(s);



    if (!(s->oformat->flags & AVFMT_NOFILE))

        avio_flush(s->pb);



fail:

    for (i = 0; i < s->nb_streams; i++) {

        av_freep(&s->streams[i]->priv_data);

        av_freep(&s->streams[i]->index_entries);

    }

    if (s->oformat->priv_class)

        av_opt_free(s->priv_data);

    av_freep(&s->priv_data);

    return ret;

}

        ret = s->oformat->write_packet(s, &pkt);
int FUNC_0(AVFormatContext *VAR_0)

{

    int VAR_1, VAR_2;



    for (;; ) {

        AVPacket pkt;

        VAR_1 = interleave_packet(VAR_0, &pkt, NULL, 1);

        if (VAR_1 < 0) 

            goto fail;

        if (!VAR_1)

            break;



        VAR_1 = VAR_0->oformat->write_packet(VAR_0, &pkt);

        if (VAR_1 >= 0)

            VAR_0->streams[pkt.stream_index]->nb_frames++;



        av_free_packet(&pkt);



        if (VAR_1 < 0)

            goto fail;

    }



    if (VAR_0->oformat->write_trailer)

        VAR_1 = VAR_0->oformat->write_trailer(VAR_0);



    if (!(VAR_0->oformat->flags & AVFMT_NOFILE))

        avio_flush(VAR_0->pb);



fail:

    for (VAR_2 = 0; VAR_2 < VAR_0->nb_streams; VAR_2++) {

        av_freep(&VAR_0->streams[VAR_2]->priv_data);

        av_freep(&VAR_0->streams[VAR_2]->index_entries);

    }

    if (VAR_0->oformat->priv_class)

        av_opt_free(VAR_0->priv_data);

    av_freep(&VAR_0->priv_data);

    return VAR_1;

}

int FUNC_0(AVFormatContext *VAR_0)
{ int VAR_1, VAR_2; for (;; ) { AVPacket pkt; VAR_1 = interleave_packet(VAR_0, &pkt, NULL, 1); if (VAR_1 < 0)
goto fail; if (!VAR_1)
break; VAR_1 = VAR_0->oformat->write_packet(VAR_0, &pkt); if (VAR_1 >= 0)
VAR_0->streams[pkt.stream_index]->nb_frames++; av_free_packet(&pkt); if (VAR_1 < 0)
goto fail; } if (VAR_0->oformat->write_trailer)
VAR_1 = VAR_0->oformat->write_trailer(VAR_0); if (!(VAR_0->oformat->flags & AVFMT_NOFILE))
avio_flush(VAR_0->pb); fail:
for (VAR_2 = 0; VAR_2 < VAR_0->nb_streams; VAR_2++) { av_freep(&VAR_0->streams[VAR_2]->priv_data); av_freep(&VAR_0->streams[VAR_2]->index_entries); } if (VAR_0->oformat->priv_class)
av_opt_free(VAR_0->priv_data); av_freep(&VAR_0->priv_data); return VAR_1; }