From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTP id 9545343803 for ; Wed, 29 Jun 2022 07:50:53 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 8EA0868B761; Wed, 29 Jun 2022 10:50:50 +0300 (EEST) Received: from mail-lf1-f54.google.com (mail-lf1-f54.google.com [209.85.167.54]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id AE46268B056 for ; Wed, 29 Jun 2022 10:50:43 +0300 (EEST) Received: by mail-lf1-f54.google.com with SMTP id a4so12975719lfm.0 for ; Wed, 29 Jun 2022 00:50:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to; bh=B9l/+PbOvmIHow/NgncuFQX5wAK9LpPvW2ipVqhwDhg=; b=DoE6g4YUM9Nbn0wtFxU/psU9P39IBKM8FOEsNvJ26iQxGFNoS65LF5RaMHWKqCzDGW Jr3GNoVHwIms4iILgzyPeDjqRWoUdjj3I5S3Vf/VNFf1BRZINCgy5yUeJKTzYpUCrAJQ ygMD1Ypr4KH1BswV53paoLdIkPjRCBuH8gF9OkIbuwlfDx9CnpTOxBn+6U4yPTJc6HjB LOgC+PECU3ea5MuW2tPPd0bHmw4cdHgiatysg2u37EktZHlTu+V5ZFSK9ufxwGHn2Pr5 IgL3exNpz+yPPxyo0bhwyG8mIg0msOBw38kmQYJjJfIHr6HdXn0YMdIg2aCnJdqg/HZX UA4w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to; bh=B9l/+PbOvmIHow/NgncuFQX5wAK9LpPvW2ipVqhwDhg=; b=z93bYl+oVb7XbgRzZImiRdSh5UwYGTr2stOp9qOhU56vDDoMNMR2tAEtPLHDY6V0b0 NRtGpIaHwLph89QnAvr5LTx58luTyewv1Z7lWEUJ7zHQ0hzbtC3+CNbVrerafW2wp6TX FIyYBG+kqaSUV8SHClCN3iwfmCz80SGG6aXnO/w3lLNaTrqyrgPI+J6E7R45SCJi7S5j mmAwctG1dqMzn55gdSycqGpIXEbB2LGHT+aCZR4SvGaBGctix8MVK3OVCsXBvy7m3SE7 7h8FQkhbn191igNrmOgSA/x3+bevTFrPlzqycc508UQaIIYXjq97Sd9FwiTWsY27ACMX CAVg== X-Gm-Message-State: AJIora8NvPvhVabDyqjpuWe5pTzk0BfyxfOEHUSkDNT8MZhcNzkDwuyP fe0PFTh4ErRqCDLk614iLQ6+KsruDox3/aRt/KdNsylpq1o= X-Google-Smtp-Source: AGRyM1sPXBM7p0hUvNt0QRvm4QqAnnPoxLOGsYlq+c3BjNXAcsv1GrzYKfGMKRG4NSGybMK0Kgu9FkJdBw5jf3xBx70= X-Received: by 2002:a05:6512:118a:b0:47f:93c4:fcb2 with SMTP id g10-20020a056512118a00b0047f93c4fcb2mr1224133lfr.39.1656489042413; Wed, 29 Jun 2022 00:50:42 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Hendrik Leppkes Date: Wed, 29 Jun 2022 09:50:29 +0200 Message-ID: To: FFmpeg development discussions and patches Subject: Re: [FFmpeg-devel] [RFC] Bug in colorspace.c 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 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: On Wed, Jun 29, 2022 at 6:34 AM Hendrik Leppkes wrote: > > On Tue, Jun 28, 2022 at 11:38 PM Soft Works wrote: > > > > Hi, > > > > in colorspace.c, there are two functions with contradicting behavior > > regarding reading/writing the max_luminance value from/to > > AVMasteringDisplayMetadata. The code seems to be unchanged since > > 3 years: > > > > > > 1. ff_determine_signal_peak() > > > > sd = av_frame_get_side_data(in, AV_FRAME_DATA_MASTERING_DISPLAY_METADATA); > > if (!peak && sd) { > > AVMasteringDisplayMetadata *metadata = (AVMasteringDisplayMetadata *)sd->data; > > if (metadata->has_luminance) > > peak = av_q2d(metadata->max_luminance) / REFERENCE_WHITE; > > } > > > > > > 2. ff_update_hdr_metadata() > > > > sd = av_frame_get_side_data(in, AV_FRAME_DATA_MASTERING_DISPLAY_METADATA); > > if (sd) { > > AVMasteringDisplayMetadata *metadata = (AVMasteringDisplayMetadata *)sd->data; > > if (metadata->has_luminance) > > metadata->max_luminance = av_d2q(peak * REFERENCE_WHITE, 10000); > > } > > > > > > The latter function writes the value as an AVRational with a denominator of > > 10000, but the former function doesn't multiply the value by 10000. > > > > These two calls round-trip just fine. The 10000 is not a forced > denominator, divisor, or multiplier, it is the maximum denominator it > is allowed to use to convert the floating point value to a rational. > av_d2q will ensure the value is properly scaled. > To elaborate some more, AVRational is just a number, it has no inherent "base" or "range". An AVRational of 1000/1 or 10000000/10000 represents the same value - 1000, the extra zeros have no meaning and none should be attributed to it. Its just that, a rational value represented as math intended - a fraction. If any code that processes it needs the value in a particular scale, for example the 10000 denominator scale HEVC SEI uses, then it needs to make sure to convert it into that particular scale, as the incoming AVRational makes absolutely no guarantees in that regard. All code currently using eg. max_luminance in ffmpeg seems to do it right. The AVRational is never handled directly, but typically read through av_q2d (to convert it into a real number), or rescaled manually to the base a format expects. So whatever odd values you see somewhere else, its not from FFmpeg. - Hendrik _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".