FFmpeg  2.1.1
vf_format.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2007 Bobby Bingham
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 /**
22  * @file
23  * format and noformat video filters
24  */
25 
26 #include <string.h>
27 
28 #include "libavutil/internal.h"
29 #include "libavutil/mem.h"
30 #include "libavutil/pixdesc.h"
31 #include "libavutil/opt.h"
32 
33 #include "avfilter.h"
34 #include "formats.h"
35 #include "internal.h"
36 #include "video.h"
37 
38 typedef struct {
39  const AVClass *class;
40  char *pix_fmts;
41  /**
42  * List of flags telling if a given image format has been listed
43  * as argument to the filter.
44  */
45  int listed_pix_fmt_flags[AV_PIX_FMT_NB];
47 
48 #define AV_PIX_FMT_NAME_MAXSIZE 32
49 
50 static av_cold int init(AVFilterContext *ctx)
51 {
52  FormatContext *s = ctx->priv;
53  const char *cur, *sep;
54  char pix_fmt_name[AV_PIX_FMT_NAME_MAXSIZE];
55  int pix_fmt_name_len, ret;
57 
58  /* parse the list of formats */
59  for (cur = s->pix_fmts; cur; cur = sep ? sep + 1 : NULL) {
60  if (!(sep = strchr(cur, '|')))
61  pix_fmt_name_len = strlen(cur);
62  else
63  pix_fmt_name_len = sep - cur;
64  if (pix_fmt_name_len >= AV_PIX_FMT_NAME_MAXSIZE) {
65  av_log(ctx, AV_LOG_ERROR, "Format name too long\n");
66  return -1;
67  }
68 
69  memcpy(pix_fmt_name, cur, pix_fmt_name_len);
70  pix_fmt_name[pix_fmt_name_len] = 0;
71 
72  if ((ret = ff_parse_pixel_format(&pix_fmt, pix_fmt_name, ctx)) < 0)
73  return ret;
74 
76  }
77 
78  return 0;
79 }
80 
82 {
83  AVFilterFormats *formats = NULL;
85 
86  for (pix_fmt = 0; pix_fmt < AV_PIX_FMT_NB; pix_fmt++)
87  if (s->listed_pix_fmt_flags[pix_fmt] == flag) {
88  int ret = ff_add_format(&formats, pix_fmt);
89  if (ret < 0) {
90  ff_formats_unref(&formats);
91  return NULL;
92  }
93  }
94 
95  return formats;
96 }
97 
98 #define OFFSET(x) offsetof(FormatContext, x)
99 static const AVOption options[] = {
100  { "pix_fmts", "A '|'-separated list of pixel formats", OFFSET(pix_fmts), AV_OPT_TYPE_STRING, .flags = AV_OPT_FLAG_VIDEO_PARAM },
101  { NULL }
102 };
103 
104 #if CONFIG_FORMAT_FILTER
105 static int query_formats_format(AVFilterContext *ctx)
106 {
108  return 0;
109 }
110 
111 #define format_options options
112 AVFILTER_DEFINE_CLASS(format);
113 
114 static const AVFilterPad avfilter_vf_format_inputs[] = {
115  {
116  .name = "default",
117  .type = AVMEDIA_TYPE_VIDEO,
118  .get_video_buffer = ff_null_get_video_buffer,
119  },
120  { NULL }
121 };
122 
123 static const AVFilterPad avfilter_vf_format_outputs[] = {
124  {
125  .name = "default",
126  .type = AVMEDIA_TYPE_VIDEO
127  },
128  { NULL }
129 };
130 
131 AVFilter avfilter_vf_format = {
132  .name = "format",
133  .description = NULL_IF_CONFIG_SMALL("Convert the input video to one of the specified pixel formats."),
134  .init = init,
135  .query_formats = query_formats_format,
136  .priv_size = sizeof(FormatContext),
137  .priv_class = &format_class,
138  .inputs = avfilter_vf_format_inputs,
139  .outputs = avfilter_vf_format_outputs,
140 };
141 #endif /* CONFIG_FORMAT_FILTER */
142 
143 #if CONFIG_NOFORMAT_FILTER
144 static int query_formats_noformat(AVFilterContext *ctx)
145 {
147  return 0;
148 }
149 
150 #define noformat_options options
151 AVFILTER_DEFINE_CLASS(noformat);
152 
153 static const AVFilterPad avfilter_vf_noformat_inputs[] = {
154  {
155  .name = "default",
156  .type = AVMEDIA_TYPE_VIDEO,
157  .get_video_buffer = ff_null_get_video_buffer,
158  },
159  { NULL }
160 };
161 
162 static const AVFilterPad avfilter_vf_noformat_outputs[] = {
163  {
164  .name = "default",
165  .type = AVMEDIA_TYPE_VIDEO
166  },
167  { NULL }
168 };
169 
170 AVFilter avfilter_vf_noformat = {
171  .name = "noformat",
172  .description = NULL_IF_CONFIG_SMALL("Force libavfilter not to use any of the specified pixel formats for the input to the next filter."),
173  .init = init,
174  .query_formats = query_formats_noformat,
175  .priv_size = sizeof(FormatContext),
176  .priv_class = &noformat_class,
177  .inputs = avfilter_vf_noformat_inputs,
178  .outputs = avfilter_vf_noformat_outputs,
179 };
180 #endif /* CONFIG_NOFORMAT_FILTER */
const char * s
Definition: avisynth_c.h:668
int listed_pix_fmt_flags[AV_PIX_FMT_NB]
List of flags telling if a given image format has been listed as argument to the filter.
Definition: vf_format.c:45
AVOption.
Definition: opt.h:253
const char * name
Filter name.
Definition: avfilter.h:468
int ff_parse_pixel_format(enum AVPixelFormat *ret, const char *arg, void *log_ctx)
Parse a pixel format.
Definition: formats.c:565
void * priv
private data for use by the filter
Definition: avfilter.h:648
static const AVFilterPad outputs[]
Definition: af_ashowinfo.c:111
void av_log(void *avcl, int level, const char *fmt,...) av_printf_format(3
Send the specified message to the log if the level is less than or equal to the current av_log_level...
AVFrame * ff_null_get_video_buffer(AVFilterLink *link, int w, int h)
Definition: video.c:35
#define OFFSET(x)
Definition: vf_format.c:98
static enum AVSampleFormat formats[]
#define av_cold
Definition: avcodec.h:653
const char * name
Pad name.
Definition: internal.h:66
#define AV_OPT_FLAG_VIDEO_PARAM
Definition: opt.h:287
enum AVPixelFormat pix_fmt
Definition: v4l.c:62
void ff_set_common_formats(AVFilterContext *ctx, AVFilterFormats *formats)
A helper for query_formats() which sets all links to the same list of formats.
Definition: formats.c:531
const OptionDef options[]
Definition: ffserver.c:4682
A filter pad used for either input or output.
Definition: internal.h:60
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: avcodec.h:4147
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Definition: internal.h:151
int ff_add_format(AVFilterFormats **avff, int64_t fmt)
Add fmt to the list of media formats contained in *avff.
Definition: formats.c:330
AVPixelFormat
Pixel format.
Definition: pixfmt.h:66
char * pix_fmts
Definition: vf_format.c:40
common internal API header
static av_cold int init(AVFilterContext *ctx)
Definition: vf_format.c:50
ret
Definition: avfilter.c:961
Main libavfilter public API header.
#define AV_PIX_FMT_NAME_MAXSIZE
Definition: vf_format.c:48
Describe the class of an AVClass context structure.
Definition: log.h:50
Filter definition.
Definition: avfilter.h:464
static const AVFilterPad inputs[]
Definition: af_ashowinfo.c:102
void ff_formats_unref(AVFilterFormats **ref)
If *ref is non-NULL, remove *ref as a reference to the format list it currently points to...
Definition: formats.c:454
number of pixel formats, DO NOT USE THIS if you want to link with shared libav* because the number of...
Definition: avcodec.h:4730
#define AVFILTER_DEFINE_CLASS(fname)
Definition: internal.h:301
A list of supported formats for one end of a filter link.
Definition: formats.h:64
An instance of a filter.
Definition: avfilter.h:627
static AVFilterFormats * make_format_list(FormatContext *s, int flag)
Definition: vf_format.c:81
internal API functions