From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <ffmpeg-devel-bounces@ffmpeg.org>
Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100])
	by master.gitmailbox.com (Postfix) with ESMTPS id F2C334E0A0
	for <ffmpegdev@gitmailbox.com>; Sun, 27 Apr 2025 18:29:25 +0000 (UTC)
Received: from [127.0.1.1] (localhost [127.0.0.1])
	by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 2E16B68B118;
	Sun, 27 Apr 2025 21:29:20 +0300 (EEST)
Received: from mail-wr1-f46.google.com (mail-wr1-f46.google.com
 [209.85.221.46])
 by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 463FE687DBE
 for <ffmpeg-devel@ffmpeg.org>; Sun, 27 Apr 2025 21:29:13 +0300 (EEST)
Received: by mail-wr1-f46.google.com with SMTP id
 ffacd0b85a97d-39c13fa05ebso2576468f8f.0
 for <ffmpeg-devel@ffmpeg.org>; Sun, 27 Apr 2025 11:29:13 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=jkqxz-net.20230601.gappssmtp.com; s=20230601; t=1745778552; x=1746383352;
 darn=ffmpeg.org; 
 h=content-transfer-encoding:in-reply-to:from:references:to
 :content-language:subject:user-agent:mime-version:date:message-id
 :from:to:cc:subject:date:message-id:reply-to;
 bh=9a9EYgKQ7fAqoGfs8gYR9c4Ykmwie7IdiQs+/GViRRA=;
 b=Azk/p+y5kcAtTh221bu7uVHAgiC8EWAzor4Xqi6OJ5tXfhA+Pz99OSYz43X4Azxe4X
 LWWuw4GMO/M/fJH0PvsqGpJf1AkJLU0U2ZkSs2At7FsZmLQvQMxCE5vYiJ8b+PycZrPC
 z3oJKb4LsP6OZQBnrQ+D2hu05ewpz2PTs0qVsfNJ4F7YX111M5ZDIWfUqvfyTkYQALol
 uLVLI5Jj6+mjLdLa22Pg/F7t4vb25YClUb1Yu6yxNjYTwujuCaM+i4jDc8qkh+CsOzZj
 qi6BagRln4maACEOUkxoxdFaV3FJ0DBP/XiPQe+7ML8jqJ9Pit/zFHCW+h6lQwPZWQqR
 LyUg==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=1e100.net; s=20230601; t=1745778552; x=1746383352;
 h=content-transfer-encoding:in-reply-to:from:references:to
 :content-language:subject:user-agent:mime-version:date:message-id
 :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to;
 bh=9a9EYgKQ7fAqoGfs8gYR9c4Ykmwie7IdiQs+/GViRRA=;
 b=NB9+i8RcI9XDdzVZ4XeBcMuRHFHVxTz6+fEbWWrURYtKkBAnoSy/e3BLKeFPqkEMvB
 GKjEFf44o/7uicJF92TCTcbkf1xYqy9QKDDEy6188oCRz8zlLI9QFgWxJfiUy/SFX9SN
 0qUaOkbX9r4Eu2EGr/3U/Ou/MYD31OYP3MPKe85vwA2irQzsshMNutRPcrIk+eWxmVRp
 Cr+np/XW/IDxysqB4WViOMrBGWwLp8S1qaGUps6oeXOH9cebNPrrPM6AERq821rcsOnA
 7CGZkSNGRx1OskIIU2kGWTE/yvx3WuIJO04hw+dmtPsU8k5ijmtxNAI0tX1DdSwc/gOb
 HPMQ==
X-Gm-Message-State: AOJu0YzkLTD9+RvFhmuIaQkUdV15zXx6+sNV2tgjSk5h+/a7iY6dZzxS
 HTbLzbwxLIt0xzpJIgVJD5NroKjcaUOmirebq/D5xcGRK5PCaJNQhSommDPP5fFqe1k6tVfVlsy
 hUp0HrQ==
