[Libav-user] Cheking for an alpha channel / using AVPixFmtDescriptor

Carl Eugen Hoyos ceffmpeg at gmail.com
Thu Apr 18 01:22:21 EEST 2019


2019-04-17 11:37 GMT+02:00, Simone Donadini <simone.donadini at avolites.com>:

> When opening a media i need to check if the pixel format holds an alpha
> channel.
> I can check for the alpha flag in the pixel format description, like this:
> const AVPixFmtDescriptor *pixDesc = av_pix_fmt_desc_get(pix_format);
> bool has_alpha = pixDesc->flags & AV_PIX_FMT_FLAG_ALPHA;
>
> But i noticed that inside libavutil/pixdesc.c there is a function for
> checking for an alpha channel, which is defined like this:
> #define pixdesc_has_alpha(pixdesc) ((pixdesc)->nb_components == 2 ||
> (pixdesc)->nb_components == 4 || (pixdesc)->flags & AV_PIX_FMT_FLAG_PAL)
> I understand the use of AV_PIX_FMT_FLAG_PAL as it is an exception, but could
> a pixel format with alpha have a number of components different from 2 and
> 4?
>
> So, which one of the two methods is more reliable?

For you as a user, only one method exist, the macro
is not exported.
If you plan to copy the macro: It is not correct as FFmpeg
contains several formats with four components where
alpha should be ignored, it is meaningless (RGB0 and friends).

Carl Eugen


More information about the Libav-user mailing list