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
22 * @file libavfilter/vf_format.c
23 * video format and noformat filters
30 * List of flags telling if a given image format has been listed
31 * as argument to the filter.
33 int listed_pix_fmt_flags
[PIX_FMT_NB
];
36 #define PIX_FMT_NAME_MAXSIZE 32
38 static av_cold
int init(AVFilterContext
*ctx
, const char *args
, void *opaque
)
40 FormatContext
*format
= ctx
->priv
;
41 const char *cur
, *sep
;
42 char pix_fmt_name
[PIX_FMT_NAME_MAXSIZE
];
44 enum PixelFormat pix_fmt
;
46 /* parse the list of formats */
47 for (cur
= args
; cur
; cur
= sep
? sep
+1 : NULL
) {
48 if (!(sep
= strchr(cur
, ':')))
49 pix_fmt_name_len
= strlen(cur
);
51 pix_fmt_name_len
= sep
- cur
;
52 if (pix_fmt_name_len
>= PIX_FMT_NAME_MAXSIZE
) {
53 av_log(ctx
, AV_LOG_ERROR
, "Format name too long\n");
57 memcpy(pix_fmt_name
, cur
, pix_fmt_name_len
);
58 pix_fmt_name
[pix_fmt_name_len
] = 0;
59 pix_fmt
= avcodec_get_pix_fmt(pix_fmt_name
);
61 if (pix_fmt
== PIX_FMT_NONE
) {
62 av_log(ctx
, AV_LOG_ERROR
, "Unknown pixel format: %s\n", pix_fmt_name
);
66 format
->listed_pix_fmt_flags
[pix_fmt
] = 1;
72 static AVFilterFormats
*make_format_list(FormatContext
*format
, int flag
)
74 AVFilterFormats
*formats
;
75 enum PixelFormat pix_fmt
;
77 formats
= av_mallocz(sizeof(AVFilterFormats
));
78 formats
->formats
= av_malloc(sizeof(enum PixelFormat
) * PIX_FMT_NB
);
80 for (pix_fmt
= 0; pix_fmt
< PIX_FMT_NB
; pix_fmt
++)
81 if (format
->listed_pix_fmt_flags
[pix_fmt
] == flag
)
82 formats
->formats
[formats
->format_count
++] = pix_fmt
;
87 static int query_formats_format(AVFilterContext
*ctx
)
89 avfilter_set_common_formats(ctx
, make_format_list(ctx
->priv
, 1));
93 static int query_formats_noformat(AVFilterContext
*ctx
)
95 avfilter_set_common_formats(ctx
, make_format_list(ctx
->priv
, 0));
99 static void start_frame(AVFilterLink
*link
, AVFilterPicRef
*picref
)
101 avfilter_start_frame(link
->dst
->outputs
[0], picref
);
104 static void end_frame(AVFilterLink
*link
)
106 avfilter_end_frame(link
->dst
->outputs
[0]);
109 static void draw_slice(AVFilterLink
*link
, int y
, int h
)
111 avfilter_draw_slice(link
->dst
->outputs
[0], y
, h
);
114 AVFilter avfilter_vf_format
= {
116 .description
= "Convert the input video to one of the specified pixel formats.",
120 .query_formats
= query_formats_format
,
122 .priv_size
= sizeof(FormatContext
),
124 .inputs
= (AVFilterPad
[]) {{ .name
= "default",
125 .type
= CODEC_TYPE_VIDEO
,
126 .start_frame
= start_frame
,
127 .draw_slice
= draw_slice
,
128 .end_frame
= end_frame
, },
130 .outputs
= (AVFilterPad
[]) {{ .name
= "default",
131 .type
= CODEC_TYPE_VIDEO
},
135 AVFilter avfilter_vf_noformat
= {
137 .description
= "Force libavfilter not to use any of the specified pixel formats as the input to the next filter.",
141 .query_formats
= query_formats_noformat
,
143 .priv_size
= sizeof(FormatContext
),
145 .inputs
= (AVFilterPad
[]) {{ .name
= "default",
146 .type
= CODEC_TYPE_VIDEO
,
147 .start_frame
= start_frame
,
148 .draw_slice
= draw_slice
,
149 .end_frame
= end_frame
, },
151 .outputs
= (AVFilterPad
[]) {{ .name
= "default",
152 .type
= CODEC_TYPE_VIDEO
},