summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNiklas Haas <[email protected]>2025-08-13 13:53:26 +0200
committerNiklas Haas <[email protected]>2025-09-02 17:06:25 +0200
commit0fbd90d78f8d534a97e83331c6448f54fdf0a277 (patch)
tree69a4f2a86142b7b18d32a8c0c91228a0defc978f
parent65580592c91be88065951adac4403b5b94b88984 (diff)
avfilter/buffersink: add support for alpha modes
-rw-r--r--doc/APIchanges3
-rw-r--r--libavfilter/buffersink.c27
-rw-r--r--libavfilter/buffersink.h2
-rw-r--r--libavfilter/version.h2
4 files changed, 32 insertions, 2 deletions
diff --git a/doc/APIchanges b/doc/APIchanges
index 149ffc506e..9be59e7b8e 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:
+2025-09-xx - xxxxxxxxxx - lavfi 11.7.100 - buffersink.h
+ Add av_buffersink_get_alpha_mode().
+
2025-09-xx - xxxxxxxxxx - lavc 62.15.100 - avcodec.h codec_par.h
Add AVCodecContext.alpha_mode, AVCodecParameters.alpha_mode, and
AV_CODEC_CONFIG_ALPHA_MODE.
diff --git a/libavfilter/buffersink.c b/libavfilter/buffersink.c
index 50a7da2756..f636d3728f 100644
--- a/libavfilter/buffersink.c
+++ b/libavfilter/buffersink.c
@@ -53,6 +53,8 @@ typedef struct BufferSinkContext {
int color_spaces_size;
enum AVColorRange *color_ranges; ///< list of accepted color ranges
int color_ranges_size;
+ enum AVColorRange *alpha_modes; ///< list of accepted alpha modes
+ int alpha_modes_size;
#endif
enum AVPixelFormat *pixel_formats;
@@ -64,6 +66,9 @@ typedef struct BufferSinkContext {
int *colorranges;
unsigned nb_colorranges;
+ int *alphamodes;
+ unsigned nb_alphamodes;
+
/* only used for audio */
#if FF_API_BUFFERSINK_OPTS
enum AVSampleFormat *sample_fmts; ///< list of accepted sample formats
@@ -175,7 +180,7 @@ static av_cold int common_init(AVFilterContext *ctx)
}
if (ctx->input_pads[0].type == AVMEDIA_TYPE_VIDEO) {
- if ((buf->pixel_fmts_size || buf->color_spaces_size || buf->color_ranges_size) &&
+ if ((buf->pixel_fmts_size || buf->color_spaces_size || buf->color_ranges_size || buf->alpha_modes_size) &&
(buf->nb_pixel_formats || buf->nb_colorspaces || buf->nb_colorranges)) {
av_log(ctx, AV_LOG_ERROR, "Cannot combine old and new format lists\n");
return AVERROR(EINVAL);
@@ -184,6 +189,7 @@ static av_cold int common_init(AVFilterContext *ctx)
CHECK_LIST_SIZE(pixel_fmts)
CHECK_LIST_SIZE(color_spaces)
CHECK_LIST_SIZE(color_ranges)
+ CHECK_LIST_SIZE(alpha_modes)
} else {
if ((buf->sample_fmts_size || buf->channel_layouts_str || buf->sample_rates_size) &&
(buf->nb_sample_formats || buf->nb_samplerates || buf->nb_channel_layouts)) {
@@ -258,6 +264,7 @@ static int init_video(AVFilterContext *ctx)
TERMINATE_ARRAY(pixel_formats, AV_PIX_FMT_NONE);
TERMINATE_ARRAY(colorranges, -1);
TERMINATE_ARRAY(colorspaces, -1);
+ TERMINATE_ARRAY(alphamodes, -1);
return common_init(ctx);
}
@@ -336,6 +343,7 @@ MAKE_AVFILTERLINK_ACCESSOR(int , h )
MAKE_AVFILTERLINK_ACCESSOR(AVRational , sample_aspect_ratio)
MAKE_AVFILTERLINK_ACCESSOR(enum AVColorSpace, colorspace)
MAKE_AVFILTERLINK_ACCESSOR(enum AVColorRange, color_range)
+MAKE_AVFILTERLINK_ACCESSOR(enum AVAlphaMode , alpha_mode)
MAKE_AVFILTERLINK_ACCESSOR(int , sample_rate )
@@ -409,6 +417,11 @@ static int vsink_query_formats(const AVFilterContext *ctx,
if (ret < 0)
return ret;
}
+ if (buf->nb_alphamodes) {
+ ret = ff_set_common_alpha_modes_from_list2(ctx, cfg_in, cfg_out, buf->alphamodes);
+ if (ret < 0)
+ return ret;
+ }
#if FF_API_BUFFERSINK_OPTS
} else {
unsigned i;
@@ -438,6 +451,15 @@ static int vsink_query_formats(const AVFilterContext *ctx,
if ((ret = ff_set_common_color_ranges2(ctx, cfg_in, cfg_out, formats)) < 0)
return ret;
}
+
+ if (buf->alpha_modes_size) {
+ AVFilterFormats *formats = NULL;
+ for (i = 0; i < NB_ITEMS(buf->alpha_modes); i++)
+ if ((ret = ff_add_format(&formats, buf->alpha_modes[i])) < 0)
+ return ret;
+ if ((ret = ff_set_common_alpha_modes2(ctx, cfg_in, cfg_out, formats)) < 0)
+ return ret;
+ }
}
#endif
@@ -509,6 +531,7 @@ static const AVOption buffersink_options[] = {
{ "pix_fmts", "set the supported pixel formats", OFFSET(pixel_fmts), AV_OPT_TYPE_BINARY, .flags = FLAGS | AV_OPT_FLAG_DEPRECATED },
{ "color_spaces", "set the supported color spaces", OFFSET(color_spaces), AV_OPT_TYPE_BINARY, .flags = FLAGS | AV_OPT_FLAG_DEPRECATED },
{ "color_ranges", "set the supported color ranges", OFFSET(color_ranges), AV_OPT_TYPE_BINARY, .flags = FLAGS | AV_OPT_FLAG_DEPRECATED },
+ { "alpha_modes", "set the supported alpha modes", OFFSET(alpha_modes), AV_OPT_TYPE_BINARY, .flags = FLAGS | AV_OPT_FLAG_DEPRECATED },
#endif
{ "pixel_formats", "array of supported pixel formats", OFFSET(pixel_formats),
@@ -517,6 +540,8 @@ static const AVOption buffersink_options[] = {
AV_OPT_TYPE_INT | AV_OPT_TYPE_FLAG_ARRAY, .max = INT_MAX, .flags = FLAGS },
{ "colorranges", "array of supported color ranges", OFFSET(colorranges),
AV_OPT_TYPE_INT | AV_OPT_TYPE_FLAG_ARRAY, .max = INT_MAX, .flags = FLAGS },
+ { "alphamodes", "array of supported color ranges", OFFSET(alphamodes),
+ AV_OPT_TYPE_INT | AV_OPT_TYPE_FLAG_ARRAY, .max = INT_MAX, .flags = FLAGS },
{ NULL },
};
diff --git a/libavfilter/buffersink.h b/libavfilter/buffersink.h
index a8435eea8f..4e658a9795 100644
--- a/libavfilter/buffersink.h
+++ b/libavfilter/buffersink.h
@@ -58,6 +58,7 @@
* - pixel_formats (array of pixel formats),
* - colorspaces (array of int),
* - colorranges (array of int),
+ * - alphamodes (array of int),
* - sample_formats (array of sample formats),
* - samplerates (array of int),
* - channel_layouts (array of channel layouts)
@@ -115,6 +116,7 @@ int av_buffersink_get_h (const AVFilterContext *c
AVRational av_buffersink_get_sample_aspect_ratio (const AVFilterContext *ctx);
enum AVColorSpace av_buffersink_get_colorspace (const AVFilterContext *ctx);
enum AVColorRange av_buffersink_get_color_range (const AVFilterContext *ctx);
+enum AVAlphaMode av_buffersink_get_alpha_mode (const AVFilterContext *ctx);
int av_buffersink_get_channels (const AVFilterContext *ctx);
int av_buffersink_get_ch_layout (const AVFilterContext *ctx,
diff --git a/libavfilter/version.h b/libavfilter/version.h
index f191d98883..0050874108 100644
--- a/libavfilter/version.h
+++ b/libavfilter/version.h
@@ -31,7 +31,7 @@
#include "version_major.h"
-#define LIBAVFILTER_VERSION_MINOR 6
+#define LIBAVFILTER_VERSION_MINOR 7
#define LIBAVFILTER_VERSION_MICRO 100