[FFmpeg-devel] [PATCH] avcodec/libx264: Fix deprecation warnings on pix_fmts
Zhao Zhili
quinkblack at foxmail.com
Wed Feb 5 19:25:01 EET 2025
I prefer another version which doesn't drop const modifier.
https://ffmpeg.org/pipermail/ffmpeg-devel/2025-February/339331.html
> On Feb 6, 2025, at 00:07, Zhao Zhili <quinkblack-at-foxmail.com at ffmpeg.org> wrote:
>
> From: Zhao Zhili <zhilizhao at tencent.com>
>
> ---
> libavcodec/allcodecs.c | 6 ++---
> libavcodec/libx264.c | 53 +++++++++++++++++++++++++++++++++++++-----
> 2 files changed, 50 insertions(+), 9 deletions(-)
>
> diff --git a/libavcodec/allcodecs.c b/libavcodec/allcodecs.c
> index 4e1b1c9b45..d2ec4c3045 100644
> --- a/libavcodec/allcodecs.c
> +++ b/libavcodec/allcodecs.c
> @@ -811,9 +811,9 @@ extern const FFCodec ff_libvvenc_encoder;
> /* preferred over libwebp */
> extern const FFCodec ff_libwebp_anim_encoder;
> extern const FFCodec ff_libwebp_encoder;
> -extern const FFCodec ff_libx262_encoder;
> -extern const FFCodec ff_libx264_encoder;
> -extern const FFCodec ff_libx264rgb_encoder;
> +extern FFCodec ff_libx262_encoder;
> +extern FFCodec ff_libx264_encoder;
> +extern FFCodec ff_libx264rgb_encoder;
> extern FFCodec ff_libx265_encoder;
> extern const FFCodec ff_libxeve_encoder;
> extern const FFCodec ff_libxevd_decoder;
> diff --git a/libavcodec/libx264.c b/libavcodec/libx264.c
> index 409f45fc7d..c4bc7c48f5 100644
> --- a/libavcodec/libx264.c
> +++ b/libavcodec/libx264.c
> @@ -1607,6 +1607,12 @@ static const FFCodecDefault x264_defaults[] = {
> { NULL },
> };
>
> +static int X264_get_supported_config(const AVCodecContext *avctx,
> + const AVCodec *codec,
> + enum AVCodecConfig config,
> + unsigned flags, const void **out,
> + int *out_num);
> +
> #if CONFIG_LIBX264_ENCODER
> static const AVClass x264_class = {
> .class_name = "libx264",
> @@ -1615,7 +1621,7 @@ static const AVClass x264_class = {
> .version = LIBAVUTIL_VERSION_INT,
> };
>
> -const FFCodec ff_libx264_encoder = {
> +FFCodec ff_libx264_encoder = {
> .p.name = "libx264",
> CODEC_LONG_NAME("libx264 H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10"),
> .p.type = AVMEDIA_TYPE_VIDEO,
> @@ -1633,13 +1639,13 @@ const FFCodec ff_libx264_encoder = {
> .flush = X264_flush,
> .close = X264_close,
> .defaults = x264_defaults,
> - .p.pix_fmts = pix_fmts_all,
> .color_ranges = AVCOL_RANGE_MPEG | AVCOL_RANGE_JPEG,
> .caps_internal = FF_CODEC_CAP_INIT_CLEANUP | FF_CODEC_CAP_AUTO_THREADS
> #if X264_BUILD < 158
> | FF_CODEC_CAP_NOT_INIT_THREADSAFE
> #endif
> ,
> + .get_supported_config = X264_get_supported_config,
> };
> #endif
>
> @@ -1651,7 +1657,7 @@ static const AVClass rgbclass = {
> .version = LIBAVUTIL_VERSION_INT,
> };
>
> -const FFCodec ff_libx264rgb_encoder = {
> +FFCodec ff_libx264rgb_encoder = {
> .p.name = "libx264rgb",
> CODEC_LONG_NAME("libx264 H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10 RGB"),
> .p.type = AVMEDIA_TYPE_VIDEO,
> @@ -1659,7 +1665,6 @@ const FFCodec ff_libx264rgb_encoder = {
> .p.capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_DELAY |
> AV_CODEC_CAP_OTHER_THREADS |
> AV_CODEC_CAP_ENCODER_REORDERED_OPAQUE,
> - .p.pix_fmts = pix_fmts_8bit_rgb,
> .p.priv_class = &rgbclass,
> .p.wrapper_name = "libx264",
> .priv_data_size = sizeof(X264Context),
> @@ -1672,6 +1677,7 @@ const FFCodec ff_libx264rgb_encoder = {
> | FF_CODEC_CAP_NOT_INIT_THREADSAFE
> #endif
> ,
> + .get_supported_config = X264_get_supported_config,
> };
> #endif
>
> @@ -1683,7 +1689,7 @@ static const AVClass X262_class = {
> .version = LIBAVUTIL_VERSION_INT,
> };
>
> -const FFCodec ff_libx262_encoder = {
> +FFCodec ff_libx262_encoder = {
> .p.name = "libx262",
> CODEC_LONG_NAME("libx262 MPEG2VIDEO"),
> .p.type = AVMEDIA_TYPE_VIDEO,
> @@ -1691,7 +1697,6 @@ const FFCodec ff_libx262_encoder = {
> .p.capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_DELAY |
> AV_CODEC_CAP_OTHER_THREADS |
> AV_CODEC_CAP_ENCODER_REORDERED_OPAQUE,
> - .p.pix_fmts = pix_fmts_8bit,
> .color_ranges = AVCOL_RANGE_MPEG,
> .p.priv_class = &X262_class,
> .p.wrapper_name = "libx264",
> @@ -1702,5 +1707,41 @@ const FFCodec ff_libx262_encoder = {
> .defaults = x264_defaults,
> .caps_internal = FF_CODEC_CAP_NOT_INIT_THREADSAFE |
> FF_CODEC_CAP_INIT_CLEANUP | FF_CODEC_CAP_AUTO_THREADS,
> + .get_supported_config = X264_get_supported_config,
> };
> #endif
> +
> +static int X264_get_supported_config(const AVCodecContext *avctx,
> + const AVCodec *codec,
> + enum AVCodecConfig config,
> + unsigned flags, const void **out,
> + int *out_num)
> +{
> + if (config == AV_CODEC_CONFIG_PIX_FORMAT) {
> +#if CONFIG_LIBX264_ENCODER
> + if (codec == &ff_libx264_encoder.p) {
> + *out = pix_fmts_all;
> + *out_num = FF_ARRAY_ELEMS(pix_fmts_all) - 1;
> + return 0;
> + }
> +#endif
> +
> +#if CONFIG_LIBX264RGB_ENCODER
> + if (codec == &ff_libx264rgb_encoder.p) {
> + *out = pix_fmts_8bit_rgb;
> + *out_num = FF_ARRAY_ELEMS(pix_fmts_8bit_rgb) - 1;
> + return 0;
> + }
> +#endif
> +#if CONFIG_LIBX262_ENCODER
> + if (codec == &ff_libx262_encoder.p) {
> + *out = pix_fmts_8bit;
> + *out_num = FF_ARRAY_ELEMS(pix_fmts_8bit) - 1;
> + }
> +#endif
> + return AVERROR(EINVAL);
> + }
> +
> + return ff_default_get_supported_config(avctx, codec, config, flags, out,
> + out_num);
> +}
> --
> 2.46.0
>
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel at ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-request at ffmpeg.org with subject "unsubscribe".
More information about the ffmpeg-devel
mailing list