* [FFmpeg-devel] [PATCH 1/2] avfilter/avfilter: add avfilter_print_config_formats()
2022-10-11 13:17 [FFmpeg-devel] [PATCH 0/2] Print filter input/output formats in help output ffmpegagent
@ 2022-10-11 13:17 ` softworkz
2022-11-03 9:58 ` Paul B Mahol
2022-10-11 13:17 ` [FFmpeg-devel] [PATCH 2/2] ftools/opt_common: Print filter input/output formats in help output softworkz
2022-10-11 21:38 ` [FFmpeg-devel] [PATCH v2 0/2] " ffmpegagent
2 siblings, 1 reply; 10+ messages in thread
From: softworkz @ 2022-10-11 13:17 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: softworkz
From: softworkz <softworkz@hotmail.com>
Prints the following to AVBPrint:
For pass-through filter links:
"All (passthrough)"
For filters using query_formats:
"Dynamic"
For filters using query_formats where a call to query_formats
succeeds (example):
"Dynamic, Defaults: [yuv420p, yuvj420p, yuva420p, nv12, nv21]"
For all other filters (example):
"[s16p, s32p, fltp, dblp]"
Except in case when the number of formats equals the number of
available formats:
"All"
Signed-off-by: softworkz <softworkz@hotmail.com>
---
doc/APIchanges | 3 ++
libavfilter/avfilter.c | 102 +++++++++++++++++++++++++++++++++++-
libavfilter/avfilter.h | 12 +++++
libavfilter/avfiltergraph.c | 14 +++--
libavfilter/internal.h | 9 ++++
libavfilter/version.h | 4 +-
6 files changed, 136 insertions(+), 8 deletions(-)
diff --git a/doc/APIchanges b/doc/APIchanges
index cbb579612e..6e2a528b04 100644
--- a/doc/APIchanges
+++ b/doc/APIchanges
@@ -14,6 +14,9 @@ libavutil: 2021-04-27
API changes, most recent first:
+2022-10-11 - xxxxxxxxxx - lavf 59.50.100 - avfilter.h
+ Add add avfilter_print_config_formats().
+
2022-10-05 - 37d5ddc317 - lavu 57.39.100 - cpu.h
Add AV_CPU_FLAG_RVB_BASIC.
diff --git a/libavfilter/avfilter.c b/libavfilter/avfilter.c
index cc5505e65b..8cc665e19c 100644
--- a/libavfilter/avfilter.c
+++ b/libavfilter/avfilter.c
@@ -196,6 +196,104 @@ void avfilter_link_free(AVFilterLink **link)
av_freep(link);
}
+static unsigned get_nb_pix_fmts()
+{
+ unsigned i = 0;
+ while (av_pix_fmt_desc_get(i++)) {}
+ return i - 1;
+}
+
+static unsigned get_nb_sample_fmts()
+{
+ unsigned i = 0;
+ while (av_get_sample_fmt_name(i++)) {}
+ return i - 1;
+}
+
+int avfilter_print_config_formats(AVBPrint *bp, const struct AVFilter *filter, int for_output, unsigned pad_index)
+{
+ AVFilterGraph *graph;
+ AVFilterContext *filter_context;
+ AVFilterFormatsConfig *config;
+ enum AVMediaType media_type;
+ int ret = 0;
+
+ if (filter->formats_state == FF_FILTER_FORMATS_PASSTHROUGH) {
+ av_bprintf(bp, "All (passthrough)");
+ return 0;
+ }
+
+ graph = avfilter_graph_alloc();
+ if (!graph) {
+ av_log(NULL, AV_LOG_ERROR, "Failed to create filtergraph\n");
+ ret = AVERROR(ENOMEM);
+ goto cleanup;
+ }
+
+ filter_context = avfilter_graph_alloc_filter(graph, filter, "filter");
+ if (!filter_context) {
+ av_log(NULL, AV_LOG_ERROR, "Failed to create filter\n");
+ ret = AVERROR(ENOMEM);
+ goto cleanup;
+ }
+
+ avfilter_init_str(filter_context, NULL);
+
+ if (filter->formats_state == FF_FILTER_FORMATS_QUERY_FUNC)
+ av_bprintf(bp, "Dynamic");
+
+ if (!for_output && pad_index >= filter_context->nb_inputs
+ || for_output && pad_index >= filter_context->nb_outputs)
+ goto cleanup;
+
+ avfilter_graph_config(graph, graph);
+
+ for (unsigned i = 0; i < filter_context->nb_inputs; i++)
+ filter_context->inputs[i] = (AVFilterLink *)av_mallocz(sizeof(AVFilterLink));
+
+ for (unsigned i = 0; i < filter_context->nb_outputs; i++)
+ filter_context->outputs[i] = (AVFilterLink *)av_mallocz(sizeof(AVFilterLink));
+
+ ff_filter_query_formats(filter_context);
+
+ config = for_output ? &filter_context->outputs[pad_index]->incfg : &filter_context->inputs[pad_index]->outcfg;
+
+ if (!config || !config->formats)
+ goto cleanup;
+
+ media_type= for_output ? filter->outputs[pad_index].type : filter->inputs[pad_index].type;
+
+ if (filter->formats_state == FF_FILTER_FORMATS_QUERY_FUNC) {
+ if (config->formats && config->formats->nb_formats)
+ av_bprintf(bp, ", Default: ");
+ }
+
+ if (config->formats == NULL)
+ av_bprintf(bp, "unknown");
+ else if (media_type == AVMEDIA_TYPE_VIDEO && config->formats->nb_formats == get_nb_pix_fmts() ||
+ media_type == AVMEDIA_TYPE_AUDIO && config->formats->nb_formats == get_nb_sample_fmts())
+ av_bprintf(bp, "All");
+ else {
+ for (unsigned i = 0; i < config->formats->nb_formats; i++) {
+ if (i == 0)
+ av_bprintf(bp, "[");
+
+ if (media_type == AVMEDIA_TYPE_VIDEO)
+ av_bprintf(bp, "%s", av_get_pix_fmt_name(config->formats->formats[i]));
+ else if (media_type == AVMEDIA_TYPE_AUDIO)
+ av_bprintf(bp, "%s", av_get_sample_fmt_name(config->formats->formats[i]));
+
+ if (i < config->formats->nb_formats - 1)
+ av_bprintf(bp, ", ");
+ else
+ av_bprintf(bp, "]"); }
+ }
+
+cleanup:
+ avfilter_graph_free(&graph);
+ return ret;
+}
+
void ff_filter_set_ready(AVFilterContext *filter, unsigned priority)
{
filter->ready = FFMAX(filter->ready, priority);
@@ -759,12 +857,12 @@ void avfilter_free(AVFilterContext *filter)
for (i = 0; i < filter->nb_inputs; i++) {
free_link(filter->inputs[i]);
- if (filter->input_pads[i].flags & AVFILTERPAD_FLAG_FREE_NAME)
+ if (filter->input_pads && filter->input_pads[i].flags & AVFILTERPAD_FLAG_FREE_NAME)
av_freep(&filter->input_pads[i].name);
}
for (i = 0; i < filter->nb_outputs; i++) {
free_link(filter->outputs[i]);
- if (filter->output_pads[i].flags & AVFILTERPAD_FLAG_FREE_NAME)
+ if (filter->output_pads && filter->output_pads[i].flags & AVFILTERPAD_FLAG_FREE_NAME)
av_freep(&filter->output_pads[i].name);
}
diff --git a/libavfilter/avfilter.h b/libavfilter/avfilter.h
index 2e8197c9a6..705dabe53c 100644
--- a/libavfilter/avfilter.h
+++ b/libavfilter/avfilter.h
@@ -41,6 +41,7 @@
#include "libavutil/avutil.h"
#include "libavutil/buffer.h"
#include "libavutil/dict.h"
+#include "libavutil/bprint.h"
#include "libavutil/frame.h"
#include "libavutil/log.h"
#include "libavutil/samplefmt.h"
@@ -738,6 +739,17 @@ int avfilter_link(AVFilterContext *src, unsigned srcpad,
*/
void avfilter_link_free(AVFilterLink **link);
+/**
+ * Gets the formats from an AVFilterFormatsConfig.
+ *
+ * @param bp an instance of AVBPrint
+ * @param filter the AVFilter
+ * @param for_output set to 1 for filter outputs
+ * @param pad_index the index of the input or output
+ * @return zero on success
+ */
+int avfilter_print_config_formats(AVBPrint *bp, const AVFilter *filter, int for_output, unsigned pad_index);
+
/**
* Negotiate the media format, dimensions, etc of all inputs to a filter.
*
diff --git a/libavfilter/avfiltergraph.c b/libavfilter/avfiltergraph.c
index 53f468494d..9118a44e1f 100644
--- a/libavfilter/avfiltergraph.c
+++ b/libavfilter/avfiltergraph.c
@@ -416,10 +416,7 @@ static int query_formats(AVFilterGraph *graph, void *log_ctx)
AVFilterContext *f = graph->filters[i];
if (formats_declared(f))
continue;
- if (f->filter->formats_state == FF_FILTER_FORMATS_QUERY_FUNC)
- ret = filter_query_formats(f);
- else
- ret = ff_default_query_formats(f);
+ ret = ff_filter_query_formats(f);
if (ret < 0 && ret != AVERROR(EAGAIN))
return ret;
/* note: EAGAIN could indicate a partial success, not counted yet */
@@ -1351,3 +1348,12 @@ int ff_filter_graph_run_once(AVFilterGraph *graph)
return AVERROR(EAGAIN);
return ff_filter_activate(filter);
}
+
+int ff_filter_query_formats(AVFilterContext *filter)
+{
+ if (filter->filter->formats_state == FF_FILTER_FORMATS_QUERY_FUNC)
+ return filter_query_formats(filter);
+
+ return ff_default_query_formats(filter);
+}
+
diff --git a/libavfilter/internal.h b/libavfilter/internal.h
index aaf2c6c584..446d2a45f8 100644
--- a/libavfilter/internal.h
+++ b/libavfilter/internal.h
@@ -374,6 +374,15 @@ void ff_filter_graph_remove_filter(AVFilterGraph *graph, AVFilterContext *filter
*/
int ff_filter_graph_run_once(AVFilterGraph *graph);
+/**
+ * Query the formats of a filter.
+ *
+ * @param filter the filter context
+ *
+ * @return 0 on success
+ */
+int ff_filter_query_formats(AVFilterContext *filter);
+
/**
* Get number of threads for current filter instance.
* This number is always same or less than graph->nb_threads.
diff --git a/libavfilter/version.h b/libavfilter/version.h
index 4ccbf5641c..436c2b8b17 100644
--- a/libavfilter/version.h
+++ b/libavfilter/version.h
@@ -31,8 +31,8 @@
#include "version_major.h"
-#define LIBAVFILTER_VERSION_MINOR 49
-#define LIBAVFILTER_VERSION_MICRO 101
+#define LIBAVFILTER_VERSION_MINOR 50
+#define LIBAVFILTER_VERSION_MICRO 100
#define LIBAVFILTER_VERSION_INT AV_VERSION_INT(LIBAVFILTER_VERSION_MAJOR, \
--
ffmpeg-codebot
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [FFmpeg-devel] [PATCH 1/2] avfilter/avfilter: add avfilter_print_config_formats()
2022-10-11 13:17 ` [FFmpeg-devel] [PATCH 1/2] avfilter/avfilter: add avfilter_print_config_formats() softworkz
@ 2022-11-03 9:58 ` Paul B Mahol
2022-11-03 22:34 ` Soft Works
2022-12-12 23:13 ` Soft Works
0 siblings, 2 replies; 10+ messages in thread
From: Paul B Mahol @ 2022-11-03 9:58 UTC (permalink / raw)
To: FFmpeg development discussions and patches; +Cc: softworkz
On 10/11/22, softworkz <ffmpegagent@gmail.com> wrote:
> From: softworkz <softworkz@hotmail.com>
>
> Prints the following to AVBPrint:
>
> For pass-through filter links:
>
> "All (passthrough)"
>
> For filters using query_formats:
>
> "Dynamic"
>
> For filters using query_formats where a call to query_formats
> succeeds (example):
>
> "Dynamic, Defaults: [yuv420p, yuvj420p, yuva420p, nv12, nv21]"
>
> For all other filters (example):
>
> "[s16p, s32p, fltp, dblp]"
>
> Except in case when the number of formats equals the number of
> available formats:
>
> "All"
>
> Signed-off-by: softworkz <softworkz@hotmail.com>
> ---
> doc/APIchanges | 3 ++
> libavfilter/avfilter.c | 102 +++++++++++++++++++++++++++++++++++-
> libavfilter/avfilter.h | 12 +++++
> libavfilter/avfiltergraph.c | 14 +++--
> libavfilter/internal.h | 9 ++++
> libavfilter/version.h | 4 +-
> 6 files changed, 136 insertions(+), 8 deletions(-)
>
> diff --git a/doc/APIchanges b/doc/APIchanges
> index cbb579612e..6e2a528b04 100644
> --- a/doc/APIchanges
> +++ b/doc/APIchanges
> @@ -14,6 +14,9 @@ libavutil: 2021-04-27
>
> API changes, most recent first:
>
> +2022-10-11 - xxxxxxxxxx - lavf 59.50.100 - avfilter.h
> + Add add avfilter_print_config_formats().
> +
> 2022-10-05 - 37d5ddc317 - lavu 57.39.100 - cpu.h
> Add AV_CPU_FLAG_RVB_BASIC.
>
> diff --git a/libavfilter/avfilter.c b/libavfilter/avfilter.c
> index cc5505e65b..8cc665e19c 100644
> --- a/libavfilter/avfilter.c
> +++ b/libavfilter/avfilter.c
> @@ -196,6 +196,104 @@ void avfilter_link_free(AVFilterLink **link)
> av_freep(link);
> }
>
> +static unsigned get_nb_pix_fmts()
> +{
> + unsigned i = 0;
> + while (av_pix_fmt_desc_get(i++)) {}
> + return i - 1;
> +}
> +
> +static unsigned get_nb_sample_fmts()
> +{
> + unsigned i = 0;
> + while (av_get_sample_fmt_name(i++)) {}
> + return i - 1;
> +}
> +
> +int avfilter_print_config_formats(AVBPrint *bp, const struct AVFilter
> *filter, int for_output, unsigned pad_index)
> +{
> + AVFilterGraph *graph;
> + AVFilterContext *filter_context;
> + AVFilterFormatsConfig *config;
> + enum AVMediaType media_type;
> + int ret = 0;
> +
> + if (filter->formats_state == FF_FILTER_FORMATS_PASSTHROUGH) {
> + av_bprintf(bp, "All (passthrough)");
> + return 0;
> + }
> +
> + graph = avfilter_graph_alloc();
> + if (!graph) {
> + av_log(NULL, AV_LOG_ERROR, "Failed to create filtergraph\n");
> + ret = AVERROR(ENOMEM);
> + goto cleanup;
> + }
> +
> + filter_context = avfilter_graph_alloc_filter(graph, filter, "filter");
> + if (!filter_context) {
> + av_log(NULL, AV_LOG_ERROR, "Failed to create filter\n");
> + ret = AVERROR(ENOMEM);
> + goto cleanup;
> + }
> +
> + avfilter_init_str(filter_context, NULL);
> +
> + if (filter->formats_state == FF_FILTER_FORMATS_QUERY_FUNC)
> + av_bprintf(bp, "Dynamic");
> +
> + if (!for_output && pad_index >= filter_context->nb_inputs
> + || for_output && pad_index >= filter_context->nb_outputs)
> + goto cleanup;
> +
> + avfilter_graph_config(graph, graph);
> +
> + for (unsigned i = 0; i < filter_context->nb_inputs; i++)
> + filter_context->inputs[i] = (AVFilterLink
> *)av_mallocz(sizeof(AVFilterLink));
> +
> + for (unsigned i = 0; i < filter_context->nb_outputs; i++)
> + filter_context->outputs[i] = (AVFilterLink
> *)av_mallocz(sizeof(AVFilterLink));
> +
> + ff_filter_query_formats(filter_context);
> +
> + config = for_output ? &filter_context->outputs[pad_index]->incfg :
> &filter_context->inputs[pad_index]->outcfg;
> +
> + if (!config || !config->formats)
> + goto cleanup;
> +
> + media_type= for_output ? filter->outputs[pad_index].type :
> filter->inputs[pad_index].type;
> +
> + if (filter->formats_state == FF_FILTER_FORMATS_QUERY_FUNC) {
> + if (config->formats && config->formats->nb_formats)
> + av_bprintf(bp, ", Default: ");
> + }
> +
> + if (config->formats == NULL)
> + av_bprintf(bp, "unknown");
> + else if (media_type == AVMEDIA_TYPE_VIDEO &&
> config->formats->nb_formats == get_nb_pix_fmts() ||
> + media_type == AVMEDIA_TYPE_AUDIO &&
> config->formats->nb_formats == get_nb_sample_fmts())
> + av_bprintf(bp, "All");
> + else {
> + for (unsigned i = 0; i < config->formats->nb_formats; i++) {
> + if (i == 0)
> + av_bprintf(bp, "[");
> +
> + if (media_type == AVMEDIA_TYPE_VIDEO)
> + av_bprintf(bp, "%s",
> av_get_pix_fmt_name(config->formats->formats[i]));
> + else if (media_type == AVMEDIA_TYPE_AUDIO)
> + av_bprintf(bp, "%s",
> av_get_sample_fmt_name(config->formats->formats[i]));
> +
> + if (i < config->formats->nb_formats - 1)
> + av_bprintf(bp, ", ");
> + else
> + av_bprintf(bp, "]"); }
> + }
> +
> +cleanup:
> + avfilter_graph_free(&graph);
> + return ret;
> +}
> +
> void ff_filter_set_ready(AVFilterContext *filter, unsigned priority)
> {
> filter->ready = FFMAX(filter->ready, priority);
> @@ -759,12 +857,12 @@ void avfilter_free(AVFilterContext *filter)
>
> for (i = 0; i < filter->nb_inputs; i++) {
> free_link(filter->inputs[i]);
> - if (filter->input_pads[i].flags & AVFILTERPAD_FLAG_FREE_NAME)
> + if (filter->input_pads && filter->input_pads[i].flags &
> AVFILTERPAD_FLAG_FREE_NAME)
> av_freep(&filter->input_pads[i].name);
> }
> for (i = 0; i < filter->nb_outputs; i++) {
> free_link(filter->outputs[i]);
> - if (filter->output_pads[i].flags & AVFILTERPAD_FLAG_FREE_NAME)
> + if (filter->output_pads && filter->output_pads[i].flags &
> AVFILTERPAD_FLAG_FREE_NAME)
> av_freep(&filter->output_pads[i].name);
> }
>
> diff --git a/libavfilter/avfilter.h b/libavfilter/avfilter.h
> index 2e8197c9a6..705dabe53c 100644
> --- a/libavfilter/avfilter.h
> +++ b/libavfilter/avfilter.h
> @@ -41,6 +41,7 @@
> #include "libavutil/avutil.h"
> #include "libavutil/buffer.h"
> #include "libavutil/dict.h"
> +#include "libavutil/bprint.h"
> #include "libavutil/frame.h"
> #include "libavutil/log.h"
> #include "libavutil/samplefmt.h"
> @@ -738,6 +739,17 @@ int avfilter_link(AVFilterContext *src, unsigned
> srcpad,
> */
> void avfilter_link_free(AVFilterLink **link);
>
> +/**
> + * Gets the formats from an AVFilterFormatsConfig.
> + *
> + * @param bp an instance of AVBPrint
> + * @param filter the AVFilter
> + * @param for_output set to 1 for filter outputs
> + * @param pad_index the index of the input or output
> + * @return zero on success
> + */
> +int avfilter_print_config_formats(AVBPrint *bp, const AVFilter *filter, int
> for_output, unsigned pad_index);
> +
> /**
> * Negotiate the media format, dimensions, etc of all inputs to a filter.
> *
> diff --git a/libavfilter/avfiltergraph.c b/libavfilter/avfiltergraph.c
> index 53f468494d..9118a44e1f 100644
> --- a/libavfilter/avfiltergraph.c
> +++ b/libavfilter/avfiltergraph.c
> @@ -416,10 +416,7 @@ static int query_formats(AVFilterGraph *graph, void
> *log_ctx)
> AVFilterContext *f = graph->filters[i];
> if (formats_declared(f))
> continue;
> - if (f->filter->formats_state == FF_FILTER_FORMATS_QUERY_FUNC)
> - ret = filter_query_formats(f);
> - else
> - ret = ff_default_query_formats(f);
> + ret = ff_filter_query_formats(f);
> if (ret < 0 && ret != AVERROR(EAGAIN))
> return ret;
> /* note: EAGAIN could indicate a partial success, not counted yet
> */
> @@ -1351,3 +1348,12 @@ int ff_filter_graph_run_once(AVFilterGraph *graph)
> return AVERROR(EAGAIN);
> return ff_filter_activate(filter);
> }
> +
> +int ff_filter_query_formats(AVFilterContext *filter)
> +{
> + if (filter->filter->formats_state == FF_FILTER_FORMATS_QUERY_FUNC)
> + return filter_query_formats(filter);
> +
> + return ff_default_query_formats(filter);
> +}
> +
> diff --git a/libavfilter/internal.h b/libavfilter/internal.h
> index aaf2c6c584..446d2a45f8 100644
> --- a/libavfilter/internal.h
> +++ b/libavfilter/internal.h
> @@ -374,6 +374,15 @@ void ff_filter_graph_remove_filter(AVFilterGraph
> *graph, AVFilterContext *filter
> */
> int ff_filter_graph_run_once(AVFilterGraph *graph);
>
> +/**
> + * Query the formats of a filter.
> + *
> + * @param filter the filter context
> + *
> + * @return 0 on success
> + */
> +int ff_filter_query_formats(AVFilterContext *filter);
> +
> /**
> * Get number of threads for current filter instance.
> * This number is always same or less than graph->nb_threads.
> diff --git a/libavfilter/version.h b/libavfilter/version.h
> index 4ccbf5641c..436c2b8b17 100644
> --- a/libavfilter/version.h
> +++ b/libavfilter/version.h
> @@ -31,8 +31,8 @@
>
> #include "version_major.h"
>
> -#define LIBAVFILTER_VERSION_MINOR 49
> -#define LIBAVFILTER_VERSION_MICRO 101
> +#define LIBAVFILTER_VERSION_MINOR 50
> +#define LIBAVFILTER_VERSION_MICRO 100
>
>
> #define LIBAVFILTER_VERSION_INT AV_VERSION_INT(LIBAVFILTER_VERSION_MAJOR,
> \
> --
> ffmpeg-codebot
>
LGTM
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
>
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [FFmpeg-devel] [PATCH 1/2] avfilter/avfilter: add avfilter_print_config_formats()
2022-11-03 9:58 ` Paul B Mahol
@ 2022-11-03 22:34 ` Soft Works
2022-12-12 23:13 ` Soft Works
1 sibling, 0 replies; 10+ messages in thread
From: Soft Works @ 2022-11-03 22:34 UTC (permalink / raw)
To: Paul B Mahol, FFmpeg development discussions and patches
> -----Original Message-----
> From: Paul B Mahol <onemda@gmail.com>
> Sent: Thursday, November 3, 2022 10:58 AM
> To: FFmpeg development discussions and patches <ffmpeg-
> devel@ffmpeg.org>
> Cc: softworkz <softworkz@hotmail.com>
> Subject: Re: [FFmpeg-devel] [PATCH 1/2] avfilter/avfilter: add
> avfilter_print_config_formats()
>
> On 10/11/22, softworkz <ffmpegagent@gmail.com> wrote:
> > From: softworkz <softworkz@hotmail.com>
> >
> > Prints the following to AVBPrint:
> >
> > For pass-through filter links:
> >
> > "All (passthrough)"
> >
> > For filters using query_formats:
> >
> > "Dynamic"
> >
> > For filters using query_formats where a call to query_formats
> > succeeds (example):
> >
> > "Dynamic, Defaults: [yuv420p, yuvj420p, yuva420p, nv12, nv21]"
> >
> > For all other filters (example):
> >
> > "[s16p, s32p, fltp, dblp]"
> >
> > Except in case when the number of formats equals the number of
> > available formats:
> >
> > "All"
> >
> > Signed-off-by: softworkz <softworkz@hotmail.com>
> > ---
> > doc/APIchanges | 3 ++
> > libavfilter/avfilter.c | 102
> +++++++++++++++++++++++++++++++++++-
> > libavfilter/avfilter.h | 12 +++++
> > libavfilter/avfiltergraph.c | 14 +++--
> > libavfilter/internal.h | 9 ++++
> > libavfilter/version.h | 4 +-
> > 6 files changed, 136 insertions(+), 8 deletions(-)
> >
> > diff --git a/doc/APIchanges b/doc/APIchanges
> > index cbb579612e..6e2a528b04 100644
> > --- a/doc/APIchanges
> > +++ b/doc/APIchanges
> > @@ -14,6 +14,9 @@ libavutil: 2021-04-27
> >
> > API changes, most recent first:
> >
> > +2022-10-11 - xxxxxxxxxx - lavf 59.50.100 - avfilter.h
> > + Add add avfilter_print_config_formats().
> > +
> > 2022-10-05 - 37d5ddc317 - lavu 57.39.100 - cpu.h
> > Add AV_CPU_FLAG_RVB_BASIC.
> >
> > diff --git a/libavfilter/avfilter.c b/libavfilter/avfilter.c
> > index cc5505e65b..8cc665e19c 100644
> > --- a/libavfilter/avfilter.c
> > +++ b/libavfilter/avfilter.c
> > @@ -196,6 +196,104 @@ void avfilter_link_free(AVFilterLink **link)
> > av_freep(link);
> > }
> >
> > +static unsigned get_nb_pix_fmts()
> > +{
> > + unsigned i = 0;
> > + while (av_pix_fmt_desc_get(i++)) {}
> > + return i - 1;
> > +}
> > +
> > +static unsigned get_nb_sample_fmts()
> > +{
> > + unsigned i = 0;
> > + while (av_get_sample_fmt_name(i++)) {}
> > + return i - 1;
> > +}
> > +
> > +int avfilter_print_config_formats(AVBPrint *bp, const struct
> AVFilter
> > *filter, int for_output, unsigned pad_index)
> > +{
> > + AVFilterGraph *graph;
> > + AVFilterContext *filter_context;
> > + AVFilterFormatsConfig *config;
> > + enum AVMediaType media_type;
> > + int ret = 0;
> > +
> > + if (filter->formats_state == FF_FILTER_FORMATS_PASSTHROUGH) {
> > + av_bprintf(bp, "All (passthrough)");
> > + return 0;
> > + }
> > +
> > + graph = avfilter_graph_alloc();
> > + if (!graph) {
> > + av_log(NULL, AV_LOG_ERROR, "Failed to create
> filtergraph\n");
> > + ret = AVERROR(ENOMEM);
> > + goto cleanup;
> > + }
> > +
> > + filter_context = avfilter_graph_alloc_filter(graph, filter,
> "filter");
> > + if (!filter_context) {
> > + av_log(NULL, AV_LOG_ERROR, "Failed to create filter\n");
> > + ret = AVERROR(ENOMEM);
> > + goto cleanup;
> > + }
> > +
> > + avfilter_init_str(filter_context, NULL);
> > +
> > + if (filter->formats_state == FF_FILTER_FORMATS_QUERY_FUNC)
> > + av_bprintf(bp, "Dynamic");
> > +
> > + if (!for_output && pad_index >= filter_context->nb_inputs
> > + || for_output && pad_index >= filter_context->nb_outputs)
> > + goto cleanup;
> > +
> > + avfilter_graph_config(graph, graph);
> > +
> > + for (unsigned i = 0; i < filter_context->nb_inputs; i++)
> > + filter_context->inputs[i] = (AVFilterLink
> > *)av_mallocz(sizeof(AVFilterLink));
> > +
> > + for (unsigned i = 0; i < filter_context->nb_outputs; i++)
> > + filter_context->outputs[i] = (AVFilterLink
> > *)av_mallocz(sizeof(AVFilterLink));
> > +
> > + ff_filter_query_formats(filter_context);
> > +
> > + config = for_output ? &filter_context->outputs[pad_index]-
> >incfg :
> > &filter_context->inputs[pad_index]->outcfg;
> > +
> > + if (!config || !config->formats)
> > + goto cleanup;
> > +
> > + media_type= for_output ? filter->outputs[pad_index].type :
> > filter->inputs[pad_index].type;
> > +
> > + if (filter->formats_state == FF_FILTER_FORMATS_QUERY_FUNC) {
> > + if (config->formats && config->formats->nb_formats)
> > + av_bprintf(bp, ", Default: ");
> > + }
> > +
> > + if (config->formats == NULL)
> > + av_bprintf(bp, "unknown");
> > + else if (media_type == AVMEDIA_TYPE_VIDEO &&
> > config->formats->nb_formats == get_nb_pix_fmts() ||
> > + media_type == AVMEDIA_TYPE_AUDIO &&
> > config->formats->nb_formats == get_nb_sample_fmts())
> > + av_bprintf(bp, "All");
> > + else {
> > + for (unsigned i = 0; i < config->formats->nb_formats; i++)
> {
> > + if (i == 0)
> > + av_bprintf(bp, "[");
> > +
> > + if (media_type == AVMEDIA_TYPE_VIDEO)
> > + av_bprintf(bp, "%s",
> > av_get_pix_fmt_name(config->formats->formats[i]));
> > + else if (media_type == AVMEDIA_TYPE_AUDIO)
> > + av_bprintf(bp, "%s",
> > av_get_sample_fmt_name(config->formats->formats[i]));
> > +
> > + if (i < config->formats->nb_formats - 1)
> > + av_bprintf(bp, ", ");
> > + else
> > + av_bprintf(bp, "]"); }
> > + }
> > +
> > +cleanup:
> > + avfilter_graph_free(&graph);
> > + return ret;
> > +}
> > +
> > void ff_filter_set_ready(AVFilterContext *filter, unsigned
> priority)
> > {
> > filter->ready = FFMAX(filter->ready, priority);
> > @@ -759,12 +857,12 @@ void avfilter_free(AVFilterContext *filter)
> >
> > for (i = 0; i < filter->nb_inputs; i++) {
> > free_link(filter->inputs[i]);
> > - if (filter->input_pads[i].flags &
> AVFILTERPAD_FLAG_FREE_NAME)
> > + if (filter->input_pads && filter->input_pads[i].flags &
> > AVFILTERPAD_FLAG_FREE_NAME)
> > av_freep(&filter->input_pads[i].name);
> > }
> > for (i = 0; i < filter->nb_outputs; i++) {
> > free_link(filter->outputs[i]);
> > - if (filter->output_pads[i].flags &
> AVFILTERPAD_FLAG_FREE_NAME)
> > + if (filter->output_pads && filter->output_pads[i].flags &
> > AVFILTERPAD_FLAG_FREE_NAME)
> > av_freep(&filter->output_pads[i].name);
> > }
> >
> > diff --git a/libavfilter/avfilter.h b/libavfilter/avfilter.h
> > index 2e8197c9a6..705dabe53c 100644
> > --- a/libavfilter/avfilter.h
> > +++ b/libavfilter/avfilter.h
> > @@ -41,6 +41,7 @@
> > #include "libavutil/avutil.h"
> > #include "libavutil/buffer.h"
> > #include "libavutil/dict.h"
> > +#include "libavutil/bprint.h"
> > #include "libavutil/frame.h"
> > #include "libavutil/log.h"
> > #include "libavutil/samplefmt.h"
> > @@ -738,6 +739,17 @@ int avfilter_link(AVFilterContext *src,
> unsigned
> > srcpad,
> > */
> > void avfilter_link_free(AVFilterLink **link);
> >
> > +/**
> > + * Gets the formats from an AVFilterFormatsConfig.
> > + *
> > + * @param bp an instance of AVBPrint
> > + * @param filter the AVFilter
> > + * @param for_output set to 1 for filter outputs
> > + * @param pad_index the index of the input or output
> > + * @return zero on success
> > + */
> > +int avfilter_print_config_formats(AVBPrint *bp, const AVFilter
> *filter, int
> > for_output, unsigned pad_index);
> > +
> > /**
> > * Negotiate the media format, dimensions, etc of all inputs to a
> filter.
> > *
> > diff --git a/libavfilter/avfiltergraph.c
> b/libavfilter/avfiltergraph.c
> > index 53f468494d..9118a44e1f 100644
> > --- a/libavfilter/avfiltergraph.c
> > +++ b/libavfilter/avfiltergraph.c
> > @@ -416,10 +416,7 @@ static int query_formats(AVFilterGraph *graph,
> void
> > *log_ctx)
> > AVFilterContext *f = graph->filters[i];
> > if (formats_declared(f))
> > continue;
> > - if (f->filter->formats_state ==
> FF_FILTER_FORMATS_QUERY_FUNC)
> > - ret = filter_query_formats(f);
> > - else
> > - ret = ff_default_query_formats(f);
> > + ret = ff_filter_query_formats(f);
> > if (ret < 0 && ret != AVERROR(EAGAIN))
> > return ret;
> > /* note: EAGAIN could indicate a partial success, not
> counted yet
> > */
> > @@ -1351,3 +1348,12 @@ int ff_filter_graph_run_once(AVFilterGraph
> *graph)
> > return AVERROR(EAGAIN);
> > return ff_filter_activate(filter);
> > }
> > +
> > +int ff_filter_query_formats(AVFilterContext *filter)
> > +{
> > + if (filter->filter->formats_state ==
> FF_FILTER_FORMATS_QUERY_FUNC)
> > + return filter_query_formats(filter);
> > +
> > + return ff_default_query_formats(filter);
> > +}
> > +
> > diff --git a/libavfilter/internal.h b/libavfilter/internal.h
> > index aaf2c6c584..446d2a45f8 100644
> > --- a/libavfilter/internal.h
> > +++ b/libavfilter/internal.h
> > @@ -374,6 +374,15 @@ void
> ff_filter_graph_remove_filter(AVFilterGraph
> > *graph, AVFilterContext *filter
> > */
> > int ff_filter_graph_run_once(AVFilterGraph *graph);
> >
> > +/**
> > + * Query the formats of a filter.
> > + *
> > + * @param filter the filter context
> > + *
> > + * @return 0 on success
> > + */
> > +int ff_filter_query_formats(AVFilterContext *filter);
> > +
> > /**
> > * Get number of threads for current filter instance.
> > * This number is always same or less than graph->nb_threads.
> > diff --git a/libavfilter/version.h b/libavfilter/version.h
> > index 4ccbf5641c..436c2b8b17 100644
> > --- a/libavfilter/version.h
> > +++ b/libavfilter/version.h
> > @@ -31,8 +31,8 @@
> >
> > #include "version_major.h"
> >
> > -#define LIBAVFILTER_VERSION_MINOR 49
> > -#define LIBAVFILTER_VERSION_MICRO 101
> > +#define LIBAVFILTER_VERSION_MINOR 50
> > +#define LIBAVFILTER_VERSION_MICRO 100
> >
> >
> > #define LIBAVFILTER_VERSION_INT
> AV_VERSION_INT(LIBAVFILTER_VERSION_MAJOR,
> > \
> > --
> > ffmpeg-codebot
> >
>
>
> LGTM
>
Thanks a lot for reviewing.
While reworking, I also figured why you had called my earlier
version a 'hack', so nevermind on that..
Best,
softworkz
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [FFmpeg-devel] [PATCH 1/2] avfilter/avfilter: add avfilter_print_config_formats()
2022-11-03 9:58 ` Paul B Mahol
2022-11-03 22:34 ` Soft Works
@ 2022-12-12 23:13 ` Soft Works
2022-12-26 20:24 ` Paul B Mahol
1 sibling, 1 reply; 10+ messages in thread
From: Soft Works @ 2022-12-12 23:13 UTC (permalink / raw)
To: Paul B Mahol, FFmpeg development discussions and patches
Another Ping
Thanks,
softworkz
> -----Original Message-----
> From: Paul B Mahol <onemda@gmail.com>
> Sent: Thursday, November 3, 2022 10:58 AM
> To: FFmpeg development discussions and patches <ffmpeg-
> devel@ffmpeg.org>
> Cc: softworkz <softworkz@hotmail.com>
> Subject: Re: [FFmpeg-devel] [PATCH 1/2] avfilter/avfilter: add
> avfilter_print_config_formats()
>
> On 10/11/22, softworkz <ffmpegagent@gmail.com> wrote:
> > From: softworkz <softworkz@hotmail.com>
> >
> > Prints the following to AVBPrint:
> >
> > For pass-through filter links:
> >
> > "All (passthrough)"
> >
> > For filters using query_formats:
> >
> > "Dynamic"
> >
> > For filters using query_formats where a call to query_formats
> > succeeds (example):
> >
> > "Dynamic, Defaults: [yuv420p, yuvj420p, yuva420p, nv12, nv21]"
> >
> > For all other filters (example):
> >
> > "[s16p, s32p, fltp, dblp]"
> >
> > Except in case when the number of formats equals the number of
> > available formats:
> >
> > "All"
> >
> > Signed-off-by: softworkz <softworkz@hotmail.com>
> > ---
> > doc/APIchanges | 3 ++
> > libavfilter/avfilter.c | 102
> +++++++++++++++++++++++++++++++++++-
> > libavfilter/avfilter.h | 12 +++++
> > libavfilter/avfiltergraph.c | 14 +++--
> > libavfilter/internal.h | 9 ++++
> > libavfilter/version.h | 4 +-
> > 6 files changed, 136 insertions(+), 8 deletions(-)
> >
> > diff --git a/doc/APIchanges b/doc/APIchanges
> > index cbb579612e..6e2a528b04 100644
> > --- a/doc/APIchanges
> > +++ b/doc/APIchanges
> > @@ -14,6 +14,9 @@ libavutil: 2021-04-27
> >
> > API changes, most recent first:
> >
> > +2022-10-11 - xxxxxxxxxx - lavf 59.50.100 - avfilter.h
> > + Add add avfilter_print_config_formats().
> > +
> > 2022-10-05 - 37d5ddc317 - lavu 57.39.100 - cpu.h
> > Add AV_CPU_FLAG_RVB_BASIC.
> >
> > diff --git a/libavfilter/avfilter.c b/libavfilter/avfilter.c
> > index cc5505e65b..8cc665e19c 100644
> > --- a/libavfilter/avfilter.c
> > +++ b/libavfilter/avfilter.c
> > @@ -196,6 +196,104 @@ void avfilter_link_free(AVFilterLink **link)
> > av_freep(link);
> > }
> >
> > +static unsigned get_nb_pix_fmts()
> > +{
> > + unsigned i = 0;
> > + while (av_pix_fmt_desc_get(i++)) {}
> > + return i - 1;
> > +}
> > +
> > +static unsigned get_nb_sample_fmts()
> > +{
> > + unsigned i = 0;
> > + while (av_get_sample_fmt_name(i++)) {}
> > + return i - 1;
> > +}
> > +
> > +int avfilter_print_config_formats(AVBPrint *bp, const struct
> AVFilter
> > *filter, int for_output, unsigned pad_index)
> > +{
> > + AVFilterGraph *graph;
> > + AVFilterContext *filter_context;
> > + AVFilterFormatsConfig *config;
> > + enum AVMediaType media_type;
> > + int ret = 0;
> > +
> > + if (filter->formats_state == FF_FILTER_FORMATS_PASSTHROUGH) {
> > + av_bprintf(bp, "All (passthrough)");
> > + return 0;
> > + }
> > +
> > + graph = avfilter_graph_alloc();
> > + if (!graph) {
> > + av_log(NULL, AV_LOG_ERROR, "Failed to create
> filtergraph\n");
> > + ret = AVERROR(ENOMEM);
> > + goto cleanup;
> > + }
> > +
> > + filter_context = avfilter_graph_alloc_filter(graph, filter,
> "filter");
> > + if (!filter_context) {
> > + av_log(NULL, AV_LOG_ERROR, "Failed to create filter\n");
> > + ret = AVERROR(ENOMEM);
> > + goto cleanup;
> > + }
> > +
> > + avfilter_init_str(filter_context, NULL);
> > +
> > + if (filter->formats_state == FF_FILTER_FORMATS_QUERY_FUNC)
> > + av_bprintf(bp, "Dynamic");
> > +
> > + if (!for_output && pad_index >= filter_context->nb_inputs
> > + || for_output && pad_index >= filter_context->nb_outputs)
> > + goto cleanup;
> > +
> > + avfilter_graph_config(graph, graph);
> > +
> > + for (unsigned i = 0; i < filter_context->nb_inputs; i++)
> > + filter_context->inputs[i] = (AVFilterLink
> > *)av_mallocz(sizeof(AVFilterLink));
> > +
> > + for (unsigned i = 0; i < filter_context->nb_outputs; i++)
> > + filter_context->outputs[i] = (AVFilterLink
> > *)av_mallocz(sizeof(AVFilterLink));
> > +
> > + ff_filter_query_formats(filter_context);
> > +
> > + config = for_output ? &filter_context->outputs[pad_index]-
> >incfg :
> > &filter_context->inputs[pad_index]->outcfg;
> > +
> > + if (!config || !config->formats)
> > + goto cleanup;
> > +
> > + media_type= for_output ? filter->outputs[pad_index].type :
> > filter->inputs[pad_index].type;
> > +
> > + if (filter->formats_state == FF_FILTER_FORMATS_QUERY_FUNC) {
> > + if (config->formats && config->formats->nb_formats)
> > + av_bprintf(bp, ", Default: ");
> > + }
> > +
> > + if (config->formats == NULL)
> > + av_bprintf(bp, "unknown");
> > + else if (media_type == AVMEDIA_TYPE_VIDEO &&
> > config->formats->nb_formats == get_nb_pix_fmts() ||
> > + media_type == AVMEDIA_TYPE_AUDIO &&
> > config->formats->nb_formats == get_nb_sample_fmts())
> > + av_bprintf(bp, "All");
> > + else {
> > + for (unsigned i = 0; i < config->formats->nb_formats; i++)
> {
> > + if (i == 0)
> > + av_bprintf(bp, "[");
> > +
> > + if (media_type == AVMEDIA_TYPE_VIDEO)
> > + av_bprintf(bp, "%s",
> > av_get_pix_fmt_name(config->formats->formats[i]));
> > + else if (media_type == AVMEDIA_TYPE_AUDIO)
> > + av_bprintf(bp, "%s",
> > av_get_sample_fmt_name(config->formats->formats[i]));
> > +
> > + if (i < config->formats->nb_formats - 1)
> > + av_bprintf(bp, ", ");
> > + else
> > + av_bprintf(bp, "]"); }
> > + }
> > +
> > +cleanup:
> > + avfilter_graph_free(&graph);
> > + return ret;
> > +}
> > +
> > void ff_filter_set_ready(AVFilterContext *filter, unsigned
> priority)
> > {
> > filter->ready = FFMAX(filter->ready, priority);
> > @@ -759,12 +857,12 @@ void avfilter_free(AVFilterContext *filter)
> >
> > for (i = 0; i < filter->nb_inputs; i++) {
> > free_link(filter->inputs[i]);
> > - if (filter->input_pads[i].flags &
> AVFILTERPAD_FLAG_FREE_NAME)
> > + if (filter->input_pads && filter->input_pads[i].flags &
> > AVFILTERPAD_FLAG_FREE_NAME)
> > av_freep(&filter->input_pads[i].name);
> > }
> > for (i = 0; i < filter->nb_outputs; i++) {
> > free_link(filter->outputs[i]);
> > - if (filter->output_pads[i].flags &
> AVFILTERPAD_FLAG_FREE_NAME)
> > + if (filter->output_pads && filter->output_pads[i].flags &
> > AVFILTERPAD_FLAG_FREE_NAME)
> > av_freep(&filter->output_pads[i].name);
> > }
> >
> > diff --git a/libavfilter/avfilter.h b/libavfilter/avfilter.h
> > index 2e8197c9a6..705dabe53c 100644
> > --- a/libavfilter/avfilter.h
> > +++ b/libavfilter/avfilter.h
> > @@ -41,6 +41,7 @@
> > #include "libavutil/avutil.h"
> > #include "libavutil/buffer.h"
> > #include "libavutil/dict.h"
> > +#include "libavutil/bprint.h"
> > #include "libavutil/frame.h"
> > #include "libavutil/log.h"
> > #include "libavutil/samplefmt.h"
> > @@ -738,6 +739,17 @@ int avfilter_link(AVFilterContext *src,
> unsigned
> > srcpad,
> > */
> > void avfilter_link_free(AVFilterLink **link);
> >
> > +/**
> > + * Gets the formats from an AVFilterFormatsConfig.
> > + *
> > + * @param bp an instance of AVBPrint
> > + * @param filter the AVFilter
> > + * @param for_output set to 1 for filter outputs
> > + * @param pad_index the index of the input or output
> > + * @return zero on success
> > + */
> > +int avfilter_print_config_formats(AVBPrint *bp, const AVFilter
> *filter, int
> > for_output, unsigned pad_index);
> > +
> > /**
> > * Negotiate the media format, dimensions, etc of all inputs to a
> filter.
> > *
> > diff --git a/libavfilter/avfiltergraph.c
> b/libavfilter/avfiltergraph.c
> > index 53f468494d..9118a44e1f 100644
> > --- a/libavfilter/avfiltergraph.c
> > +++ b/libavfilter/avfiltergraph.c
> > @@ -416,10 +416,7 @@ static int query_formats(AVFilterGraph *graph,
> void
> > *log_ctx)
> > AVFilterContext *f = graph->filters[i];
> > if (formats_declared(f))
> > continue;
> > - if (f->filter->formats_state ==
> FF_FILTER_FORMATS_QUERY_FUNC)
> > - ret = filter_query_formats(f);
> > - else
> > - ret = ff_default_query_formats(f);
> > + ret = ff_filter_query_formats(f);
> > if (ret < 0 && ret != AVERROR(EAGAIN))
> > return ret;
> > /* note: EAGAIN could indicate a partial success, not
> counted yet
> > */
> > @@ -1351,3 +1348,12 @@ int ff_filter_graph_run_once(AVFilterGraph
> *graph)
> > return AVERROR(EAGAIN);
> > return ff_filter_activate(filter);
> > }
> > +
> > +int ff_filter_query_formats(AVFilterContext *filter)
> > +{
> > + if (filter->filter->formats_state ==
> FF_FILTER_FORMATS_QUERY_FUNC)
> > + return filter_query_formats(filter);
> > +
> > + return ff_default_query_formats(filter);
> > +}
> > +
> > diff --git a/libavfilter/internal.h b/libavfilter/internal.h
> > index aaf2c6c584..446d2a45f8 100644
> > --- a/libavfilter/internal.h
> > +++ b/libavfilter/internal.h
> > @@ -374,6 +374,15 @@ void
> ff_filter_graph_remove_filter(AVFilterGraph
> > *graph, AVFilterContext *filter
> > */
> > int ff_filter_graph_run_once(AVFilterGraph *graph);
> >
> > +/**
> > + * Query the formats of a filter.
> > + *
> > + * @param filter the filter context
> > + *
> > + * @return 0 on success
> > + */
> > +int ff_filter_query_formats(AVFilterContext *filter);
> > +
> > /**
> > * Get number of threads for current filter instance.
> > * This number is always same or less than graph->nb_threads.
> > diff --git a/libavfilter/version.h b/libavfilter/version.h
> > index 4ccbf5641c..436c2b8b17 100644
> > --- a/libavfilter/version.h
> > +++ b/libavfilter/version.h
> > @@ -31,8 +31,8 @@
> >
> > #include "version_major.h"
> >
> > -#define LIBAVFILTER_VERSION_MINOR 49
> > -#define LIBAVFILTER_VERSION_MICRO 101
> > +#define LIBAVFILTER_VERSION_MINOR 50
> > +#define LIBAVFILTER_VERSION_MICRO 100
> >
> >
> > #define LIBAVFILTER_VERSION_INT
> AV_VERSION_INT(LIBAVFILTER_VERSION_MAJOR,
> > \
> > --
> > ffmpeg-codebot
> >
>
>
> LGTM
>
> > _______________________________________________
> > ffmpeg-devel mailing list
> > ffmpeg-devel@ffmpeg.org
> > https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
> >
> > To unsubscribe, visit link above, or email
> > ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
> >
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [FFmpeg-devel] [PATCH 1/2] avfilter/avfilter: add avfilter_print_config_formats()
2022-12-12 23:13 ` Soft Works
@ 2022-12-26 20:24 ` Paul B Mahol
0 siblings, 0 replies; 10+ messages in thread
From: Paul B Mahol @ 2022-12-26 20:24 UTC (permalink / raw)
To: Soft Works; +Cc: FFmpeg development discussions and patches
On 12/13/22, Soft Works <softworkz@hotmail.com> wrote:
> Another Ping
Please confirm that this still applies without issues,
otherwise provide new patches for this feature so i can apply it.
>
> Thanks,
> softworkz
>
>> -----Original Message-----
>> From: Paul B Mahol <onemda@gmail.com>
>> Sent: Thursday, November 3, 2022 10:58 AM
>> To: FFmpeg development discussions and patches <ffmpeg-
>> devel@ffmpeg.org>
>> Cc: softworkz <softworkz@hotmail.com>
>> Subject: Re: [FFmpeg-devel] [PATCH 1/2] avfilter/avfilter: add
>> avfilter_print_config_formats()
>>
>> On 10/11/22, softworkz <ffmpegagent@gmail.com> wrote:
>> > From: softworkz <softworkz@hotmail.com>
>> >
>> > Prints the following to AVBPrint:
>> >
>> > For pass-through filter links:
>> >
>> > "All (passthrough)"
>> >
>> > For filters using query_formats:
>> >
>> > "Dynamic"
>> >
>> > For filters using query_formats where a call to query_formats
>> > succeeds (example):
>> >
>> > "Dynamic, Defaults: [yuv420p, yuvj420p, yuva420p, nv12, nv21]"
>> >
>> > For all other filters (example):
>> >
>> > "[s16p, s32p, fltp, dblp]"
>> >
>> > Except in case when the number of formats equals the number of
>> > available formats:
>> >
>> > "All"
>> >
>> > Signed-off-by: softworkz <softworkz@hotmail.com>
>> > ---
>> > doc/APIchanges | 3 ++
>> > libavfilter/avfilter.c | 102
>> +++++++++++++++++++++++++++++++++++-
>> > libavfilter/avfilter.h | 12 +++++
>> > libavfilter/avfiltergraph.c | 14 +++--
>> > libavfilter/internal.h | 9 ++++
>> > libavfilter/version.h | 4 +-
>> > 6 files changed, 136 insertions(+), 8 deletions(-)
>> >
>> > diff --git a/doc/APIchanges b/doc/APIchanges
>> > index cbb579612e..6e2a528b04 100644
>> > --- a/doc/APIchanges
>> > +++ b/doc/APIchanges
>> > @@ -14,6 +14,9 @@ libavutil: 2021-04-27
>> >
>> > API changes, most recent first:
>> >
>> > +2022-10-11 - xxxxxxxxxx - lavf 59.50.100 - avfilter.h
>> > + Add add avfilter_print_config_formats().
>> > +
>> > 2022-10-05 - 37d5ddc317 - lavu 57.39.100 - cpu.h
>> > Add AV_CPU_FLAG_RVB_BASIC.
>> >
>> > diff --git a/libavfilter/avfilter.c b/libavfilter/avfilter.c
>> > index cc5505e65b..8cc665e19c 100644
>> > --- a/libavfilter/avfilter.c
>> > +++ b/libavfilter/avfilter.c
>> > @@ -196,6 +196,104 @@ void avfilter_link_free(AVFilterLink **link)
>> > av_freep(link);
>> > }
>> >
>> > +static unsigned get_nb_pix_fmts()
>> > +{
>> > + unsigned i = 0;
>> > + while (av_pix_fmt_desc_get(i++)) {}
>> > + return i - 1;
>> > +}
>> > +
>> > +static unsigned get_nb_sample_fmts()
>> > +{
>> > + unsigned i = 0;
>> > + while (av_get_sample_fmt_name(i++)) {}
>> > + return i - 1;
>> > +}
>> > +
>> > +int avfilter_print_config_formats(AVBPrint *bp, const struct
>> AVFilter
>> > *filter, int for_output, unsigned pad_index)
>> > +{
>> > + AVFilterGraph *graph;
>> > + AVFilterContext *filter_context;
>> > + AVFilterFormatsConfig *config;
>> > + enum AVMediaType media_type;
>> > + int ret = 0;
>> > +
>> > + if (filter->formats_state == FF_FILTER_FORMATS_PASSTHROUGH) {
>> > + av_bprintf(bp, "All (passthrough)");
>> > + return 0;
>> > + }
>> > +
>> > + graph = avfilter_graph_alloc();
>> > + if (!graph) {
>> > + av_log(NULL, AV_LOG_ERROR, "Failed to create
>> filtergraph\n");
>> > + ret = AVERROR(ENOMEM);
>> > + goto cleanup;
>> > + }
>> > +
>> > + filter_context = avfilter_graph_alloc_filter(graph, filter,
>> "filter");
>> > + if (!filter_context) {
>> > + av_log(NULL, AV_LOG_ERROR, "Failed to create filter\n");
>> > + ret = AVERROR(ENOMEM);
>> > + goto cleanup;
>> > + }
>> > +
>> > + avfilter_init_str(filter_context, NULL);
>> > +
>> > + if (filter->formats_state == FF_FILTER_FORMATS_QUERY_FUNC)
>> > + av_bprintf(bp, "Dynamic");
>> > +
>> > + if (!for_output && pad_index >= filter_context->nb_inputs
>> > + || for_output && pad_index >= filter_context->nb_outputs)
>> > + goto cleanup;
>> > +
>> > + avfilter_graph_config(graph, graph);
>> > +
>> > + for (unsigned i = 0; i < filter_context->nb_inputs; i++)
>> > + filter_context->inputs[i] = (AVFilterLink
>> > *)av_mallocz(sizeof(AVFilterLink));
>> > +
>> > + for (unsigned i = 0; i < filter_context->nb_outputs; i++)
>> > + filter_context->outputs[i] = (AVFilterLink
>> > *)av_mallocz(sizeof(AVFilterLink));
>> > +
>> > + ff_filter_query_formats(filter_context);
>> > +
>> > + config = for_output ? &filter_context->outputs[pad_index]-
>> >incfg :
>> > &filter_context->inputs[pad_index]->outcfg;
>> > +
>> > + if (!config || !config->formats)
>> > + goto cleanup;
>> > +
>> > + media_type= for_output ? filter->outputs[pad_index].type :
>> > filter->inputs[pad_index].type;
>> > +
>> > + if (filter->formats_state == FF_FILTER_FORMATS_QUERY_FUNC) {
>> > + if (config->formats && config->formats->nb_formats)
>> > + av_bprintf(bp, ", Default: ");
>> > + }
>> > +
>> > + if (config->formats == NULL)
>> > + av_bprintf(bp, "unknown");
>> > + else if (media_type == AVMEDIA_TYPE_VIDEO &&
>> > config->formats->nb_formats == get_nb_pix_fmts() ||
>> > + media_type == AVMEDIA_TYPE_AUDIO &&
>> > config->formats->nb_formats == get_nb_sample_fmts())
>> > + av_bprintf(bp, "All");
>> > + else {
>> > + for (unsigned i = 0; i < config->formats->nb_formats; i++)
>> {
>> > + if (i == 0)
>> > + av_bprintf(bp, "[");
>> > +
>> > + if (media_type == AVMEDIA_TYPE_VIDEO)
>> > + av_bprintf(bp, "%s",
>> > av_get_pix_fmt_name(config->formats->formats[i]));
>> > + else if (media_type == AVMEDIA_TYPE_AUDIO)
>> > + av_bprintf(bp, "%s",
>> > av_get_sample_fmt_name(config->formats->formats[i]));
>> > +
>> > + if (i < config->formats->nb_formats - 1)
>> > + av_bprintf(bp, ", ");
>> > + else
>> > + av_bprintf(bp, "]"); }
>> > + }
>> > +
>> > +cleanup:
>> > + avfilter_graph_free(&graph);
>> > + return ret;
>> > +}
>> > +
>> > void ff_filter_set_ready(AVFilterContext *filter, unsigned
>> priority)
>> > {
>> > filter->ready = FFMAX(filter->ready, priority);
>> > @@ -759,12 +857,12 @@ void avfilter_free(AVFilterContext *filter)
>> >
>> > for (i = 0; i < filter->nb_inputs; i++) {
>> > free_link(filter->inputs[i]);
>> > - if (filter->input_pads[i].flags &
>> AVFILTERPAD_FLAG_FREE_NAME)
>> > + if (filter->input_pads && filter->input_pads[i].flags &
>> > AVFILTERPAD_FLAG_FREE_NAME)
>> > av_freep(&filter->input_pads[i].name);
>> > }
>> > for (i = 0; i < filter->nb_outputs; i++) {
>> > free_link(filter->outputs[i]);
>> > - if (filter->output_pads[i].flags &
>> AVFILTERPAD_FLAG_FREE_NAME)
>> > + if (filter->output_pads && filter->output_pads[i].flags &
>> > AVFILTERPAD_FLAG_FREE_NAME)
>> > av_freep(&filter->output_pads[i].name);
>> > }
>> >
>> > diff --git a/libavfilter/avfilter.h b/libavfilter/avfilter.h
>> > index 2e8197c9a6..705dabe53c 100644
>> > --- a/libavfilter/avfilter.h
>> > +++ b/libavfilter/avfilter.h
>> > @@ -41,6 +41,7 @@
>> > #include "libavutil/avutil.h"
>> > #include "libavutil/buffer.h"
>> > #include "libavutil/dict.h"
>> > +#include "libavutil/bprint.h"
>> > #include "libavutil/frame.h"
>> > #include "libavutil/log.h"
>> > #include "libavutil/samplefmt.h"
>> > @@ -738,6 +739,17 @@ int avfilter_link(AVFilterContext *src,
>> unsigned
>> > srcpad,
>> > */
>> > void avfilter_link_free(AVFilterLink **link);
>> >
>> > +/**
>> > + * Gets the formats from an AVFilterFormatsConfig.
>> > + *
>> > + * @param bp an instance of AVBPrint
>> > + * @param filter the AVFilter
>> > + * @param for_output set to 1 for filter outputs
>> > + * @param pad_index the index of the input or output
>> > + * @return zero on success
>> > + */
>> > +int avfilter_print_config_formats(AVBPrint *bp, const AVFilter
>> *filter, int
>> > for_output, unsigned pad_index);
>> > +
>> > /**
>> > * Negotiate the media format, dimensions, etc of all inputs to a
>> filter.
>> > *
>> > diff --git a/libavfilter/avfiltergraph.c
>> b/libavfilter/avfiltergraph.c
>> > index 53f468494d..9118a44e1f 100644
>> > --- a/libavfilter/avfiltergraph.c
>> > +++ b/libavfilter/avfiltergraph.c
>> > @@ -416,10 +416,7 @@ static int query_formats(AVFilterGraph *graph,
>> void
>> > *log_ctx)
>> > AVFilterContext *f = graph->filters[i];
>> > if (formats_declared(f))
>> > continue;
>> > - if (f->filter->formats_state ==
>> FF_FILTER_FORMATS_QUERY_FUNC)
>> > - ret = filter_query_formats(f);
>> > - else
>> > - ret = ff_default_query_formats(f);
>> > + ret = ff_filter_query_formats(f);
>> > if (ret < 0 && ret != AVERROR(EAGAIN))
>> > return ret;
>> > /* note: EAGAIN could indicate a partial success, not
>> counted yet
>> > */
>> > @@ -1351,3 +1348,12 @@ int ff_filter_graph_run_once(AVFilterGraph
>> *graph)
>> > return AVERROR(EAGAIN);
>> > return ff_filter_activate(filter);
>> > }
>> > +
>> > +int ff_filter_query_formats(AVFilterContext *filter)
>> > +{
>> > + if (filter->filter->formats_state ==
>> FF_FILTER_FORMATS_QUERY_FUNC)
>> > + return filter_query_formats(filter);
>> > +
>> > + return ff_default_query_formats(filter);
>> > +}
>> > +
>> > diff --git a/libavfilter/internal.h b/libavfilter/internal.h
>> > index aaf2c6c584..446d2a45f8 100644
>> > --- a/libavfilter/internal.h
>> > +++ b/libavfilter/internal.h
>> > @@ -374,6 +374,15 @@ void
>> ff_filter_graph_remove_filter(AVFilterGraph
>> > *graph, AVFilterContext *filter
>> > */
>> > int ff_filter_graph_run_once(AVFilterGraph *graph);
>> >
>> > +/**
>> > + * Query the formats of a filter.
>> > + *
>> > + * @param filter the filter context
>> > + *
>> > + * @return 0 on success
>> > + */
>> > +int ff_filter_query_formats(AVFilterContext *filter);
>> > +
>> > /**
>> > * Get number of threads for current filter instance.
>> > * This number is always same or less than graph->nb_threads.
>> > diff --git a/libavfilter/version.h b/libavfilter/version.h
>> > index 4ccbf5641c..436c2b8b17 100644
>> > --- a/libavfilter/version.h
>> > +++ b/libavfilter/version.h
>> > @@ -31,8 +31,8 @@
>> >
>> > #include "version_major.h"
>> >
>> > -#define LIBAVFILTER_VERSION_MINOR 49
>> > -#define LIBAVFILTER_VERSION_MICRO 101
>> > +#define LIBAVFILTER_VERSION_MINOR 50
>> > +#define LIBAVFILTER_VERSION_MICRO 100
>> >
>> >
>> > #define LIBAVFILTER_VERSION_INT
>> AV_VERSION_INT(LIBAVFILTER_VERSION_MAJOR,
>> > \
>> > --
>> > ffmpeg-codebot
>> >
>>
>>
>> LGTM
>>
>> > _______________________________________________
>> > ffmpeg-devel mailing list
>> > ffmpeg-devel@ffmpeg.org
>> > https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>> >
>> > To unsubscribe, visit link above, or email
>> > ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
>> >
>
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 10+ messages in thread
* [FFmpeg-devel] [PATCH 2/2] ftools/opt_common: Print filter input/output formats in help output
2022-10-11 13:17 [FFmpeg-devel] [PATCH 0/2] Print filter input/output formats in help output ffmpegagent
2022-10-11 13:17 ` [FFmpeg-devel] [PATCH 1/2] avfilter/avfilter: add avfilter_print_config_formats() softworkz
@ 2022-10-11 13:17 ` softworkz
2022-10-11 21:38 ` [FFmpeg-devel] [PATCH v2 0/2] " ffmpegagent
2 siblings, 0 replies; 10+ messages in thread
From: softworkz @ 2022-10-11 13:17 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: softworkz
From: softworkz <softworkz@hotmail.com>
Exmaple command: ffmpeg -h filters=overlay
Output:
Filter overlay
Overlay a video source on top of the input.
slice threading supported
Inputs:
#0: main (video), Formats: Dynamic, Default: [yuv420p, yuvj420p,
yuva420p, nv12, nv21]
#1: overlay (video), Formats: Dynamic, Default: [yuva420p]
Outputs:
#0: default (video), Formats: Dynamic, Default: [yuv420p, yuvj420p,
yuva420p, nv12, nv21]
overlay AVOptions:
[...]
Signed-off-by: softworkz <softworkz@hotmail.com>
---
fftools/opt_common.c | 39 +++++++++++++++++++++++++++------------
1 file changed, 27 insertions(+), 12 deletions(-)
diff --git a/fftools/opt_common.c b/fftools/opt_common.c
index 8a06df82df..cb9de897a3 100644
--- a/fftools/opt_common.c
+++ b/fftools/opt_common.c
@@ -504,7 +504,8 @@ static void show_help_filter(const char *name)
{
#if CONFIG_AVFILTER
const AVFilter *f = avfilter_get_by_name(name);
- int i, count;
+ AVBPrint bp;
+ int i, count, ret;
if (!name) {
av_log(NULL, AV_LOG_ERROR, "No filter name specified.\n");
@@ -514,40 +515,54 @@ static void show_help_filter(const char *name)
return;
}
- printf("Filter %s\n", f->name);
+ av_bprint_init(&bp, 0, AV_BPRINT_SIZE_UNLIMITED);
+ av_log_set_callback(NULL);
+
+ av_bprintf(&bp, "Filter %s\n", f->name);
if (f->description)
- printf(" %s\n", f->description);
+ av_bprintf(&bp, " %s\n", f->description);
if (f->flags & AVFILTER_FLAG_SLICE_THREADS)
- printf(" slice threading supported\n");
+ av_bprintf(&bp, " slice threading supported\n");
- printf(" Inputs:\n");
+ av_bprintf(&bp, " Inputs:\n");
count = avfilter_filter_pad_count(f, 0);
for (i = 0; i < count; i++) {
- printf(" #%d: %s (%s)\n", i, avfilter_pad_get_name(f->inputs, i),
+ av_bprintf(&bp, " #%d: %s (%s), Formats: ", i, avfilter_pad_get_name(f->inputs, i),
av_get_media_type_string(avfilter_pad_get_type(f->inputs, i)));
+
+ avfilter_print_config_formats(&bp, f, 0, i);
+ av_bprintf(&bp, "\n");
}
if (f->flags & AVFILTER_FLAG_DYNAMIC_INPUTS)
- printf(" dynamic (depending on the options)\n");
+ av_bprintf(&bp, " dynamic (depending on the options)\n");
else if (!count)
- printf(" none (source filter)\n");
+ av_bprintf(&bp, " none (source filter)\n");
- printf(" Outputs:\n");
+ av_bprintf(&bp, " Outputs:\n");
count = avfilter_filter_pad_count(f, 1);
for (i = 0; i < count; i++) {
- printf(" #%d: %s (%s)\n", i, avfilter_pad_get_name(f->outputs, i),
+ av_bprintf(&bp, " #%d: %s (%s), Formats: ", i, avfilter_pad_get_name(f->outputs, i),
av_get_media_type_string(avfilter_pad_get_type(f->outputs, i)));
+
+ avfilter_print_config_formats(&bp, f, 1, i);
+ av_bprintf(&bp, "\n");
}
if (f->flags & AVFILTER_FLAG_DYNAMIC_OUTPUTS)
- printf(" dynamic (depending on the options)\n");
+ av_bprintf(&bp, " dynamic (depending on the options)\n");
else if (!count)
- printf(" none (sink filter)\n");
+ av_bprintf(&bp, " none (sink filter)\n");
+
+ av_log_set_callback(log_callback_help);
+ printf("%s\n", bp.str);
if (f->priv_class)
show_help_children(f->priv_class, AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_FILTERING_PARAM |
AV_OPT_FLAG_AUDIO_PARAM);
if (f->flags & AVFILTER_FLAG_SUPPORT_TIMELINE)
printf("This filter has support for timeline through the 'enable' option.\n");
+
+ av_bprint_finalize(&bp, NULL);
#else
av_log(NULL, AV_LOG_ERROR, "Build without libavfilter; "
"can not to satisfy request\n");
--
ffmpeg-codebot
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 10+ messages in thread
* [FFmpeg-devel] [PATCH v2 0/2] Print filter input/output formats in help output
2022-10-11 13:17 [FFmpeg-devel] [PATCH 0/2] Print filter input/output formats in help output ffmpegagent
2022-10-11 13:17 ` [FFmpeg-devel] [PATCH 1/2] avfilter/avfilter: add avfilter_print_config_formats() softworkz
2022-10-11 13:17 ` [FFmpeg-devel] [PATCH 2/2] ftools/opt_common: Print filter input/output formats in help output softworkz
@ 2022-10-11 21:38 ` ffmpegagent
2022-10-11 21:38 ` [FFmpeg-devel] [PATCH v2 1/2] avfilter/avfilter: add avfilter_print_config_formats() softworkz
2022-10-11 21:38 ` [FFmpeg-devel] [PATCH v2 2/2] ftools/opt_common: Print filter input/output formats in help output softworkz
2 siblings, 2 replies; 10+ messages in thread
From: ffmpegagent @ 2022-10-11 21:38 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: softworkz
Example output for command: ffmpeg -h filters=overlay
Filter overlay
Overlay a video source on top of the input.
slice threading supported
Inputs:
#0: main (video), Formats: Dynamic, Default: [yuv420p, yuvj420p, yuva420p, nv12, nv21]
#1: overlay (video), Formats: Dynamic, Default: [yuva420p]
Outputs:
#0: default (video), Formats: Dynamic, Default: [yuv420p, yuvj420p, yuva420p, nv12, nv21]
overlay AVOptions:
[...]
Examples for what it prints in various cases
============================================
For pass-through filter links
"All (passthrough)"
For filters using query_formats
"Dynamic"
For filters using query_formats where a call to query_formats succeeds
"Dynamic, Default: [yuv420p, yuvj420p, yuva420p, nv12, nv21]"
For all other cases
"[s16p, s32p, fltp, dblp]"
Except when all formats are supported (number of formats equals number of
available formats)
"All"
----------------------------------------------------------------------------
v2: rebase and fix compiler warnings
softworkz (2):
avfilter/avfilter: add avfilter_print_config_formats()
ftools/opt_common: Print filter input/output formats in help output
doc/APIchanges | 3 ++
fftools/opt_common.c | 37 +++++++++----
libavfilter/avfilter.c | 102 +++++++++++++++++++++++++++++++++++-
libavfilter/avfilter.h | 12 +++++
libavfilter/avfiltergraph.c | 15 ++++--
libavfilter/internal.h | 9 ++++
libavfilter/version.h | 4 +-
7 files changed, 163 insertions(+), 19 deletions(-)
base-commit: 479747645f795b6f4f376578ea1556409f943c31
Published-As: https://github.com/ffstaging/FFmpeg/releases/tag/pr-ffstaging-43%2Fsoftworkz%2Fsubmit_print_formats-v2
Fetch-It-Via: git fetch https://github.com/ffstaging/FFmpeg pr-ffstaging-43/softworkz/submit_print_formats-v2
Pull-Request: https://github.com/ffstaging/FFmpeg/pull/43
Range-diff vs v1:
1: c9496ca671 ! 1: 5ae347e40c avfilter/avfilter: add avfilter_print_config_formats()
@@ doc/APIchanges: libavutil: 2021-04-27
+2022-10-11 - xxxxxxxxxx - lavf 59.50.100 - avfilter.h
+ Add add avfilter_print_config_formats().
-+
- 2022-10-05 - 37d5ddc317 - lavu 57.39.100 - cpu.h
- Add AV_CPU_FLAG_RVB_BASIC.
++
+ 2022-10-11 - xxxxxxxxxx - lavu 57.39.101 - pixfmt.h
+ Add AV_PIX_FMT_RGBF32 and AV_PIX_FMT_RGBAF32.
## libavfilter/avfilter.c ##
@@ libavfilter/avfilter.c: void avfilter_link_free(AVFilterLink **link)
av_freep(link);
}
-+static unsigned get_nb_pix_fmts()
++static unsigned get_nb_pix_fmts(void)
+{
+ unsigned i = 0;
+ while (av_pix_fmt_desc_get(i++)) {}
+ return i - 1;
+}
+
-+static unsigned get_nb_sample_fmts()
++static unsigned get_nb_sample_fmts(void)
+{
+ unsigned i = 0;
+ while (av_get_sample_fmt_name(i++)) {}
@@ libavfilter/avfiltergraph.c: static int query_formats(AVFilterGraph *graph, void
- ret = filter_query_formats(f);
- else
- ret = ff_default_query_formats(f);
++
+ ret = ff_filter_query_formats(f);
if (ret < 0 && ret != AVERROR(EAGAIN))
return ret;
2: c99d278881 ! 2: 29389422a9 ftools/opt_common: Print filter input/output formats in help output
@@ fftools/opt_common.c: static void show_help_filter(const char *name)
{
#if CONFIG_AVFILTER
const AVFilter *f = avfilter_get_by_name(name);
-- int i, count;
+ AVBPrint bp;
-+ int i, count, ret;
+ int i, count;
if (!name) {
- av_log(NULL, AV_LOG_ERROR, "No filter name specified.\n");
@@ fftools/opt_common.c: static void show_help_filter(const char *name)
return;
}
--
ffmpeg-codebot
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 10+ messages in thread
* [FFmpeg-devel] [PATCH v2 1/2] avfilter/avfilter: add avfilter_print_config_formats()
2022-10-11 21:38 ` [FFmpeg-devel] [PATCH v2 0/2] " ffmpegagent
@ 2022-10-11 21:38 ` softworkz
2022-10-11 21:38 ` [FFmpeg-devel] [PATCH v2 2/2] ftools/opt_common: Print filter input/output formats in help output softworkz
1 sibling, 0 replies; 10+ messages in thread
From: softworkz @ 2022-10-11 21:38 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: softworkz
From: softworkz <softworkz@hotmail.com>
Prints the following to AVBPrint:
For pass-through filter links:
"All (passthrough)"
For filters using query_formats:
"Dynamic"
For filters using query_formats where a call to query_formats
succeeds (example):
"Dynamic, Defaults: [yuv420p, yuvj420p, yuva420p, nv12, nv21]"
For all other filters (example):
"[s16p, s32p, fltp, dblp]"
Except in case when the number of formats equals the number of
available formats:
"All"
Signed-off-by: softworkz <softworkz@hotmail.com>
---
doc/APIchanges | 3 ++
libavfilter/avfilter.c | 102 +++++++++++++++++++++++++++++++++++-
libavfilter/avfilter.h | 12 +++++
libavfilter/avfiltergraph.c | 15 ++++--
libavfilter/internal.h | 9 ++++
libavfilter/version.h | 4 +-
6 files changed, 137 insertions(+), 8 deletions(-)
diff --git a/doc/APIchanges b/doc/APIchanges
index 5807bf8069..82a029144d 100644
--- a/doc/APIchanges
+++ b/doc/APIchanges
@@ -14,6 +14,9 @@ libavutil: 2021-04-27
API changes, most recent first:
+2022-10-11 - xxxxxxxxxx - lavf 59.50.100 - avfilter.h
+ Add add avfilter_print_config_formats().
+
2022-10-11 - xxxxxxxxxx - lavu 57.39.101 - pixfmt.h
Add AV_PIX_FMT_RGBF32 and AV_PIX_FMT_RGBAF32.
diff --git a/libavfilter/avfilter.c b/libavfilter/avfilter.c
index cc5505e65b..8f2741c6ec 100644
--- a/libavfilter/avfilter.c
+++ b/libavfilter/avfilter.c
@@ -196,6 +196,104 @@ void avfilter_link_free(AVFilterLink **link)
av_freep(link);
}
+static unsigned get_nb_pix_fmts(void)
+{
+ unsigned i = 0;
+ while (av_pix_fmt_desc_get(i++)) {}
+ return i - 1;
+}
+
+static unsigned get_nb_sample_fmts(void)
+{
+ unsigned i = 0;
+ while (av_get_sample_fmt_name(i++)) {}
+ return i - 1;
+}
+
+int avfilter_print_config_formats(AVBPrint *bp, const struct AVFilter *filter, int for_output, unsigned pad_index)
+{
+ AVFilterGraph *graph;
+ AVFilterContext *filter_context;
+ AVFilterFormatsConfig *config;
+ enum AVMediaType media_type;
+ int ret = 0;
+
+ if (filter->formats_state == FF_FILTER_FORMATS_PASSTHROUGH) {
+ av_bprintf(bp, "All (passthrough)");
+ return 0;
+ }
+
+ graph = avfilter_graph_alloc();
+ if (!graph) {
+ av_log(NULL, AV_LOG_ERROR, "Failed to create filtergraph\n");
+ ret = AVERROR(ENOMEM);
+ goto cleanup;
+ }
+
+ filter_context = avfilter_graph_alloc_filter(graph, filter, "filter");
+ if (!filter_context) {
+ av_log(NULL, AV_LOG_ERROR, "Failed to create filter\n");
+ ret = AVERROR(ENOMEM);
+ goto cleanup;
+ }
+
+ avfilter_init_str(filter_context, NULL);
+
+ if (filter->formats_state == FF_FILTER_FORMATS_QUERY_FUNC)
+ av_bprintf(bp, "Dynamic");
+
+ if (!for_output && pad_index >= filter_context->nb_inputs
+ || for_output && pad_index >= filter_context->nb_outputs)
+ goto cleanup;
+
+ avfilter_graph_config(graph, graph);
+
+ for (unsigned i = 0; i < filter_context->nb_inputs; i++)
+ filter_context->inputs[i] = (AVFilterLink *)av_mallocz(sizeof(AVFilterLink));
+
+ for (unsigned i = 0; i < filter_context->nb_outputs; i++)
+ filter_context->outputs[i] = (AVFilterLink *)av_mallocz(sizeof(AVFilterLink));
+
+ ff_filter_query_formats(filter_context);
+
+ config = for_output ? &filter_context->outputs[pad_index]->incfg : &filter_context->inputs[pad_index]->outcfg;
+
+ if (!config || !config->formats)
+ goto cleanup;
+
+ media_type= for_output ? filter->outputs[pad_index].type : filter->inputs[pad_index].type;
+
+ if (filter->formats_state == FF_FILTER_FORMATS_QUERY_FUNC) {
+ if (config->formats && config->formats->nb_formats)
+ av_bprintf(bp, ", Default: ");
+ }
+
+ if (config->formats == NULL)
+ av_bprintf(bp, "unknown");
+ else if (media_type == AVMEDIA_TYPE_VIDEO && config->formats->nb_formats == get_nb_pix_fmts() ||
+ media_type == AVMEDIA_TYPE_AUDIO && config->formats->nb_formats == get_nb_sample_fmts())
+ av_bprintf(bp, "All");
+ else {
+ for (unsigned i = 0; i < config->formats->nb_formats; i++) {
+ if (i == 0)
+ av_bprintf(bp, "[");
+
+ if (media_type == AVMEDIA_TYPE_VIDEO)
+ av_bprintf(bp, "%s", av_get_pix_fmt_name(config->formats->formats[i]));
+ else if (media_type == AVMEDIA_TYPE_AUDIO)
+ av_bprintf(bp, "%s", av_get_sample_fmt_name(config->formats->formats[i]));
+
+ if (i < config->formats->nb_formats - 1)
+ av_bprintf(bp, ", ");
+ else
+ av_bprintf(bp, "]"); }
+ }
+
+cleanup:
+ avfilter_graph_free(&graph);
+ return ret;
+}
+
void ff_filter_set_ready(AVFilterContext *filter, unsigned priority)
{
filter->ready = FFMAX(filter->ready, priority);
@@ -759,12 +857,12 @@ void avfilter_free(AVFilterContext *filter)
for (i = 0; i < filter->nb_inputs; i++) {
free_link(filter->inputs[i]);
- if (filter->input_pads[i].flags & AVFILTERPAD_FLAG_FREE_NAME)
+ if (filter->input_pads && filter->input_pads[i].flags & AVFILTERPAD_FLAG_FREE_NAME)
av_freep(&filter->input_pads[i].name);
}
for (i = 0; i < filter->nb_outputs; i++) {
free_link(filter->outputs[i]);
- if (filter->output_pads[i].flags & AVFILTERPAD_FLAG_FREE_NAME)
+ if (filter->output_pads && filter->output_pads[i].flags & AVFILTERPAD_FLAG_FREE_NAME)
av_freep(&filter->output_pads[i].name);
}
diff --git a/libavfilter/avfilter.h b/libavfilter/avfilter.h
index 2e8197c9a6..705dabe53c 100644
--- a/libavfilter/avfilter.h
+++ b/libavfilter/avfilter.h
@@ -41,6 +41,7 @@
#include "libavutil/avutil.h"
#include "libavutil/buffer.h"
#include "libavutil/dict.h"
+#include "libavutil/bprint.h"
#include "libavutil/frame.h"
#include "libavutil/log.h"
#include "libavutil/samplefmt.h"
@@ -738,6 +739,17 @@ int avfilter_link(AVFilterContext *src, unsigned srcpad,
*/
void avfilter_link_free(AVFilterLink **link);
+/**
+ * Gets the formats from an AVFilterFormatsConfig.
+ *
+ * @param bp an instance of AVBPrint
+ * @param filter the AVFilter
+ * @param for_output set to 1 for filter outputs
+ * @param pad_index the index of the input or output
+ * @return zero on success
+ */
+int avfilter_print_config_formats(AVBPrint *bp, const AVFilter *filter, int for_output, unsigned pad_index);
+
/**
* Negotiate the media format, dimensions, etc of all inputs to a filter.
*
diff --git a/libavfilter/avfiltergraph.c b/libavfilter/avfiltergraph.c
index 53f468494d..a6d2f1c48b 100644
--- a/libavfilter/avfiltergraph.c
+++ b/libavfilter/avfiltergraph.c
@@ -416,10 +416,8 @@ static int query_formats(AVFilterGraph *graph, void *log_ctx)
AVFilterContext *f = graph->filters[i];
if (formats_declared(f))
continue;
- if (f->filter->formats_state == FF_FILTER_FORMATS_QUERY_FUNC)
- ret = filter_query_formats(f);
- else
- ret = ff_default_query_formats(f);
+
+ ret = ff_filter_query_formats(f);
if (ret < 0 && ret != AVERROR(EAGAIN))
return ret;
/* note: EAGAIN could indicate a partial success, not counted yet */
@@ -1351,3 +1349,12 @@ int ff_filter_graph_run_once(AVFilterGraph *graph)
return AVERROR(EAGAIN);
return ff_filter_activate(filter);
}
+
+int ff_filter_query_formats(AVFilterContext *filter)
+{
+ if (filter->filter->formats_state == FF_FILTER_FORMATS_QUERY_FUNC)
+ return filter_query_formats(filter);
+
+ return ff_default_query_formats(filter);
+}
+
diff --git a/libavfilter/internal.h b/libavfilter/internal.h
index aaf2c6c584..446d2a45f8 100644
--- a/libavfilter/internal.h
+++ b/libavfilter/internal.h
@@ -374,6 +374,15 @@ void ff_filter_graph_remove_filter(AVFilterGraph *graph, AVFilterContext *filter
*/
int ff_filter_graph_run_once(AVFilterGraph *graph);
+/**
+ * Query the formats of a filter.
+ *
+ * @param filter the filter context
+ *
+ * @return 0 on success
+ */
+int ff_filter_query_formats(AVFilterContext *filter);
+
/**
* Get number of threads for current filter instance.
* This number is always same or less than graph->nb_threads.
diff --git a/libavfilter/version.h b/libavfilter/version.h
index 4ccbf5641c..436c2b8b17 100644
--- a/libavfilter/version.h
+++ b/libavfilter/version.h
@@ -31,8 +31,8 @@
#include "version_major.h"
-#define LIBAVFILTER_VERSION_MINOR 49
-#define LIBAVFILTER_VERSION_MICRO 101
+#define LIBAVFILTER_VERSION_MINOR 50
+#define LIBAVFILTER_VERSION_MICRO 100
#define LIBAVFILTER_VERSION_INT AV_VERSION_INT(LIBAVFILTER_VERSION_MAJOR, \
--
ffmpeg-codebot
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 10+ messages in thread
* [FFmpeg-devel] [PATCH v2 2/2] ftools/opt_common: Print filter input/output formats in help output
2022-10-11 21:38 ` [FFmpeg-devel] [PATCH v2 0/2] " ffmpegagent
2022-10-11 21:38 ` [FFmpeg-devel] [PATCH v2 1/2] avfilter/avfilter: add avfilter_print_config_formats() softworkz
@ 2022-10-11 21:38 ` softworkz
1 sibling, 0 replies; 10+ messages in thread
From: softworkz @ 2022-10-11 21:38 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: softworkz
From: softworkz <softworkz@hotmail.com>
Exmaple command: ffmpeg -h filters=overlay
Output:
Filter overlay
Overlay a video source on top of the input.
slice threading supported
Inputs:
#0: main (video), Formats: Dynamic, Default: [yuv420p, yuvj420p,
yuva420p, nv12, nv21]
#1: overlay (video), Formats: Dynamic, Default: [yuva420p]
Outputs:
#0: default (video), Formats: Dynamic, Default: [yuv420p, yuvj420p,
yuva420p, nv12, nv21]
overlay AVOptions:
[...]
Signed-off-by: softworkz <softworkz@hotmail.com>
---
fftools/opt_common.c | 37 ++++++++++++++++++++++++++-----------
1 file changed, 26 insertions(+), 11 deletions(-)
diff --git a/fftools/opt_common.c b/fftools/opt_common.c
index 8a06df82df..774e3c776b 100644
--- a/fftools/opt_common.c
+++ b/fftools/opt_common.c
@@ -504,6 +504,7 @@ static void show_help_filter(const char *name)
{
#if CONFIG_AVFILTER
const AVFilter *f = avfilter_get_by_name(name);
+ AVBPrint bp;
int i, count;
if (!name) {
@@ -514,40 +515,54 @@ static void show_help_filter(const char *name)
return;
}
- printf("Filter %s\n", f->name);
+ av_bprint_init(&bp, 0, AV_BPRINT_SIZE_UNLIMITED);
+ av_log_set_callback(NULL);
+
+ av_bprintf(&bp, "Filter %s\n", f->name);
if (f->description)
- printf(" %s\n", f->description);
+ av_bprintf(&bp, " %s\n", f->description);
if (f->flags & AVFILTER_FLAG_SLICE_THREADS)
- printf(" slice threading supported\n");
+ av_bprintf(&bp, " slice threading supported\n");
- printf(" Inputs:\n");
+ av_bprintf(&bp, " Inputs:\n");
count = avfilter_filter_pad_count(f, 0);
for (i = 0; i < count; i++) {
- printf(" #%d: %s (%s)\n", i, avfilter_pad_get_name(f->inputs, i),
+ av_bprintf(&bp, " #%d: %s (%s), Formats: ", i, avfilter_pad_get_name(f->inputs, i),
av_get_media_type_string(avfilter_pad_get_type(f->inputs, i)));
+
+ avfilter_print_config_formats(&bp, f, 0, i);
+ av_bprintf(&bp, "\n");
}
if (f->flags & AVFILTER_FLAG_DYNAMIC_INPUTS)
- printf(" dynamic (depending on the options)\n");
+ av_bprintf(&bp, " dynamic (depending on the options)\n");
else if (!count)
- printf(" none (source filter)\n");
+ av_bprintf(&bp, " none (source filter)\n");
- printf(" Outputs:\n");
+ av_bprintf(&bp, " Outputs:\n");
count = avfilter_filter_pad_count(f, 1);
for (i = 0; i < count; i++) {
- printf(" #%d: %s (%s)\n", i, avfilter_pad_get_name(f->outputs, i),
+ av_bprintf(&bp, " #%d: %s (%s), Formats: ", i, avfilter_pad_get_name(f->outputs, i),
av_get_media_type_string(avfilter_pad_get_type(f->outputs, i)));
+
+ avfilter_print_config_formats(&bp, f, 1, i);
+ av_bprintf(&bp, "\n");
}
if (f->flags & AVFILTER_FLAG_DYNAMIC_OUTPUTS)
- printf(" dynamic (depending on the options)\n");
+ av_bprintf(&bp, " dynamic (depending on the options)\n");
else if (!count)
- printf(" none (sink filter)\n");
+ av_bprintf(&bp, " none (sink filter)\n");
+
+ av_log_set_callback(log_callback_help);
+ printf("%s\n", bp.str);
if (f->priv_class)
show_help_children(f->priv_class, AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_FILTERING_PARAM |
AV_OPT_FLAG_AUDIO_PARAM);
if (f->flags & AVFILTER_FLAG_SUPPORT_TIMELINE)
printf("This filter has support for timeline through the 'enable' option.\n");
+
+ av_bprint_finalize(&bp, NULL);
#else
av_log(NULL, AV_LOG_ERROR, "Build without libavfilter; "
"can not to satisfy request\n");
--
ffmpeg-codebot
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 10+ messages in thread