[FFmpeg-devel] [PATCH 1/2] avcodec: add YUV color space metadata to AVCodec

Andreas Rheinhardt andreas.rheinhardt at outlook.com
Thu Feb 8 14:33:51 EET 2024


Niklas Haas:
> On Mon, 05 Feb 2024 19:37:48 +0100 Niklas Haas <ffmpeg at haasn.xyz> wrote:
>> On Mon, 05 Feb 2024 19:04:30 +0100 Andreas Rheinhardt <andreas.rheinhardt at outlook.com> wrote:
>>> This presumes the relevant states to be a cartesian product. Which need
>>> not be true. A callback would be better; this would also allow to base
>>> the list on other values already set in an AVCodecContext. And if this
>>> were extended, it would also allow to remove init_static_data one day.
>>> It is furthermore quite wasteful to store color_ranges in a list,
>>> although there are only very few states for it.
>>
>> What signature would you propose for such a callback?
> 
> Well, there are two fundamental approaches here:
> 
> 1. The callback somehow sets or returns a list of supported colorspaces.
> 2. The callback accepts a particular configuration and simply returns if
>    it's supported or not, with fields set to AVCOL_*_UNKNOWN being
>    ignored.
> 
> The first case has the pro of simplicity, and the ability to enumerate
> more easily, but the drawback of only being scalable if we return
> a cartesian set (i.e. set each attribute list independently, rather than
> generating one big list).
> 
> The second case has the pro of flexibility, and the ability to handle
> non-cartesian use cases, but the con of being slightly more awkward to
> recover a list (for e.g. filtering purpose). Fortunately, we can recover
> the minimal cartesian superset of the actual supported set in O(n) time,
> and then still verify the exact format chosen at encode time.
> 
> One possibility could be to add a `test()` callback which simply tests
> if the current codec context has valid parameters. For example:
> 
> struct AVCodecContext {
>     ...
>     int (*test)(const AVCodecContext *ctx);
> }
> 
> But this suggests a very stateful API, where you have to mutate
> AVCodecContext in order to query what formats would be supported.
> I don't like this.
> 
> So probably it makes more sense to just directly ingest a new struct
> for this purpose, which we can then extend easily. (Or should we just
> ingest AVFrame directly, i.e. int (*test_avframe)(ctx, AVFrame *frame)?)

Sorry for not answering earlier.
My intention is to allow users who only want to deal with the common
case of a cartesian product to continue to do so, but to also support
other usecases.
The public function would look like

int avcodec_get_supported_config(const AVCodecContext *avctx, const
AVCodec *codec, int **supported_configs, unsigned desired_configs,
unsigned flags, void *logctx);

avctx can be NULL (in which case this allows to return all potential
configurations, irrespective of e.g. the level of strictness).
codec can be omitted if avctx->codec is set, but if both are supplied
and avctx->codec is set, they have to match (like in avcodec_open2()).
desired_configs is a bitfield of configs that the user wants to get
information about; your patch would have to add flags for color_ranges
and color_spaces.
supported_configs will on return point to something like an array of
struct { int desired_config0, desired_config1,...;}. The order of the
entries will be fixed (say coincide with the order of the bits in the
desired_configs bitfields).
If one member is the unspec value for its type, then this means that it
works with everything.
supported_configs will be allocated; ownership passes to the user.
Using a multidimensional sentinel (that would depend on desired_configs)
is clumsy, so there will be two supported ways for this (depends upon a
flag to be supplied in flags): One method that really adds a
multidimensional sentinel, the other method that writes the number of
entries into **supported_configs, so that the first entry starts at
(*supported_configs)[1]. This allows users that only want to deal with
the factors of a cartesian product separately to continue to do so.

- Andreas



More information about the ffmpeg-devel mailing list