static int mxf_write_header(AVFormatContext *s)
{
    MXFContext *mxf = s->priv_data;
    int i;
    uint8_t present[sizeof(mxf_essence_container_uls)/
                    sizeof(*mxf_essence_container_uls)] = {0};
    for (i = 0; i < s->nb_streams; i++) {
        AVStream *st = s->streams[i];
        MXFStreamContext *sc = av_mallocz(sizeof(*sc));
        if (!sc)
            return AVERROR(ENOMEM);
        st->priv_data = sc;
        if (st->codec->codec_type == CODEC_TYPE_VIDEO)
            av_set_pts_info(st, 64, 1, st->codec->time_base.den);
        else if (st->codec->codec_type == CODEC_TYPE_AUDIO)
            av_set_pts_info(st, 64, 1, st->codec->sample_rate);
        sc->duration = -1;
        sc->index = mxf_get_essence_container_ul_index(st->codec->codec_id);
        if (sc->index == -1) {
            av_log(s, AV_LOG_ERROR, "track %d: could not find essence container ul, "
                   "codec not currently supported in container\n", i);
            return -1;
        }
        if (st->codec->codec_id == CODEC_ID_MPEG2VIDEO) {
            if (st->codec->profile == FF_PROFILE_UNKNOWN ||
                st->codec->level == FF_LEVEL_UNKNOWN) {
                av_log(s, AV_LOG_ERROR, "track %d: profile and level must be set for mpeg-2\n", i);
                return -1;
            }
            sc->codec_ul = mxf_get_mpeg2_codec_ul(st->codec);
            if (!sc->codec_ul) {
                av_log(s, AV_LOG_ERROR, "track %d: could not find codec ul for mpeg-2, "
                       "unsupported profile/level\n", i);
                return -1;
            }
        } else
            sc->codec_ul = &mxf_essence_container_uls[sc->index].codec_ul;
        if (!present[sc->index]) {
            mxf->essence_containers_indices[mxf->essence_container_count++] = sc->index;
            present[sc->index] = 1;
        } else
            present[sc->index]++;
        memcpy(sc->track_essence_element_key, mxf_essence_container_uls[sc->index].element_ul, 15);
        sc->track_essence_element_key[15] = present[sc->index];
        PRINT_KEY(s, "track essence element key", sc->track_essence_element_key);
    }
    mxf_write_partition(s, 1, header_open_partition_key, 1);
    return 0;
}
['static int mxf_write_header(AVFormatContext *s)\n{\n    MXFContext *mxf = s->priv_data;\n    int i;\n    uint8_t present[sizeof(mxf_essence_container_uls)/\n                    sizeof(*mxf_essence_container_uls)] = {0};\n    for (i = 0; i < s->nb_streams; i++) {\n        AVStream *st = s->streams[i];\n        MXFStreamContext *sc = av_mallocz(sizeof(*sc));\n        if (!sc)\n            return AVERROR(ENOMEM);\n        st->priv_data = sc;\n        if (st->codec->codec_type == CODEC_TYPE_VIDEO)\n            av_set_pts_info(st, 64, 1, st->codec->time_base.den);\n        else if (st->codec->codec_type == CODEC_TYPE_AUDIO)\n            av_set_pts_info(st, 64, 1, st->codec->sample_rate);\n        sc->duration = -1;\n        sc->index = mxf_get_essence_container_ul_index(st->codec->codec_id);\n        if (sc->index == -1) {\n            av_log(s, AV_LOG_ERROR, "track %d: could not find essence container ul, "\n                   "codec not currently supported in container\\n", i);\n            return -1;\n        }\n        if (st->codec->codec_id == CODEC_ID_MPEG2VIDEO) {\n            if (st->codec->profile == FF_PROFILE_UNKNOWN ||\n                st->codec->level == FF_LEVEL_UNKNOWN) {\n                av_log(s, AV_LOG_ERROR, "track %d: profile and level must be set for mpeg-2\\n", i);\n                return -1;\n            }\n            sc->codec_ul = mxf_get_mpeg2_codec_ul(st->codec);\n            if (!sc->codec_ul) {\n                av_log(s, AV_LOG_ERROR, "track %d: could not find codec ul for mpeg-2, "\n                       "unsupported profile/level\\n", i);\n                return -1;\n            }\n        } else\n            sc->codec_ul = &mxf_essence_container_uls[sc->index].codec_ul;\n        if (!present[sc->index]) {\n            mxf->essence_containers_indices[mxf->essence_container_count++] = sc->index;\n            present[sc->index] = 1;\n        } else\n            present[sc->index]++;\n        memcpy(sc->track_essence_element_key, mxf_essence_container_uls[sc->index].element_ul, 15);\n        sc->track_essence_element_key[15] = present[sc->index];\n        PRINT_KEY(s, "track essence element key", sc->track_essence_element_key);\n    }\n    mxf_write_partition(s, 1, header_open_partition_key, 1);\n    return 0;\n}', 'static int mxf_get_essence_container_ul_index(enum CodecID id)\n{\n    int i;\n    for (i = 0; i < sizeof(mxf_essence_container_uls)/\n                    sizeof(*mxf_essence_container_uls); i++)\n        if (mxf_essence_container_uls[i].id == id)\n            return i;\n    return -1;\n}']