static void mxf_write_preface(AVFormatContext *s)

{

    MXFContext *mxf = s->priv_data;

    AVIOContext *pb = s->pb;



    mxf_write_metadata_key(pb, 0x012f00);

    PRINT_KEY(s, "preface key", pb->buf_ptr - 16);

    klv_encode_ber_length(pb, 130 + 16 * mxf->essence_container_count);



    // write preface set uid

    mxf_write_local_tag(pb, 16, 0x3C0A);

    mxf_write_uuid(pb, Preface, 0);

    PRINT_KEY(s, "preface uid", pb->buf_ptr - 16);



    // last modified date

    mxf_write_local_tag(pb, 8, 0x3B02);

    avio_wb64(pb, mxf->timestamp);



    // write version

    mxf_write_local_tag(pb, 2, 0x3B05);

    avio_wb16(pb, 258); // v1.2



    // write identification_refs

    mxf_write_local_tag(pb, 16 + 8, 0x3B06);

    mxf_write_refs_count(pb, 1);

    mxf_write_uuid(pb, Identification, 0);



    // write content_storage_refs

    mxf_write_local_tag(pb, 16, 0x3B03);

    mxf_write_uuid(pb, ContentStorage, 0);



    // operational pattern

    mxf_write_local_tag(pb, 16, 0x3B09);

    avio_write(pb, op1a_ul, 16);



    // write essence_container_refs

    mxf_write_local_tag(pb, 8 + 16 * mxf->essence_container_count, 0x3B0A);

    mxf_write_essence_container_refs(s);



    // write dm_scheme_refs

    mxf_write_local_tag(pb, 8, 0x3B0B);

    avio_wb64(pb, 0);

}
