1
0
mirror of https://github.com/FFmpeg/FFmpeg.git synced 2024-11-21 10:55:51 +02:00

avfilter/vf_showinfo: add support for HDR10+ metadata

Signed-off-by: James Almer <jamrial@gmail.com>
This commit is contained in:
Mohammad Izadi 2020-11-23 13:29:35 -08:00 committed by James Almer
parent afbc6852b4
commit 6f2d6e3efd

View File

@ -24,6 +24,7 @@
#include <inttypes.h>
#include "libavcodec/dynamic_hdr10_plus.h"
#include "libavutil/bswap.h"
#include "libavutil/adler32.h"
#include "libavutil/display.h"
@ -178,7 +179,107 @@ static void dump_mastering_display(AVFilterContext *ctx, const AVFrameSideData *
av_q2d(mastering_display->min_luminance), av_q2d(mastering_display->max_luminance));
}
static void dump_content_light_metadata(AVFilterContext *ctx, const AVFrameSideData *sd)
static void dump_dynamic_hdr_plus(AVFilterContext *ctx, AVFrameSideData *sd)
{
AVDynamicHDRPlus *hdr_plus;
av_log(ctx, AV_LOG_INFO, "HDR10+ metadata: ");
if (sd->size < sizeof(*hdr_plus)) {
av_log(ctx, AV_LOG_ERROR, "invalid data\n");
return;
}
hdr_plus = (AVDynamicHDRPlus *)sd->data;
av_log(ctx, AV_LOG_INFO, "application version: %d, ", hdr_plus->application_version);
av_log(ctx, AV_LOG_INFO, "num_windows: %d, ", hdr_plus->num_windows);
for (int w = 1; w < hdr_plus->num_windows; w++) {
AVHDRPlusColorTransformParams *params = &hdr_plus->params[w];
av_log(ctx, AV_LOG_INFO, "window %d { ", w);
av_log(ctx, AV_LOG_INFO, "window_upper_left_corner: (%5.4f,%5.4f),",
av_q2d(params->window_upper_left_corner_x),
av_q2d(params->window_upper_left_corner_y));
av_log(ctx, AV_LOG_INFO, "window_lower_right_corner: (%5.4f,%5.4f), ",
av_q2d(params->window_lower_right_corner_x),
av_q2d(params->window_lower_right_corner_y));
av_log(ctx, AV_LOG_INFO, "window_upper_left_corner: (%5.4f, %5.4f), ",
av_q2d(params->window_upper_left_corner_x),
av_q2d(params->window_upper_left_corner_y));
av_log(ctx, AV_LOG_INFO, "center_of_ellipse_x: (%d,%d), ",
params->center_of_ellipse_x,
params->center_of_ellipse_y);
av_log(ctx, AV_LOG_INFO, "rotation_angle: %d, ",
params->rotation_angle);
av_log(ctx, AV_LOG_INFO, "semimajor_axis_internal_ellipse: %d, ",
params->semimajor_axis_internal_ellipse);
av_log(ctx, AV_LOG_INFO, "semimajor_axis_external_ellipse: %d, ",
params->semimajor_axis_external_ellipse);
av_log(ctx, AV_LOG_INFO, "semiminor_axis_external_ellipse: %d, ",
params->semiminor_axis_external_ellipse);
av_log(ctx, AV_LOG_INFO, "overlap_process_option: %d}, ",
params->overlap_process_option);
}
av_log(ctx, AV_LOG_INFO, "targeted_system_display_maximum_luminance: %9.4f, ",
av_q2d(hdr_plus->targeted_system_display_maximum_luminance));
if (hdr_plus->targeted_system_display_actual_peak_luminance_flag) {
av_log(ctx, AV_LOG_INFO, "targeted_system_display_actual_peak_luminance: {");
for (int i = 0; i < hdr_plus->num_rows_targeted_system_display_actual_peak_luminance; i++) {
av_log(ctx, AV_LOG_INFO, "(");
for (int j = 0; j < hdr_plus->num_cols_targeted_system_display_actual_peak_luminance; j++) {
av_log(ctx, AV_LOG_INFO, "%5.4f,",
av_q2d(hdr_plus->targeted_system_display_actual_peak_luminance[i][j]));
}
av_log(ctx, AV_LOG_INFO, ")");
}
av_log(ctx, AV_LOG_INFO, "}, ");
}
for (int w = 0; w < hdr_plus->num_windows; w++) {
AVHDRPlusColorTransformParams *params = &hdr_plus->params[w];
av_log(ctx, AV_LOG_INFO, "window %d {maxscl: {", w);
for (int i = 0; i < 3; i++) {
av_log(ctx, AV_LOG_INFO, "%5.4f,",av_q2d(params->maxscl[i]));
}
av_log(ctx, AV_LOG_INFO, "} average_maxrgb: %5.4f, ",
av_q2d(params->average_maxrgb));
av_log(ctx, AV_LOG_INFO, "distribution_maxrgb: {");
for (int i = 0; i < params->num_distribution_maxrgb_percentiles; i++) {
av_log(ctx, AV_LOG_INFO, "(%d,%5.4f)",
params->distribution_maxrgb[i].percentage,
av_q2d(params->distribution_maxrgb[i].percentile));
}
av_log(ctx, AV_LOG_INFO, "} fraction_bright_pixels: %5.4f, ",
av_q2d(params->fraction_bright_pixels));
if (params->tone_mapping_flag) {
av_log(ctx, AV_LOG_INFO, "knee_point: (%5.4f,%5.4f), ", av_q2d(params->knee_point_x), av_q2d(params->knee_point_y));
av_log(ctx, AV_LOG_INFO, "bezier_curve_anchors: {");
for (int i = 0; i < params->num_bezier_curve_anchors; i++) {
av_log(ctx, AV_LOG_INFO, "%5.4f,",
av_q2d(params->bezier_curve_anchors[i]));
}
av_log(ctx, AV_LOG_INFO, "} ");
}
if (params->color_saturation_mapping_flag) {
av_log(ctx, AV_LOG_INFO, "color_saturation_weight: %5.4f",
av_q2d(params->color_saturation_weight));
}
av_log(ctx, AV_LOG_INFO, "} ");
}
if (hdr_plus->mastering_display_actual_peak_luminance_flag) {
av_log(ctx, AV_LOG_INFO, "mastering_display_actual_peak_luminance: {");
for (int i = 0; i < hdr_plus->num_rows_mastering_display_actual_peak_luminance; i++) {
av_log(ctx, AV_LOG_INFO, "(");
for (int j = 0; j < hdr_plus->num_cols_mastering_display_actual_peak_luminance; j++) {
av_log(ctx, AV_LOG_INFO, " %5.4f,",
av_q2d(hdr_plus->mastering_display_actual_peak_luminance[i][j]));
}
av_log(ctx, AV_LOG_INFO, ")");
}
av_log(ctx, AV_LOG_INFO, "} ");
}
}
static void dump_content_light_metadata(AVFilterContext *ctx, AVFrameSideData *sd)
{
const AVContentLightMetadata *metadata = (const AVContentLightMetadata *)sd->data;
@ -396,6 +497,9 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *frame)
case AV_FRAME_DATA_MASTERING_DISPLAY_METADATA:
dump_mastering_display(ctx, sd);
break;
case AV_FRAME_DATA_DYNAMIC_HDR_PLUS:
dump_dynamic_hdr_plus(ctx, sd);
break;
case AV_FRAME_DATA_CONTENT_LIGHT_LEVEL:
dump_content_light_metadata(ctx, sd);
break;