This is an automated email from the git hooks/post-receive script. Git pushed a commit to branch master in repository ffmpeg.
commit 12dc67b6fe0e25da23cf77fdd60d3678b5e8d956 Author: Lynne <[email protected]> AuthorDate: Sat May 16 17:40:14 2026 +0900 Commit: Lynne <[email protected]> CommitDate: Wed Jun 10 02:38:35 2026 +0900 lavu/frame: add camera raw codec side data Required to correctly present raw video. Codec-specific since I'd like to support ARRIRAW in the future, which has a different format. --- doc/APIchanges | 3 + libavutil/Makefile | 2 + libavutil/frame.h | 7 ++ libavutil/{downmix_info.c => raw_color_params.c} | 32 +++-- libavutil/raw_color_params.h | 147 +++++++++++++++++++++++ libavutil/side_data.c | 1 + libavutil/version.h | 2 +- 7 files changed, 180 insertions(+), 14 deletions(-) diff --git a/doc/APIchanges b/doc/APIchanges index 2fab69f261..baba5918e6 100644 --- a/doc/APIchanges +++ b/doc/APIchanges @@ -2,6 +2,9 @@ The last version increases of all libraries were on 2025-03-28 API changes, most recent first: +2026-06-xx - xxxxxxxxxx - lavu 60.33.100 - frame.h + Add AV_FRAME_DATA_RAW_COLOR_PARAMS. + 2026-06-xx - xxxxxxxxxx - lsws 9.8.100 - swscale.h Add enum SwsBackend and SwsContext.backends diff --git a/libavutil/Makefile b/libavutil/Makefile index aa381c88cb..2e8a5de551 100644 --- a/libavutil/Makefile +++ b/libavutil/Makefile @@ -76,6 +76,7 @@ HEADERS = adler32.h \ pixelutils.h \ pixfmt.h \ random_seed.h \ + raw_color_params.h \ rc4.h \ rational.h \ refstruct.h \ @@ -169,6 +170,7 @@ OBJS = adler32.o \ pixdesc.o \ pixelutils.o \ random_seed.o \ + raw_color_params.o \ rational.o \ refstruct.o \ reverse.o \ diff --git a/libavutil/frame.h b/libavutil/frame.h index e123668124..52adbc6288 100644 --- a/libavutil/frame.h +++ b/libavutil/frame.h @@ -292,6 +292,13 @@ enum AVFrameSideDataType { * and Formats standard. */ AV_FRAME_DATA_IAMF_RECON_GAIN_INFO_PARAM, + + /** + * Color information from a RAW camera codecs, needed to correctly process + * the video data. The payload is an AVRawColorParams struct defined in + * libavutil/raw_color_params.h. + */ + AV_FRAME_DATA_RAW_COLOR_PARAMS, }; enum AVActiveFormatDescription { diff --git a/libavutil/downmix_info.c b/libavutil/raw_color_params.c similarity index 56% copy from libavutil/downmix_info.c copy to libavutil/raw_color_params.c index 7e6c3e854d..7b096fa793 100644 --- a/libavutil/downmix_info.c +++ b/libavutil/raw_color_params.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014 Tim Walker <[email protected]> + * Copyright (c) 2026 Lynne <[email protected]> * * This file is part of FFmpeg. * @@ -18,24 +18,30 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#include "downmix_info.h" -#include "frame.h" +#include "raw_color_params.h" +#include "mem.h" -AVDownmixInfo *av_downmix_info_update_side_data(AVFrame *frame) +AVRawColorParams *av_raw_color_params_alloc(size_t *size) { - AVFrameSideData *side_data; + AVRawColorParams *p = av_mallocz(sizeof(AVRawColorParams)); + if (!p) + return NULL; - side_data = av_frame_get_side_data(frame, AV_FRAME_DATA_DOWNMIX_INFO); + if (size) + *size = sizeof(*p); - if (!side_data) { - side_data = av_frame_new_side_data(frame, AV_FRAME_DATA_DOWNMIX_INFO, - sizeof(AVDownmixInfo)); - if (side_data) - memset(side_data->data, 0, sizeof(AVDownmixInfo)); - } + return p; +} +AVRawColorParams *av_raw_color_params_create_side_data(AVFrame *frame) +{ + AVFrameSideData *side_data = + av_frame_new_side_data(frame, AV_FRAME_DATA_RAW_COLOR_PARAMS, + sizeof(AVRawColorParams)); if (!side_data) return NULL; - return (AVDownmixInfo*)side_data->data; + memset(side_data->data, 0, side_data->size); + + return (AVRawColorParams *)side_data->data; } diff --git a/libavutil/raw_color_params.h b/libavutil/raw_color_params.h new file mode 100644 index 0000000000..db6f841020 --- /dev/null +++ b/libavutil/raw_color_params.h @@ -0,0 +1,147 @@ +/* + * Copyright (c) 2026 Lynne <[email protected]> + * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef AVUTIL_RAW_COLOR_PARAMS_H +#define AVUTIL_RAW_COLOR_PARAMS_H + +#include <stddef.h> +#include <stdint.h> + +#include "frame.h" +#include "rational.h" + +enum AVRawColorParamsType { + AV_RAW_COLOR_PARAMS_NONE = 0, + + /** + * The union is valid when interpreted as AVProResRawColorParams + * (codec.prores_raw). + */ + AV_RAW_COLOR_PARAMS_PRORES_RAW, +}; + +/** + * ProRes RAW per-frame color transform, parsed from the prrf frame header. + * + * The correct rendering pipeline is: + * -> (sample - black_level) / (white_level - black_level) + * -> per-channel white balance (wb_red, 1.0 for G, wb_blue) pre-debayer + * -> debayer + * -> color_matrix (camera RGB -> CIE 1931 XYZ relative to D65) + * -> gain (scene-linear scale) + * + * Black/white levels live on the outer AVRawColorParams. The matrix output + * is linear-light CIE XYZ D65; convert to a working RGB space downstream. + * + * @note The struct must be allocated as part of AVRawColorParams using + * av_raw_color_params_alloc(). Its size is not a part of the public ABI. + */ +typedef struct AVProResRawColorParams { + /** + * White balance multiplier for the red channel, applied pre-debayer. + */ + AVRational wb_red; + + /** + * White balance multiplier for the blue channel, applied pre-debayer. + * (The green channel is implicit 1.0 for ProRes RAW) + */ + AVRational wb_blue; + + /** + * 3x3 row-major color matrix from camera RGB to linear-light CIE 1931 + * XYZ relative to the D65 illuminant, applied post-debayer. + * out[i] = sum_j color_matrix[i][j] * in[j]. + */ + AVRational color_matrix[3][3]; + + /** + * Post-matrix scene-linear scaling factor. Encodes highlight headroom the + * encoder reserved; multiply the matrixed values by this to recover + * scene-linear light. + */ + AVRational gain; +} AVProResRawColorParams; + +/** + * Per-frame color information for a RAW camera codec. Carried as side data of + * type AV_FRAME_DATA_RAW_COLOR_PARAMS. + * + * The outer struct carries the fields every RAW codec exposes: the sensor's + * valid sample range and the white-balance correlated color temperature. + * The codec union holds the codec-specific transform parameters; `type` + * selects which member of the union is valid. + * + * The codec-specific transform (color_matrix or equivalent) always lands in + * linear-light CIE 1931 XYZ relative to the D65 illuminant, cameras don't + * have standard primaries, so XYZ is the only common target. + * + * @note The struct must be allocated using av_raw_color_params_alloc() or + * av_raw_color_params_create_side_data(). Its size is not a part of the + * public ABI. + */ +typedef struct AVRawColorParams { + /** + * Selects which member of `codec` is valid. + */ + enum AVRawColorParamsType type; + + /** + * Lowest valid raw sample code (sensor black point) + */ + AVRational black_level; + + /** + * Highest valid raw sample code (sensor white point) + */ + AVRational white_level; + + /** + * Color temperature in Kelvin from with the camera's white balance. + * Informational; the math uses the codec-specific white-balance fields. + * 0 if not signaled. + */ + uint32_t wb_cct; + + /** + * Additional codec-specific fields. + */ + union { + AVProResRawColorParams prores_raw; + } codec; +} AVRawColorParams; + +/** + * Allocate an AVRawColorParams structure and zero-initialize it. + * + * @param size if non-NULL, set to sizeof(AVRawColorParams) + * @return the newly allocated struct or NULL on failure + */ +AVRawColorParams *av_raw_color_params_alloc(size_t *size); + +/** + * Allocate and add an AVRawColorParams structure to an existing AVFrame as + * AV_FRAME_DATA_RAW_COLOR_PARAMS side data. + * + * @return the newly allocated struct, or NULL on failure + */ +AVRawColorParams *av_raw_color_params_create_side_data(AVFrame *frame); + +#endif /* AVUTIL_RAW_COLOR_PARAMS_H */ diff --git a/libavutil/side_data.c b/libavutil/side_data.c index 64c4220ed9..762bc59d53 100644 --- a/libavutil/side_data.c +++ b/libavutil/side_data.c @@ -61,6 +61,7 @@ static const AVSideDataDescriptor sd_props[] = { [AV_FRAME_DATA_IAMF_MIX_GAIN_PARAM] = { "IAMF Mix Gain Parameter Data" }, [AV_FRAME_DATA_IAMF_DEMIXING_INFO_PARAM] = { "IAMF Demixing Info Parameter Data", AV_SIDE_DATA_PROP_CHANNEL_DEPENDENT }, [AV_FRAME_DATA_IAMF_RECON_GAIN_INFO_PARAM] = { "IAMF Recon Gain Info Parameter Data" }, + [AV_FRAME_DATA_RAW_COLOR_PARAMS] = { "RAW camera color parameters", AV_SIDE_DATA_PROP_GLOBAL | AV_SIDE_DATA_PROP_COLOR_DEPENDENT }, }; const AVSideDataDescriptor *av_frame_side_data_desc(enum AVFrameSideDataType type) diff --git a/libavutil/version.h b/libavutil/version.h index e7aeab9995..42f2d41052 100644 --- a/libavutil/version.h +++ b/libavutil/version.h @@ -79,7 +79,7 @@ */ #define LIBAVUTIL_VERSION_MAJOR 60 -#define LIBAVUTIL_VERSION_MINOR 32 +#define LIBAVUTIL_VERSION_MINOR 33 #define LIBAVUTIL_VERSION_MICRO 100 #define LIBAVUTIL_VERSION_INT AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \ _______________________________________________ ffmpeg-cvslog mailing list -- [email protected] To unsubscribe send an email to [email protected]
