FFmpeg
filtfmts.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2009 Stefano Sabatini
3  *
4  * This file is part of FFmpeg.
5  *
6  * FFmpeg is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * FFmpeg is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with FFmpeg; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19  */
20 
21 #include <stdio.h>
22 
24 #include "libavutil/mem.h"
25 #include "libavutil/pixdesc.h"
26 #include "libavutil/samplefmt.h"
27 
28 #include "libavfilter/avfilter.h"
30 #include "libavfilter/formats.h"
31 #include "libavfilter/framequeue.h"
32 
34  unsigned nb, size_t fmts_cfg_offset,
35  const char *inout_string)
36 {
37  for (unsigned i = 0; i < nb; i++) {
38  const AVFilterLink *const link = links[i];
39  const AVFilterFormatsConfig *const cfg = (AVFilterFormatsConfig*)((const char*)link + fmts_cfg_offset);
40  const char *pad_name = avfilter_pad_get_name(pads, i);
41 
42  if (link->type == AVMEDIA_TYPE_VIDEO) {
43  const AVFilterFormats *const fmts = cfg->formats;
44  for (unsigned j = 0; fmts && j < fmts->nb_formats; j++) {
45  printf("%s[%u] %s: fmt:%s\n",
46  inout_string, i, pad_name,
47  av_get_pix_fmt_name(fmts->formats[j]));
48  }
49  } else if (link->type == AVMEDIA_TYPE_AUDIO) {
50  const AVFilterFormats *const fmts = cfg->formats;
52 
53  for (unsigned j = 0; fmts && j < fmts->nb_formats; j++)
54  printf("%s[%u] %s: fmt:%s\n",
55  inout_string, i, pad_name,
57 
58  for (unsigned j = 0; layouts && j < layouts->nb_channel_layouts; j++) {
59  char buf[256];
60  av_channel_layout_describe(&layouts->channel_layouts[j], buf, sizeof(buf));
61  printf("%s[%u] %s: chlayout:%s\n",
62  inout_string, i, pad_name, buf);
63  }
64  }
65  }
66 }
67 
69 {
70  print_formats_internal(filter_ctx->inputs, filter_ctx->input_pads,
71  filter_ctx->nb_inputs,
72  offsetof(AVFilterLink, outcfg), "INPUT");
73  print_formats_internal(filter_ctx->outputs, filter_ctx->output_pads,
74  filter_ctx->nb_outputs,
75  offsetof(AVFilterLink, incfg), "OUTPUT");
76 }
77 
78 int main(int argc, char **argv)
79 {
80  const AVFilter *filter;
81  const FFFilter *fi;
83  AVFilterGraph *graph_ctx;
84  const char *filter_name;
85  const char *filter_args = NULL;
86  int i;
87  int ret = 0;
88 
90 
91  if (argc < 2) {
92  fprintf(stderr, "Missing filter name as argument\n");
93  return 1;
94  }
95 
96  filter_name = argv[1];
97  if (argc > 2)
98  filter_args = argv[2];
99 
100  /* allocate graph */
101  graph_ctx = avfilter_graph_alloc();
102  if (!graph_ctx)
103  return 1;
104 
105  /* get a corresponding filter and open it */
106  if (!(filter = avfilter_get_by_name(filter_name))) {
107  fprintf(stderr, "Unrecognized filter with name '%s'\n", filter_name);
108  return 1;
109  }
110  fi = fffilter(filter);
111 
112  /* open filter and add it to the graph */
113  if (!(filter_ctx = avfilter_graph_alloc_filter(graph_ctx, filter, filter_name))) {
114  fprintf(stderr, "Impossible to open filter with name '%s'\n",
115  filter_name);
116  return 1;
117  }
118  if (avfilter_init_str(filter_ctx, filter_args) < 0) {
119  fprintf(stderr, "Impossible to init filter '%s' with arguments '%s'\n",
120  filter_name, filter_args);
121  return 1;
122  }
123 
124  /* create a link for each of the input pads */
125  for (i = 0; i < filter_ctx->nb_inputs; i++) {
127  if (!link) {
128  fprintf(stderr, "Unable to allocate memory for filter input link\n");
129  ret = 1;
130  goto fail;
131  }
132  link->type = avfilter_pad_get_type(filter_ctx->input_pads, i);
133  filter_ctx->inputs[i] = link;
134  }
135  for (i = 0; i < filter_ctx->nb_outputs; i++) {
137  if (!link) {
138  fprintf(stderr, "Unable to allocate memory for filter output link\n");
139  ret = 1;
140  goto fail;
141  }
142  link->type = avfilter_pad_get_type(filter_ctx->output_pads, i);
143  filter_ctx->outputs[i] = link;
144  }
145 
149  AVFilterFormatsConfig **cfg_in = NULL, **cfg_out = NULL;
150 
151  if (filter_ctx->nb_inputs) {
152  cfg_in = av_malloc_array(filter_ctx->nb_inputs, sizeof(*cfg_in));
153  for (unsigned i = 0; i < filter_ctx->nb_inputs; i++)
154  cfg_in[i] = &filter_ctx->inputs[i]->outcfg;
155  }
156  if (filter_ctx->nb_outputs) {
157  cfg_out = av_malloc_array(filter_ctx->nb_outputs, sizeof(*cfg_out));
158  for (unsigned i = 0; i < filter_ctx->nb_outputs; i++)
159  cfg_out[i] = &filter_ctx->outputs[i]->incfg;
160  }
161 
162  ret = fi->formats.query_func2(filter_ctx, cfg_in, cfg_out);
163  av_freep(&cfg_in);
164  av_freep(&cfg_out);
165  } else
167 
169 
170 fail:
172  avfilter_graph_free(&graph_ctx);
173  fflush(stdout);
174  return ret;
175 }
AVFilterChannelLayouts
A list of supported channel layouts.
Definition: formats.h:85
FF_FILTER_FORMATS_QUERY_FUNC
@ FF_FILTER_FORMATS_QUERY_FUNC
formats.query active.
Definition: filters.h:228
avfilter_pad_get_name
const char * avfilter_pad_get_name(const AVFilterPad *pads, int pad_idx)
Get the name of an AVFilterPad.
Definition: avfilter.c:983
AVFilterFormatsConfig::channel_layouts
AVFilterChannelLayouts * channel_layouts
Lists of supported channel layouts, only for audio.
Definition: avfilter.h:124
layouts
enum MovChannelLayoutTag * layouts
Definition: mov_chan.c:335
pixdesc.h
FFFilter::query_func2
int(* query_func2)(const AVFilterContext *, struct AVFilterFormatsConfig **cfg_in, struct AVFilterFormatsConfig **cfg_out)
Same as query_func(), except this function writes the results into provided arrays.
Definition: filters.h:390
filter
void(* filter)(uint8_t *src, int stride, int qscale)
Definition: h263dsp.c:29
AVFilterFormats::formats
int * formats
list of media formats
Definition: formats.h:66
fffilter
static const FFFilter * fffilter(const AVFilter *f)
Definition: filters.h:462
avfilter_graph_free
void avfilter_graph_free(AVFilterGraph **graph)
Free a graph, destroy its links, and set *graph to NULL.
Definition: avfiltergraph.c:117
FilterLinkInternal
Definition: avfilter_internal.h:34
AVFilterFormats
A list of supported formats for one end of a filter link.
Definition: formats.h:64
formats.h
FFFilter::formats_state
uint8_t formats_state
This field determines the state of the formats union.
Definition: filters.h:285
avfilter_graph_alloc_filter
AVFilterContext * avfilter_graph_alloc_filter(AVFilterGraph *graph, const AVFilter *filter, const char *name)
Create a new filter instance in a filter graph.
Definition: avfiltergraph.c:165
fail
#define fail()
Definition: checkasm.h:193
avfilter_graph_alloc
AVFilterGraph * avfilter_graph_alloc(void)
Allocate a filter graph.
Definition: avfiltergraph.c:83
samplefmt.h
filter_ctx
static FilteringContext * filter_ctx
Definition: transcode.c:52
AVFilterPad
A filter pad used for either input or output.
Definition: filters.h:38
FFFilter
Definition: filters.h:265
av_channel_layout_describe
int av_channel_layout_describe(const AVChannelLayout *channel_layout, char *buf, size_t buf_size)
Get a human-readable string describing the channel layout properties.
Definition: channel_layout.c:653
AVMEDIA_TYPE_AUDIO
@ AVMEDIA_TYPE_AUDIO
Definition: avutil.h:202
AV_LOG_DEBUG
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition: log.h:230
print_formats
static void print_formats(AVFilterContext *filter_ctx)
Definition: filtfmts.c:68
av_get_sample_fmt_name
const char * av_get_sample_fmt_name(enum AVSampleFormat sample_fmt)
Return the name of sample_fmt, or NULL if sample_fmt is not recognized.
Definition: samplefmt.c:51
link
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a link
Definition: filter_design.txt:23
avfilter_get_by_name
const AVFilter * avfilter_get_by_name(const char *name)
Get a filter definition matching the given name.
Definition: allfilters.c:637
FFFilter::formats
union FFFilter::@322 formats
The state of the following union is determined by formats_state.
NULL
#define NULL
Definition: coverity.c:32
print_formats_internal
static void print_formats_internal(AVFilterLink **links, const AVFilterPad *pads, unsigned nb, size_t fmts_cfg_offset, const char *inout_string)
Definition: filtfmts.c:33
framequeue.h
AVFilterFormats::nb_formats
unsigned nb_formats
number of formats
Definition: formats.h:65
avfilter_internal.h
AVFilterGraph
Definition: avfilter.h:581
AVFilterFormatsConfig
Lists of formats / etc.
Definition: avfilter.h:109
ff_default_query_formats
int ff_default_query_formats(AVFilterContext *ctx)
Sets all remaining unset filter lists for all inputs/outputs to their corresponding ff_all_*() lists.
Definition: formats.c:1025
printf
printf("static const uint8_t my_array[100] = {\n")
avfilter_init_str
int avfilter_init_str(AVFilterContext *filter, const char *args)
Initialize a filter with the supplied parameters.
Definition: avfilter.c:955
av_log_set_level
void av_log_set_level(int level)
Set the log level.
Definition: log.c:447
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:256
av_malloc_array
#define av_malloc_array(a, b)
Definition: tableprint_vlc.h:31
av_mallocz
void * av_mallocz(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
Definition: mem.c:256
main
int main(int argc, char **argv)
Definition: filtfmts.c:78
FFFilter::query_func
int(* query_func)(AVFilterContext *)
Query formats supported by the filter on its inputs and outputs.
Definition: filters.h:377
AVFilter
Filter definition.
Definition: avfilter.h:199
ret
ret
Definition: filter_design.txt:187
links
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output links
Definition: filter_design.txt:14
FF_FILTER_FORMATS_QUERY_FUNC2
@ FF_FILTER_FORMATS_QUERY_FUNC2
formats.query_func2 active.
Definition: filters.h:229
avfilter_pad_get_type
enum AVMediaType avfilter_pad_get_type(const AVFilterPad *pads, int pad_idx)
Get the type of an AVFilterPad.
Definition: avfilter.c:988
channel_layout.h
avfilter.h
AVFilterContext
An instance of a filter.
Definition: avfilter.h:257
AVMEDIA_TYPE_VIDEO
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:201
mem.h
AVFilterFormatsConfig::formats
AVFilterFormats * formats
List of supported formats (pixel or sample).
Definition: avfilter.h:114
avfilter_free
void avfilter_free(AVFilterContext *filter)
Free a filter context.
Definition: avfilter.c:795
av_freep
#define av_freep(p)
Definition: tableprint_vlc.h:34
av_get_pix_fmt_name
const char * av_get_pix_fmt_name(enum AVPixelFormat pix_fmt)
Return the short name for a pixel format, NULL in case pix_fmt is unknown.
Definition: pixdesc.c:3164