diff options
author | Niklas Haas <[email protected]> | 2025-08-17 19:30:56 +0200 |
---|---|---|
committer | Niklas Haas <[email protected]> | 2025-09-02 17:05:51 +0200 |
commit | 8b375b2ffd4377909180241cdc65d63d372a35a3 (patch) | |
tree | e3fc7362250b8a69d0f818018d6d7a281e49e6f2 /libavfilter/formats.c | |
parent | dbcdcaede8544705af0c3d63d0831fe20d5c1ff4 (diff) |
avfilter/avfiltergraph: allow different conversion filters per merger
Instead of hard-coding the assumption that all video properties are handled
by vf_scale, generalize the struct slightly to allow different conversion
filters for each property being merged. The avfiltergraph code creates a list
of conversion filters needed and inserts all of them at once.
Because a conversion filter might itself e.g. not support all formats,
it's possible that we need to go through the whole process of negotiating
formats multiple times, and keep adding conversion filters until all of them
are settled. Do this by simply jumping back to the beginning of the loop
to ensure that the `convertor_count` field remains contiguous.
Diffstat (limited to 'libavfilter/formats.c')
-rw-r--r-- | libavfilter/formats.c | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/libavfilter/formats.c b/libavfilter/formats.c index 652ec99c02..81c63e50cd 100644 --- a/libavfilter/formats.c +++ b/libavfilter/formats.c @@ -345,21 +345,32 @@ static int merge_generic(void *a, void *b) return merge_generic_internal(a, b, 0); } +#define CONVERSION_FILTER_SWSCALE \ + .conversion_filter = "scale", \ + .conversion_opts_offset = offsetof(AVFilterGraph, scale_sws_opts), + +#define CONVERSION_FILTER_ARESAMPLE \ + .conversion_filter = "aresample", \ + .conversion_opts_offset = offsetof(AVFilterGraph, aresample_swr_opts), + static const AVFilterFormatsMerger mergers_video[] = { { .offset = offsetof(AVFilterFormatsConfig, formats), .merge = merge_pix_fmts, .can_merge = can_merge_pix_fmts, + CONVERSION_FILTER_SWSCALE }, { .offset = offsetof(AVFilterFormatsConfig, color_spaces), .merge = merge_generic, .can_merge = can_merge_generic, + CONVERSION_FILTER_SWSCALE }, { .offset = offsetof(AVFilterFormatsConfig, color_ranges), .merge = merge_generic, .can_merge = can_merge_generic, + CONVERSION_FILTER_SWSCALE }, }; @@ -368,31 +379,30 @@ static const AVFilterFormatsMerger mergers_audio[] = { .offset = offsetof(AVFilterFormatsConfig, channel_layouts), .merge = merge_channel_layouts, .can_merge = can_merge_channel_layouts, + CONVERSION_FILTER_ARESAMPLE }, { .offset = offsetof(AVFilterFormatsConfig, samplerates), .merge = merge_samplerates, .can_merge = can_merge_samplerates, + CONVERSION_FILTER_ARESAMPLE }, { .offset = offsetof(AVFilterFormatsConfig, formats), .merge = merge_sample_fmts, .can_merge = can_merge_sample_fmts, + CONVERSION_FILTER_ARESAMPLE }, }; static const AVFilterNegotiation negotiate_video = { .nb_mergers = FF_ARRAY_ELEMS(mergers_video), .mergers = mergers_video, - .conversion_filter = "scale", - .conversion_opts_offset = offsetof(AVFilterGraph, scale_sws_opts), }; static const AVFilterNegotiation negotiate_audio = { .nb_mergers = FF_ARRAY_ELEMS(mergers_audio), .mergers = mergers_audio, - .conversion_filter = "aresample", - .conversion_opts_offset = offsetof(AVFilterGraph, aresample_swr_opts), }; const AVFilterNegotiation *ff_filter_get_negotiation(AVFilterLink *link) |