static void put_ebml_void(ByteIOContext *pb, uint64_t size)
{
    offset_t currentpos = url_ftell(pb);
    assert(size >= 2);
    put_ebml_id(pb, EBML_ID_VOID);
    if (size < 10)
        put_ebml_num(pb, size-1, 0);
    else
        put_ebml_num(pb, size-9, 8);
    while(url_ftell(pb) < currentpos + size)
        put_byte(pb, 0);
}
['static int mkv_write_trailer(AVFormatContext *s)\n{\n    MatroskaMuxContext *mkv = s->priv_data;\n    ByteIOContext *pb = s->pb;\n    offset_t currentpos, second_seekhead, cuespos;\n    int ret;\n    end_ebml_master(pb, mkv->cluster);\n    if (!url_is_streamed(pb)) {\n        cuespos = mkv_write_cues(pb, mkv->cues, s->nb_streams);\n        second_seekhead = mkv_write_seekhead(pb, mkv->cluster_seekhead);\n        ret = mkv_add_seekhead_entry(mkv->main_seekhead, MATROSKA_ID_CUES    , cuespos);\n        if (ret < 0) return ret;\n        ret = mkv_add_seekhead_entry(mkv->main_seekhead, MATROSKA_ID_SEEKHEAD, second_seekhead);\n        if (ret < 0) return ret;\n        mkv_write_seekhead(pb, mkv->main_seekhead);\n        av_log(s, AV_LOG_DEBUG, "end duration = %" PRIu64 "\\n", mkv->duration);\n        currentpos = url_ftell(pb);\n        url_fseek(pb, mkv->duration_offset, SEEK_SET);\n        put_ebml_float(pb, MATROSKA_ID_DURATION, mkv->duration);\n        if (!(s->streams[0]->codec->flags & CODEC_FLAG_BITEXACT)) {\n            uint8_t segment_uid[16];\n            av_md5_final(mkv->md5_ctx, segment_uid);\n            url_fseek(pb, mkv->segment_uid, SEEK_SET);\n            put_ebml_binary(pb, MATROSKA_ID_SEGMENTUID, segment_uid, 16);\n        }\n        url_fseek(pb, currentpos, SEEK_SET);\n    }\n    end_ebml_master(pb, mkv->segment);\n    av_free(mkv->md5_ctx);\n    return 0;\n}', 'static int mkv_add_seekhead_entry(mkv_seekhead *seekhead, unsigned int elementid, uint64_t filepos)\n{\n    mkv_seekhead_entry *entries = seekhead->entries;\n    if (seekhead->max_entries > 0 && seekhead->max_entries <= seekhead->num_entries)\n        return -1;\n    entries = av_realloc(entries, (seekhead->num_entries + 1) * sizeof(mkv_seekhead_entry));\n    if (entries == NULL)\n        return AVERROR(ENOMEM);\n    entries[seekhead->num_entries  ].elementid = elementid;\n    entries[seekhead->num_entries++].segmentpos = filepos - seekhead->segment_offset;\n    seekhead->entries = entries;\n    return 0;\n}', 'static offset_t mkv_write_seekhead(ByteIOContext *pb, mkv_seekhead *seekhead)\n{\n    ebml_master metaseek, seekentry;\n    offset_t currentpos;\n    int i;\n    currentpos = url_ftell(pb);\n    if (seekhead->reserved_size > 0)\n        url_fseek(pb, seekhead->filepos, SEEK_SET);\n    metaseek = start_ebml_master(pb, MATROSKA_ID_SEEKHEAD, seekhead->reserved_size);\n    for (i = 0; i < seekhead->num_entries; i++) {\n        mkv_seekhead_entry *entry = &seekhead->entries[i];\n        seekentry = start_ebml_master(pb, MATROSKA_ID_SEEKENTRY, MAX_SEEKENTRY_SIZE);\n        put_ebml_id(pb, MATROSKA_ID_SEEKID);\n        put_ebml_num(pb, ebml_id_size(entry->elementid), 0);\n        put_ebml_id(pb, entry->elementid);\n        put_ebml_uint(pb, MATROSKA_ID_SEEKPOSITION, entry->segmentpos);\n        end_ebml_master(pb, seekentry);\n    }\n    end_ebml_master(pb, metaseek);\n    if (seekhead->reserved_size > 0) {\n        uint64_t remaining = seekhead->filepos + seekhead->reserved_size - url_ftell(pb);\n        put_ebml_void(pb, remaining);\n        url_fseek(pb, currentpos, SEEK_SET);\n        currentpos = seekhead->filepos;\n    }\n    av_free(seekhead->entries);\n    av_free(seekhead);\n    return currentpos;\n}', 'static void put_ebml_void(ByteIOContext *pb, uint64_t size)\n{\n    offset_t currentpos = url_ftell(pb);\n    assert(size >= 2);\n    put_ebml_id(pb, EBML_ID_VOID);\n    if (size < 10)\n        put_ebml_num(pb, size-1, 0);\n    else\n        put_ebml_num(pb, size-9, 8);\n    while(url_ftell(pb) < currentpos + size)\n        put_byte(pb, 0);\n}']