[FFmpeg-devel] [PATCH 1/4] lavc/mediacodecenc: Add pix2color_fmt() and color2pix_fmt()

"zhilizhao(赵志立)" quinkblack at foxmail.com
Tue Feb 28 14:02:23 EET 2023


> +static int pix2color_fmt(AVCodecContext *avctx, enum AVPixelFormat pix_fmt)
> +{
> +    for (int i = 0; i < FF_ARRAY_ELEMS(color_formats); i++) {
> +        if (pix_fmt == color_formats[i].pix_fmt) {
> +            return color_formats[i].color_format;
> +        }
> +    }
> +    av_assert0(0);
> +}

After extracting to a general function, there is no hint that pix_fmt comes
from avctx->pix_fmt. So I prefer return error code here.

> +
> +static enum AVPixelFormat color2pix_fmt(AVCodecContext *avctx, int color_format)
> +{
> +    for (int i = 0; i < FF_ARRAY_ELEMS(color_formats); i++) {
> +        if (color_format == color_formats[i].color_format) {
> +            return color_formats[i].pix_fmt;
> +        }
> +    }
> +    av_assert0(0);
> +}


More information about the ffmpeg-devel mailing list