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
28 #include "libavutil/internal.h"
29 #include "libavutil/mem.h"
30 #include "libavutil/pixdesc.h"
39 * List of flags telling if a given image format has been listed
40 * as argument to the filter.
42 int listed_pix_fmt_flags[AV_PIX_FMT_NB];
45 #define AV_PIX_FMT_NAME_MAXSIZE 32
47 static av_cold int init(AVFilterContext *ctx, const char *args)
49 FormatContext *format = ctx->priv;
50 const char *cur, *sep;
51 char pix_fmt_name[AV_PIX_FMT_NAME_MAXSIZE];
52 int pix_fmt_name_len, ret;
53 enum AVPixelFormat pix_fmt;
55 /* parse the list of formats */
56 for (cur = args; cur; cur = sep ? sep+1 : NULL) {
57 if (!(sep = strchr(cur, ':')))
58 pix_fmt_name_len = strlen(cur);
60 pix_fmt_name_len = sep - cur;
61 if (pix_fmt_name_len >= AV_PIX_FMT_NAME_MAXSIZE) {
62 av_log(ctx, AV_LOG_ERROR, "Format name too long\n");
66 memcpy(pix_fmt_name, cur, pix_fmt_name_len);
67 pix_fmt_name[pix_fmt_name_len] = 0;
69 if ((ret = ff_parse_pixel_format(&pix_fmt, pix_fmt_name, ctx)) < 0)
72 format->listed_pix_fmt_flags[pix_fmt] = 1;
78 static AVFilterFormats *make_format_list(FormatContext *format, int flag)
80 AVFilterFormats *formats;
81 enum AVPixelFormat pix_fmt;
83 formats = av_mallocz(sizeof(AVFilterFormats));
84 formats->formats = av_malloc(sizeof(enum AVPixelFormat) * AV_PIX_FMT_NB);
86 for (pix_fmt = 0; pix_fmt < AV_PIX_FMT_NB; pix_fmt++)
87 if (format->listed_pix_fmt_flags[pix_fmt] == flag)
88 formats->formats[formats->format_count++] = pix_fmt;
93 #if CONFIG_FORMAT_FILTER
94 static int query_formats_format(AVFilterContext *ctx)
96 ff_set_common_formats(ctx, make_format_list(ctx->priv, 1));
100 AVFilter avfilter_vf_format = {
102 .description = NULL_IF_CONFIG_SMALL("Convert the input video to one of the specified pixel formats."),
106 .query_formats = query_formats_format,
108 .priv_size = sizeof(FormatContext),
110 .inputs = (const AVFilterPad[]) {{ .name = "default",
111 .type = AVMEDIA_TYPE_VIDEO,
112 .get_video_buffer= ff_null_get_video_buffer,
113 .start_frame = ff_null_start_frame,
114 .draw_slice = ff_null_draw_slice,
115 .end_frame = ff_null_end_frame, },
117 .outputs = (const AVFilterPad[]) {{ .name = "default",
118 .type = AVMEDIA_TYPE_VIDEO },
121 #endif /* CONFIG_FORMAT_FILTER */
123 #if CONFIG_NOFORMAT_FILTER
124 static int query_formats_noformat(AVFilterContext *ctx)
126 ff_set_common_formats(ctx, make_format_list(ctx->priv, 0));
130 AVFilter avfilter_vf_noformat = {
132 .description = NULL_IF_CONFIG_SMALL("Force libavfilter not to use any of the specified pixel formats for the input to the next filter."),
136 .query_formats = query_formats_noformat,
138 .priv_size = sizeof(FormatContext),
140 .inputs = (const AVFilterPad[]) {{ .name = "default",
141 .type = AVMEDIA_TYPE_VIDEO,
142 .get_video_buffer= ff_null_get_video_buffer,
143 .start_frame = ff_null_start_frame,
144 .draw_slice = ff_null_draw_slice,
145 .end_frame = ff_null_end_frame, },
147 .outputs = (const AVFilterPad[]) {{ .name = "default",
148 .type = AVMEDIA_TYPE_VIDEO },
151 #endif /* CONFIG_NOFORMAT_FILTER */