int vmaf_write_output_xml()

in libvmaf/src/output.c [67:158]


int vmaf_write_output_xml(VmafContext *vmaf, VmafFeatureCollector *fc,
                          FILE *outfile, unsigned subsample, unsigned width,
                          unsigned height, double fps, unsigned pic_cnt)
{
    if (!vmaf) return -EINVAL;
    if (!fc) return -EINVAL;
    if (!outfile) return -EINVAL;

    fprintf(outfile, "<VMAF version=\"%s\">\n", vmaf_version());
    fprintf(outfile, "  <params qualityWidth=\"%d\" qualityHeight=\"%d\" />\n",
            width, height);
    fprintf(outfile, "  <fyi fps=\"%.2f\" />\n", fps);

    unsigned n_frames = 0;
    int leading_zeros_count;
    fprintf(outfile, "  <frames>\n");
    for (unsigned i = 0 ; i < max_capacity(fc); i++) {
        if ((subsample > 1) && (i % subsample))
            continue;

        unsigned cnt = 0;
        for (unsigned j = 0; j < fc->cnt; j++) {
            if (i > fc->feature_vector[j]->capacity)
                continue;
            if (fc->feature_vector[j]->score[i].written)
                cnt++;
        }
        if (!cnt) continue;

        fprintf(outfile, "    <frame frameNum=\"%d\" ", i);
        for (unsigned j = 0; j < fc->cnt; j++) {
            if (i > fc->feature_vector[j]->capacity)
                continue;
            if (!fc->feature_vector[j]->score[i].written)
                continue;
            leading_zeros_count = count_leading_zeros_d(fc->feature_vector[j]->score[i].value);
            if (leading_zeros_count <= 6)
                fprintf(outfile, "%s=\"%.6f\" ",
                    vmaf_feature_name_alias(fc->feature_vector[j]->name),
                    fc->feature_vector[j]->score[i].value);
            else
                fprintf(outfile, "%s=\"%.16f\" ",
                    vmaf_feature_name_alias(fc->feature_vector[j]->name),
                    fc->feature_vector[j]->score[i].value);
        }
        n_frames++;
        fprintf(outfile, "/>\n");
    }
    fprintf(outfile, "  </frames>\n");

    fprintf(outfile, "  <pooled_metrics>\n");
    for (unsigned i = 0; i < fc->cnt; i++) {
        const char *feature_name = fc->feature_vector[i]->name;
        fprintf(outfile, "    <metric name=\"%s\" ",
                vmaf_feature_name_alias(feature_name));

        for (unsigned j = 1; j < VMAF_POOL_METHOD_NB; j++) {
            double score;
            int err = vmaf_feature_score_pooled(vmaf, feature_name, j, &score,
                                                0, pic_cnt - 1);
            if (!err)
            {
                leading_zeros_count = count_leading_zeros_d(score);
                if (leading_zeros_count <= 6)
                    fprintf(outfile, "%s=\"%.6f\" ", pool_method_name[j], score);
                else
                    fprintf(outfile, "%s=\"%.16f\" ", pool_method_name[j], score);
            }
        }
        fprintf(outfile, "/>\n");
    }
    fprintf(outfile, "  </pooled_metrics>\n");


    fprintf(outfile, "  <aggregate_metrics ");
    for (unsigned i = 0; i < fc->aggregate_vector.cnt; i++) {
        leading_zeros_count = count_leading_zeros_d(fc->aggregate_vector.metric[i].value);
        if (leading_zeros_count <= 6)
            fprintf(outfile, "%s=\"%.6f\" ",
                fc->aggregate_vector.metric[i].name,
                fc->aggregate_vector.metric[i].value);
        else
            fprintf(outfile, "%s=\"%.16f\" ",
                fc->aggregate_vector.metric[i].name,
                fc->aggregate_vector.metric[i].value);
    }
    fprintf(outfile, "/>\n");

    fprintf(outfile, "</VMAF>\n");

    return 0;
}