int av_write_trailer(AVFormatContext *s)
{
    int ret, i;
    for(;;){
        AVPacket pkt;
        ret= av_interleave_packet(s, &pkt, NULL, 1);
        if(ret<0)
            goto fail;
        if(!ret)
            break;
        truncate_ts(s->streams[pkt.stream_index], &pkt);
        ret= s->oformat->write_packet(s, &pkt);
        av_free_packet(&pkt);
        if(ret<0)
            goto fail;
        if(url_ferror(s->pb))
            goto fail;
    }
    if(s->oformat->write_trailer)
        ret = s->oformat->write_trailer(s);
fail:
    if(ret == 0)
       ret=url_ferror(s->pb);
    for(i=0;i<s->nb_streams;i++)
        av_freep(&s->streams[i]->priv_data);
    av_freep(&s->priv_data);
    return ret;
}
['int av_write_trailer(AVFormatContext *s)\n{\n    int ret, i;\n    for(;;){\n        AVPacket pkt;\n        ret= av_interleave_packet(s, &pkt, NULL, 1);\n        if(ret<0)\n            goto fail;\n        if(!ret)\n            break;\n        truncate_ts(s->streams[pkt.stream_index], &pkt);\n        ret= s->oformat->write_packet(s, &pkt);\n        av_free_packet(&pkt);\n        if(ret<0)\n            goto fail;\n        if(url_ferror(s->pb))\n            goto fail;\n    }\n    if(s->oformat->write_trailer)\n        ret = s->oformat->write_trailer(s);\nfail:\n    if(ret == 0)\n       ret=url_ferror(s->pb);\n    for(i=0;i<s->nb_streams;i++)\n        av_freep(&s->streams[i]->priv_data);\n    av_freep(&s->priv_data);\n    return ret;\n}']