X-Gm-Gg: ASbGnctIBOyeHR117YVBc+HzeQzrYhApmsclL74qsNvisT9nFTF/tUuXENdvEbnFug2
 gOPNZfpSuuyf9rtWElliu4cnF+AdRJP1MBXW4B8Iv2zeRPWjALlIlPFQP49n4dV+zZ0YYLmHK46
 yK3w6/iaGFCG55K25BQod2nk/Ety5vgoHqlRubkDJcaGLPcKyoKzIpnORCh0sG54w0EEaGLFBfB
 G0eYhXKqxwzrJJ07ganSK47rzAUcT9BO1HJMRulEbWcNUXTTnnm1crZryr7iYZEy+202wL7jKki
 4K69Pqiw7IjP8vf/eF67eB2QTcWQ7maWARHpak+15oFCF5nUQ+tW66a0Gd+5EpU49tWc0NE+dCI
 auKoVX9XYB+xaCw==
X-Google-Smtp-Source: AGHT+IEU36+ZINAY9cbU4O0HYe6xjCEdY6Sh/QaD2OmGehddB0ycGB+z/CTb74u5hEFN8UJ4z5Pk5Q==
X-Received: by 2002:a05:6000:1844:b0:391:4ca:490 with SMTP id
 ffacd0b85a97d-3a07aa77255mr4435427f8f.29.1745778551813; 
 Sun, 27 Apr 2025 11:29:11 -0700 (PDT)
Received: from [192.168.0.15]
 (cpc92320-cmbg19-2-0-cust719.5-4.cable.virginm.net. [82.13.66.208])
 by smtp.gmail.com with ESMTPSA id
 ffacd0b85a97d-3a073e5e1c6sm9146199f8f.98.2025.04.27.11.29.11
 for <ffmpeg-devel@ffmpeg.org>
 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128);
 Sun, 27 Apr 2025 11:29:11 -0700 (PDT)
Message-ID: <4c8f0045-58ac-4c18-8d33-6044ff9233a9@jkqxz.net>
Date: Sun, 27 Apr 2025 19:29:06 +0100
MIME-Version: 1.0
User-Agent: Mozilla Thunderbird
Content-Language: en-US
To: ffmpeg-devel@ffmpeg.org
References: <20250427175302.8777-1-jamrial@gmail.com>
From: Mark Thompson <sw@jkqxz.net>
In-Reply-To: <20250427175302.8777-1-jamrial@gmail.com>
Subject: Re: [FFmpeg-devel] [PATCH] avformat/apvdec: export color information
X-BeenThere: ffmpeg-devel@ffmpeg.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: FFmpeg development discussions and patches <ffmpeg-devel.ffmpeg.org>
List-Unsubscribe: <https://ffmpeg.org/mailman/options/ffmpeg-devel>,
 <mailto:ffmpeg-devel-request@ffmpeg.org?subject=unsubscribe>
List-Archive: <https://ffmpeg.org/pipermail/ffmpeg-devel>
List-Post: <mailto:ffmpeg-devel@ffmpeg.org>
List-Help: <mailto:ffmpeg-devel-request@ffmpeg.org?subject=help>
List-Subscribe: <https://ffmpeg.org/mailman/listinfo/ffmpeg-devel>,
 <mailto:ffmpeg-devel-request@ffmpeg.org?subject=subscribe>
Reply-To: FFmpeg development discussions and patches <ffmpeg-devel@ffmpeg.org>
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: 7bit
Errors-To: ffmpeg-devel-bounces@ffmpeg.org
Sender: "ffmpeg-devel" <ffmpeg-devel-bounces@ffmpeg.org>
Archived-At: <https://master.gitmailbox.com/ffmpegdev/4c8f0045-58ac-4c18-8d33-6044ff9233a9@jkqxz.net/>
List-Archive: <https://master.gitmailbox.com/ffmpegdev/>
List-Post: <mailto:ffmpegdev@gitmailbox.com>

