From patchwork Thu Feb 29 16:43:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Jan_Ekstr=C3=B6m?= X-Patchwork-Id: 46671 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:a919:b0:19e:cdac:8cce with SMTP id cd25csp720770pzb; Thu, 29 Feb 2024 08:45:50 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCWrF498jxe9mH9rUpjixih2ohvLpoJlUGbmqP+qqC2WqMCp7wNqZ0WoT1ykEZdOSMqg7OJdyASPbn5srsYWNBKO7lJelirSY1pltw== X-Google-Smtp-Source: AGHT+IFaDSWBp7y0kPBWLOInFpjIKd+5L5Z/XI5saj+6ZzLYB+3MOay+gpCiZ0opOTZFSGGrJHmX X-Received: by 2002:a17:906:3bc9:b0:a44:27e8:f514 with SMTP id v9-20020a1709063bc900b00a4427e8f514mr1908938ejf.38.1709225150154; Thu, 29 Feb 2024 08:45:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1709225150; cv=none; d=google.com; s=arc-20160816; b=tGiin9PW33Wtn2CY8WNLAZPTOLDJXkLcfIXR4I2HTTsZWIOpEBiM2PSzmYLStp++1s WcP9/9fQ0/A4efYyA2D8fFUvSoOpRF2+YNJTD8jaeRaYnpAWBIXIrObBnfSNYG6djNPI LLo50emV6SReup5AUUzov3haaqZzCEQiv9AZuEkF9I+2mTJu45k1kcm1RUI8DYn6XvX7 rm+7H3Kv809g10eBTpgP93g/ZwL2j8TufyHHVHRAV0hb1WRTFbwp8RliseuQUoTfYu6G mxh/lX/x/EhtsoEz0tnqfGggSBZA0c4Ln899Lhl1nTNfReSt+riHb/egD/emLC2N0yoA wDiw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:reply-to:list-subscribe :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:subject:mime-version:references:in-reply-to:message-id :date:to:from:dkim-signature:delivered-to; bh=juJkf1nOIwRytMh845McKyguLx9HwJaYyjzIcPoNoQo=; fh=YOA8vD9MJZuwZ71F/05pj6KdCjf6jQRmzLS+CATXUQk=; b=s7cZQ1ZHhL6mR262UVQTbpYSg1z9BIy1cEBRKfXvje+aUHdeXVGHmmR8lP99ceox9u gxm3PU0VXDcyhSbXPcj8QiBCnjn+Hb1zzWE01rlMrcGj3A9UU1tahFelDGx3MYsvm5w/ ZYnKMRCO//nZQFueW0tAdnBY/k5vxIEeAotPDG9vTmK5B7UPszBwOND1300bePIYYjlQ rkjbx9qFj9IT9iC65sXYDgY4Bgj7/6kmkNSyKqAFv1d7NLn/TD1UfUlKKf8B6eHQeDZo Kz7IIGPQ2anfTWirbLQzEkA9DzS06XPELq8kXag7WosWNgFWJm7Wri6/62nLJKkayboi zCVA==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20230601 header.b="ibpVJ/fq"; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id dt19-20020a170906b79300b00a441db594e6si706282ejb.643.2024.02.29.08.45.49; Thu, 29 Feb 2024 08:45:50 -0800 (PST) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20230601 header.b="ibpVJ/fq"; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 135DC68D1D3; Thu, 29 Feb 2024 18:43:40 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-lf1-f49.google.com (mail-lf1-f49.google.com [209.85.167.49]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 14B9468D1ED for ; Thu, 29 Feb 2024 18:43:25 +0200 (EET) Received: by mail-lf1-f49.google.com with SMTP id 2adb3069b0e04-512e39226efso1025280e87.0 for ; Thu, 29 Feb 2024 08:43:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1709225004; x=1709829804; darn=ffmpeg.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=eU/Egidg47lse2opH38KEQErmULRanxbj+eMGNOl9A8=; b=ibpVJ/fqEntSR/VO2GU3hKI0MfiIQsNOIz1PECCwMc8XExYyUGYNzQ8PsVNXl3I1ah T71TMeHwUcNwf2Ny4YZqJmsjMXHynWxtkA201YMJZtkSeOuF3fYe+yOAfMmumDkVJW0L UHczLFpeMAfrPe7bXROk97yJCEPdJHnH9H3GjlJOUbtQtlcH8FOE3OEZ8q2vVJ5y1gtT A0D8j1sp8qXAznQn55vhIRjx+hyt2i1AzNX3vABNURHgqotWv27vxR+1TONSIQpwFl8e RPrLYl40Mzex5qpjotqkYvx4NO6LRoqCqjOdSjtiDMno9TXXs5hsCneCKMNcoCGqfYm6 DgvQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709225004; x=1709829804; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=eU/Egidg47lse2opH38KEQErmULRanxbj+eMGNOl9A8=; b=VJH6pBG318NBwpwqQeD4MJDrspDsA4nc9dFU7QO2+2kCiDdLssydxPbTPRNxZjwcoP fxrYovn/wQK0b3zfxOHy1Nuc1SWfBW5RCAYjpJvxSSmaRI+wnxJxAgrPyhohuiY5zWsx qtftpUWwKH3phzVQ8wBiD5y2T3s6lz1rD0gbo9EDk14qPUoOpBZJNs04+y1Fz919fhgy 5aVwIh66+FRduMiTna0AVUpaVx6LkpLvT4a24wI3jQAoh+fJWl1e7Nh/Omup007qQ2Z7 hgdpcqlc7pWaVRo4RsjZv6rFDzDXKYOOaM5vrZIm7Cb+wjqC1gHMRG9+5izymdVV+5rE sAPA== X-Gm-Message-State: AOJu0YxL2zmGgNSKbhRq/aDrIL26otlNsWxA2O+YrFJCK56uUpkRFxJi NsvKMZiTM67pYvY1TjkTzjLRXEbPKwQs58T2Jx52gF5ZuA6iQLphmUf/oUOL X-Received: by 2002:a05:6512:3493:b0:512:ed78:a840 with SMTP id v19-20020a056512349300b00512ed78a840mr1631731lfr.61.1709225004163; Thu, 29 Feb 2024 08:43:24 -0800 (PST) Received: from localhost.localdomain (91-153-198-187.elisa-laajakaista.fi. [91.153.198.187]) by smtp.gmail.com with ESMTPSA id k6-20020ac24566000000b00513290734cbsm206248lfm.292.2024.02.29.08.43.23 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 29 Feb 2024 08:43:23 -0800 (PST) From: =?utf-8?q?Jan_Ekstr=C3=B6m?= To: ffmpeg-devel@ffmpeg.org Date: Thu, 29 Feb 2024 18:43:01 +0200 Message-ID: <20240229164307.3535613-15-jeebjp@gmail.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240229164307.3535613-1-jeebjp@gmail.com> References: <20240229164307.3535613-1-jeebjp@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v7 14/14] avcodec/libx265: add support for writing out CLL and MDCV X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: sd2Q4JUXk/W2 The newer of these two are the separate integers for content light level, introduced in 3952bf3e98c76c31594529a3fe34e056d3e3e2ea , with X265_BUILD 75. As we already require X265_BUILD of at least 89, no further conditions are required. --- libavcodec/libx265.c | 88 ++++++++++++++++++++++++++++++++++++ tests/fate/enc_external.mak | 5 ++ tests/ref/fate/libx265-hdr10 | 16 +++++++ 3 files changed, 109 insertions(+) create mode 100644 tests/ref/fate/libx265-hdr10 diff --git a/libavcodec/libx265.c b/libavcodec/libx265.c index 447e6da25f..8d366f51ab 100644 --- a/libavcodec/libx265.c +++ b/libavcodec/libx265.c @@ -28,9 +28,11 @@ #include #include "libavutil/avassert.h" +#include "libavutil/bprint.h" #include "libavutil/buffer.h" #include "libavutil/internal.h" #include "libavutil/common.h" +#include "libavutil/mastering_display_metadata.h" #include "libavutil/opt.h" #include "libavutil/pixdesc.h" #include "avcodec.h" @@ -179,6 +181,85 @@ static av_cold int libx265_param_parse_int(AVCodecContext *avctx, return 0; } +static int handle_mdcv(const AVClass **avcl, const x265_api *api, + x265_param *params, + const AVMasteringDisplayMetadata *mdcv) +{ + int ret = AVERROR_BUG; + AVBPrint buf; + av_bprint_init(&buf, 0, AV_BPRINT_SIZE_AUTOMATIC); + + // G(%hu,%hu)B(%hu,%hu)R(%hu,%hu)WP(%hu,%hu)L(%u,%u) + av_bprintf( + &buf, + "G(%"PRId64",%"PRId64")B(%"PRId64",%"PRId64")R(%"PRId64",%"PRId64")" + "WP(%"PRId64",%"PRId64")L(%"PRId64",%"PRId64")", + av_rescale_q(1, mdcv->display_primaries[1][0], (AVRational){ 1, 50000 }), + av_rescale_q(1, mdcv->display_primaries[1][1], (AVRational){ 1, 50000 }), + av_rescale_q(1, mdcv->display_primaries[2][0], (AVRational){ 1, 50000 }), + av_rescale_q(1, mdcv->display_primaries[2][1], (AVRational){ 1, 50000 }), + av_rescale_q(1, mdcv->display_primaries[0][0], (AVRational){ 1, 50000 }), + av_rescale_q(1, mdcv->display_primaries[0][1], (AVRational){ 1, 50000 }), + av_rescale_q(1, mdcv->white_point[0], (AVRational){ 1, 50000 }), + av_rescale_q(1, mdcv->white_point[1], (AVRational){ 1, 50000 }), + av_rescale_q(1, mdcv->max_luminance, (AVRational){ 1, 10000 }), + av_rescale_q(1, mdcv->min_luminance, (AVRational){ 1, 10000 })); + + if (!av_bprint_is_complete(&buf)) { + av_log(avcl, AV_LOG_ERROR, + "MDCV string too long for its available space!\n"); + ret = AVERROR(ENOMEM); + goto end; + } + + if (api->param_parse(params, "master-display", buf.str) == + X265_PARAM_BAD_VALUE) { + av_log(avcl, AV_LOG_ERROR, + "Invalid value \"%s\" for param \"master-display\".\n", + buf.str); + ret = AVERROR(EINVAL); + goto end; + } + + ret = 0; + +end: + av_bprint_finalize(&buf, NULL); + + return ret; +} + +static int handle_side_data(AVCodecContext *avctx, const x265_api *api, + x265_param *params) +{ + const AVFrameSideData *cll_sd = + av_frame_side_data_get( + (const AVFrameSideData **)avctx->frame_side_data, + avctx->nb_frame_side_data, AV_FRAME_DATA_CONTENT_LIGHT_LEVEL); + const AVFrameSideData *mdcv_sd = + av_frame_side_data_get( + (const AVFrameSideData **)avctx->frame_side_data, + avctx->nb_frame_side_data, AV_FRAME_DATA_MASTERING_DISPLAY_METADATA); + + if (cll_sd) { + const AVContentLightMetadata *cll = + (AVContentLightMetadata *)cll_sd->data; + + params->maxCLL = cll->MaxCLL; + params->maxFALL = cll->MaxFALL; + } + + if (mdcv_sd) { + int ret = handle_mdcv( + &avctx->av_class, api, params, + (AVMasteringDisplayMetadata *)mdcv_sd->data); + if (ret < 0) + return ret; + } + + return 0; +} + static av_cold int libx265_encode_init(AVCodecContext *avctx) { libx265Context *ctx = avctx->priv_data; @@ -339,6 +420,13 @@ FF_ENABLE_DEPRECATION_WARNINGS return AVERROR_BUG; } + ret = handle_side_data(avctx, ctx->api, ctx->params); + if (ret < 0) { + av_log(avctx, AV_LOG_ERROR, "Failed handling side data! (%s)\n", + av_err2str(ret)); + return ret; + } + if (ctx->crf >= 0) { char crf[6]; diff --git a/tests/fate/enc_external.mak b/tests/fate/enc_external.mak index 4095a4b51a..30021efbcd 100644 --- a/tests/fate/enc_external.mak +++ b/tests/fate/enc_external.mak @@ -12,5 +12,10 @@ FATE_ENC_EXTERNAL-$(call ENCDEC, LIBX264 HEVC, MOV, LIBX264_HDR10 HEVC_DEMUXER H fate-libx264-hdr10: CMD = enc_external $(TARGET_SAMPLES)/hevc/hdr10_plus_h265_sample.hevc \ mp4 "-c:v libx264" "-show_frames -show_entries frame=side_data_list -of flat" +# test for x265 MDCV and CLL passthrough during encoding +FATE_ENC_EXTERNAL-$(call ENCDEC, LIBX265 HEVC, MOV, HEVC_DEMUXER) += fate-libx265-hdr10 +fate-libx265-hdr10: CMD = enc_external $(TARGET_SAMPLES)/hevc/hdr10_plus_h265_sample.hevc \ + mp4 "-c:v libx265" "-show_frames -show_entries frame=side_data_list -of flat" + FATE_SAMPLES_FFMPEG_FFPROBE += $(FATE_ENC_EXTERNAL-yes) fate-enc-external: $(FATE_ENC_EXTERNAL-yes) diff --git a/tests/ref/fate/libx265-hdr10 b/tests/ref/fate/libx265-hdr10 new file mode 100644 index 0000000000..571c837cac --- /dev/null +++ b/tests/ref/fate/libx265-hdr10 @@ -0,0 +1,16 @@ +frames.frame.0.side_data_list.side_data.0.side_data_type="H.26[45] User Data Unregistered SEI message" +frames.frame.0.side_data_list.side_data.1.side_data_type="H.26[45] User Data Unregistered SEI message" +frames.frame.0.side_data_list.side_data.2.side_data_type="Mastering display metadata" +frames.frame.0.side_data_list.side_data.2.red_x="13250/50000" +frames.frame.0.side_data_list.side_data.2.red_y="34500/50000" +frames.frame.0.side_data_list.side_data.2.green_x="7500/50000" +frames.frame.0.side_data_list.side_data.2.green_y="3000/50000" +frames.frame.0.side_data_list.side_data.2.blue_x="34000/50000" +frames.frame.0.side_data_list.side_data.2.blue_y="16000/50000" +frames.frame.0.side_data_list.side_data.2.white_point_x="15635/50000" +frames.frame.0.side_data_list.side_data.2.white_point_y="16450/50000" +frames.frame.0.side_data_list.side_data.2.min_luminance="50/10000" +frames.frame.0.side_data_list.side_data.2.max_luminance="10000000/10000" +frames.frame.0.side_data_list.side_data.3.side_data_type="Content light level metadata" +frames.frame.0.side_data_list.side_data.3.max_content=1000 +frames.frame.0.side_data_list.side_data.3.max_average=200