2 * copyright (c) 2007 Bobby Bingham
4 * This file is part of FFmpeg.
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.
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.
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
23 * format and noformat video filters
26 #include "libavutil/pixdesc.h"
31 * List of flags telling if a given image format has been listed
32 * as argument to the filter.
34 int listed_pix_fmt_flags
[PIX_FMT_NB
];
37 #define PIX_FMT_NAME_MAXSIZE 32
39 static av_cold
int init(AVFilterContext
*ctx
, const char *args
, void *opaque
)
41 FormatContext
*format
= ctx
->priv
;
42 const char *cur
, *sep
;
43 char pix_fmt_name
[PIX_FMT_NAME_MAXSIZE
];
45 enum PixelFormat pix_fmt
;
47 /* parse the list of formats */
48 for (cur
= args
; cur
; cur
= sep ? sep
+1 : NULL
) {
49 if (!(sep
= strchr(cur
, ':')))
50 pix_fmt_name_len
= strlen(cur
);
52 pix_fmt_name_len
= sep
- cur
;
53 if (pix_fmt_name_len
>= PIX_FMT_NAME_MAXSIZE
) {
54 av_log(ctx
, AV_LOG_ERROR
, "Format name too long\n");
58 memcpy(pix_fmt_name
, cur
, pix_fmt_name_len
);
59 pix_fmt_name
[pix_fmt_name_len
] = 0;
60 pix_fmt
= av_get_pix_fmt(pix_fmt_name
);
62 if (pix_fmt
== PIX_FMT_NONE
) {
63 av_log(ctx
, AV_LOG_ERROR
, "Unknown pixel format: %s\n", pix_fmt_name
);
67 format
->listed_pix_fmt_flags
[pix_fmt
] = 1;
73 static AVFilterFormats
*make_format_list(FormatContext
*format
, int flag
)
75 AVFilterFormats
*formats
;
76 enum PixelFormat pix_fmt
;
78 formats
= av_mallocz(sizeof(AVFilterFormats
));
79 formats
->formats
= av_malloc(sizeof(enum PixelFormat
) * PIX_FMT_NB
);
81 for (pix_fmt
= 0; pix_fmt
< PIX_FMT_NB
; pix_fmt
++)
82 if (format
->listed_pix_fmt_flags
[pix_fmt
] == flag
)
83 formats
->formats
[formats
->format_count
++] = pix_fmt
;
88 #if CONFIG_FORMAT_FILTER
89 static int query_formats_format(AVFilterContext
*ctx
)
91 avfilter_set_common_formats(ctx
, make_format_list(ctx
->priv
, 1));
95 AVFilter avfilter_vf_format
= {
97 .description
= "Convert the input video to one of the specified pixel formats.",
101 .query_formats
= query_formats_format
,
103 .priv_size
= sizeof(FormatContext
),
105 .inputs
= (AVFilterPad
[]) {{ .name
= "default",
106 .type
= AVMEDIA_TYPE_VIDEO
,
107 .get_video_buffer
= avfilter_null_get_video_buffer
,
108 .start_frame
= avfilter_null_start_frame
,
109 .draw_slice
= avfilter_null_draw_slice
,
110 .end_frame
= avfilter_null_end_frame
, },
112 .outputs
= (AVFilterPad
[]) {{ .name
= "default",
113 .type
= AVMEDIA_TYPE_VIDEO
},
116 #endif /* CONFIG_FORMAT_FILTER */
118 #if CONFIG_NOFORMAT_FILTER
119 static int query_formats_noformat(AVFilterContext
*ctx
)
121 avfilter_set_common_formats(ctx
, make_format_list(ctx
->priv
, 0));
125 AVFilter avfilter_vf_noformat
= {
127 .description
= "Force libavfilter not to use any of the specified pixel formats for the input to the next filter.",
131 .query_formats
= query_formats_noformat
,
133 .priv_size
= sizeof(FormatContext
),
135 .inputs
= (AVFilterPad
[]) {{ .name
= "default",
136 .type
= AVMEDIA_TYPE_VIDEO
,
137 .get_video_buffer
= avfilter_null_get_video_buffer
,
138 .start_frame
= avfilter_null_start_frame
,
139 .draw_slice
= avfilter_null_draw_slice
,
140 .end_frame
= avfilter_null_end_frame
, },
142 .outputs
= (AVFilterPad
[]) {{ .name
= "default",
143 .type
= AVMEDIA_TYPE_VIDEO
},
146 #endif /* CONFIG_NOFORMAT_FILTER */