On 27/04/2025 18:53, James Almer wrote:
> apv_read_header() reads enough information that the generic demux code doesn't
> attempt to read a frame to fill missing fields in codecpar, so make sure it's
> set here.
> 
> Signed-off-by: James Almer <jamrial@gmail.com>
> ---
>  libavformat/apvdec.c | 32 +++++++++++++++++++++++++++++---
>  1 file changed, 29 insertions(+), 3 deletions(-)
> 
> diff --git a/libavformat/apvdec.c b/libavformat/apvdec.c
> index e1ac34b003..94d2ce9965 100644
> --- a/libavformat/apvdec.c
> +++ b/libavformat/apvdec.c
> @@ -39,6 +39,11 @@ typedef struct APVHeaderInfo {
>      uint8_t  chroma_format_idc;
>      uint8_t  bit_depth_minus8;
>  
> +    int      color_primaries;
> +    int      transfer_characteristics;
> +    int      matrix_coefficients;
> +    int      full_range_flag;
> +
>      enum AVPixelFormat pixel_format;
>  } APVHeaderInfo;
>  
> @@ -55,6 +60,8 @@ static int apv_extract_header_info(APVHeaderInfo *info,
>  {
>      int zero, byte, bit_depth_index;
>  
> +    memset(info, 0, sizeof(*info));
> +
>      info->pbu_type = bytestream2_get_byte(gbc);
>      info->group_id = bytestream2_get_be16(gbc);
>  
> @@ -107,10 +114,24 @@ static int apv_extract_header_info(APVHeaderInfo *info,
>      // Ignore capture_time_distance.
>      bytestream2_skip(gbc, 1);
>  
> -    zero = bytestream2_get_byte(gbc);
> -    if (zero != 0)
> +    // two reserved_zero_8bits
> +    if (bytestream2_get_be16(gbc) != 0)
>          return AVERROR_INVALIDDATA;
>  
> +    // color_description_present_flag
> +    if (bytestream2_peek_byte(gbc) >> 7) {
> +        // We can read 32 bits as tile info is guaranteed to be present after this.
> +        unsigned color_description = bytestream2_get_be32(gbc);
> +
> +        if (bytestream2_get_bytes_left(gbc) <= 0)
> +            return AVERROR_INVALIDDATA;
> +
> +        info->color_primaries          = (color_description >> 23) & 0xff;
> +        info->transfer_characteristics = (color_description >> 15) & 0xff;
> +        info->matrix_coefficients      = (color_description >>  7) & 0xff;

For these "unspecified" has value 2, which will need to be set somewhere in no-description case rather than zero-init.  (Matrix coefficients 0 means identity, i.e. RGB, which we definitely don't want.)

> +        info->full_range_flag          = (color_description >>  6) & 1;
> +    }
> +
>      return 1;
>  }
>  
> @@ -157,7 +178,7 @@ static int apv_read_header(AVFormatContext *s)
>      AVStream *st;
>      GetByteContext gbc;
>      APVHeaderInfo header;
> -    uint8_t buffer[28];
> +    uint8_t buffer[64];

Could be smaller, but doesn't really matter.

>      uint32_t au_size, signature, pbu_size;
>      int err, size;
>  
> @@ -201,6 +222,11 @@ static int apv_read_header(AVFormatContext *s)
>      st->codecpar->level      = header.level_idc;
>      st->codecpar->width      = header.frame_width;
>      st->codecpar->height     = header.frame_height;
> +    st->codecpar->color_primaries = header.color_primaries;
> +    st->codecpar->color_trc       = header.transfer_characteristics;
> +    st->codecpar->color_space     = header.matrix_coefficients;
> +    st->codecpar->color_range     = header.full_range_flag ? AVCOL_RANGE_JPEG
> +                                                           : AVCOL_RANGE_MPEG;

Suggest st->codecpar->chroma_location = AVCHROMA_LOC_TOPLEFT as well?

>  
>      st->avg_frame_rate = (AVRational){ 30, 1 };
>      avpriv_set_pts_info(st, 64, 1, 30);

Thanks,

- Mark

_______________________________________________
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".