Message ID | 20200416152900.145027-1-george@nsup.org |
---|---|
State | Accepted |
Headers | show |
Series | [FFmpeg-devel,1/4] lavfi/formats: add ff_formats_pixdesc_filter(). | expand |
Context | Check | Description |
---|---|---|
andriy/default | pending | |
andriy/make | success | Make finished |
andriy/make_fate | success | Make fate finished |
On 16/04/2020 16:28, Nicolas George wrote: > Signed-off-by: Nicolas George <george@nsup.org> > --- > libavfilter/formats.c | 41 +++++++++++++++++++++++++++++++++++++++++ > libavfilter/formats.h | 10 ++++++++++ > 2 files changed, 51 insertions(+) (Just a commnt out of curiosity.) Are there more filters than vf_crop that this is intended to be used on? - Derek
Derek Buitenhuis (12020-04-16): > (Just a commnt out of curiosity.) > > Are there more filters than vf_crop that this is intended to be used on? I said: >> I need it in new code. It is to be a filter that has constraints similar to vf_crop. But also, ff_all_formats() can be implemented in terms of this function, which makes it more efficient (there was an old thread about this). Also, I just checked: all these filters do a similar thing in their query_formats() function, which means this should have been done years ago. I don't intend to change them all, anybody can do it. vf_boxblur.c vf_copy.c vf_detelecine.c vf_fieldhint.c vf_fieldorder.c vf_hflip.c vf_hwdownload.c vf_il.c vf_mix.c vf_noise.c vf_stack.c vf_swaprect.c vf_swapuv.c vf_telecine.c vf_transpose.c vf_weave.c Regards,
On 16/04/2020 17:48, Nicolas George wrote: > Derek Buitenhuis (12020-04-16): >> (Just a commnt out of curiosity.) >> >> Are there more filters than vf_crop that this is intended to be used on? > > I said: > >>> I need it in new code. It wasn't clear to me what 'new code' entailed here, at the time. > It is to be a filter that has constraints similar to vf_crop. > > But also, ff_all_formats() can be implemented in terms of this function, > which makes it more efficient (there was an old thread about this). > > Also, I just checked: all these filters do a similar thing in their > query_formats() function, which means this should have been done years > ago. I don't intend to change them all, anybody can do it. > > vf_boxblur.c > vf_copy.c > vf_detelecine.c > vf_fieldhint.c > vf_fieldorder.c > vf_hflip.c > vf_hwdownload.c > vf_il.c > vf_mix.c > vf_noise.c > vf_stack.c > vf_swaprect.c > vf_swapuv.c > vf_telecine.c > vf_transpose.c > vf_weave.c Thanks for the info! - Derek
Nicolas George (12020-04-16): > Signed-off-by: Nicolas George <george@nsup.org> > --- > libavfilter/formats.c | 41 +++++++++++++++++++++++++++++++++++++++++ > libavfilter/formats.h | 10 ++++++++++ > 2 files changed, 51 insertions(+) Series pushed. Regards,
diff --git a/libavfilter/formats.c b/libavfilter/formats.c index 33c64668a0..784f604483 100644 --- a/libavfilter/formats.c +++ b/libavfilter/formats.c @@ -373,6 +373,47 @@ const int64_t avfilter_all_channel_layouts[] = { -1 }; +int ff_formats_pixdesc_filter(AVFilterFormats **rfmts, unsigned want, unsigned rej) +{ + unsigned nb_formats, fmt, flags; + AVFilterFormats *formats = NULL; + + while (1) { + nb_formats = 0; + for (fmt = 0;; fmt++) { + const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(fmt); + if (!desc) + break; + flags = desc->flags; + if (!(desc->flags & AV_PIX_FMT_FLAG_HWACCEL) && + !(desc->flags & AV_PIX_FMT_FLAG_PLANAR) && + (desc->log2_chroma_w || desc->log2_chroma_h)) + flags |= FF_PIX_FMT_FLAG_SW_FLAT_SUB; + if ((flags & (want | rej)) != want) + continue; + if (formats) + formats->formats[nb_formats] = fmt; + nb_formats++; + } + if (formats) { + av_assert0(formats->nb_formats == nb_formats); + *rfmts = formats; + return 0; + } + formats = av_mallocz(sizeof(*formats)); + if (!formats) + return AVERROR(ENOMEM); + formats->nb_formats = nb_formats; + if (nb_formats) { + formats->formats = av_malloc_array(nb_formats, sizeof(*formats->formats)); + if (!formats->formats) { + av_freep(&formats); + return AVERROR(ENOMEM); + } + } + } +} + // AVFilterFormats *avfilter_make_all_channel_layouts(void) // { // return avfilter_make_format64_list(avfilter_all_channel_layouts); diff --git a/libavfilter/formats.h b/libavfilter/formats.h index 870809b5a0..cc588f30d8 100644 --- a/libavfilter/formats.h +++ b/libavfilter/formats.h @@ -221,6 +221,16 @@ int ff_add_format(AVFilterFormats **avff, int64_t fmt); av_warn_unused_result AVFilterFormats *ff_all_formats(enum AVMediaType type); +/** + * Construct a formats list containing all pixel formats with certain + * properties + */ +av_warn_unused_result +int ff_formats_pixdesc_filter(AVFilterFormats **rfmts, unsigned want, unsigned rej); + +//* format is software, non-planar with sub-sampling +#define FF_PIX_FMT_FLAG_SW_FLAT_SUB (1 << 24) + /** * Construct a formats list containing all planar sample formats. */
Signed-off-by: Nicolas George <george@nsup.org> --- libavfilter/formats.c | 41 +++++++++++++++++++++++++++++++++++++++++ libavfilter/formats.h | 10 ++++++++++ 2 files changed, 51 insertions(+) I need it in new code.