00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00026 #include "libavutil/pixdesc.h"
00027 #include "avfilter.h"
00028 #include "internal.h"
00029 #include "video.h"
00030
00031 typedef struct {
00036 int listed_pix_fmt_flags[PIX_FMT_NB];
00037 } FormatContext;
00038
00039 #define PIX_FMT_NAME_MAXSIZE 32
00040
00041 static av_cold int init(AVFilterContext *ctx, const char *args, void *opaque)
00042 {
00043 FormatContext *format = ctx->priv;
00044 const char *cur, *sep;
00045 char pix_fmt_name[PIX_FMT_NAME_MAXSIZE];
00046 int pix_fmt_name_len, ret;
00047 enum PixelFormat pix_fmt;
00048
00049
00050 for (cur = args; cur; cur = sep ? sep+1 : NULL) {
00051 if (!(sep = strchr(cur, ':')))
00052 pix_fmt_name_len = strlen(cur);
00053 else
00054 pix_fmt_name_len = sep - cur;
00055 if (pix_fmt_name_len >= PIX_FMT_NAME_MAXSIZE) {
00056 av_log(ctx, AV_LOG_ERROR, "Format name too long\n");
00057 return -1;
00058 }
00059
00060 memcpy(pix_fmt_name, cur, pix_fmt_name_len);
00061 pix_fmt_name[pix_fmt_name_len] = 0;
00062
00063 if ((ret = ff_parse_pixel_format(&pix_fmt, pix_fmt_name, ctx)) < 0)
00064 return ret;
00065
00066 format->listed_pix_fmt_flags[pix_fmt] = 1;
00067 }
00068
00069 return 0;
00070 }
00071
00072 static AVFilterFormats *make_format_list(FormatContext *format, int flag)
00073 {
00074 AVFilterFormats *formats;
00075 enum PixelFormat pix_fmt;
00076
00077 formats = av_mallocz(sizeof(AVFilterFormats));
00078 formats->formats = av_malloc(sizeof(enum PixelFormat) * PIX_FMT_NB);
00079
00080 for (pix_fmt = 0; pix_fmt < PIX_FMT_NB; pix_fmt++)
00081 if (format->listed_pix_fmt_flags[pix_fmt] == flag)
00082 formats->formats[formats->format_count++] = pix_fmt;
00083
00084 return formats;
00085 }
00086
00087 #if CONFIG_FORMAT_FILTER
00088 static int query_formats_format(AVFilterContext *ctx)
00089 {
00090 avfilter_set_common_pixel_formats(ctx, make_format_list(ctx->priv, 1));
00091 return 0;
00092 }
00093
00094 AVFilter avfilter_vf_format = {
00095 .name = "format",
00096 .description = NULL_IF_CONFIG_SMALL("Convert the input video to one of the specified pixel formats."),
00097
00098 .init = init,
00099
00100 .query_formats = query_formats_format,
00101
00102 .priv_size = sizeof(FormatContext),
00103
00104 .inputs = (const AVFilterPad[]) {{ .name = "default",
00105 .type = AVMEDIA_TYPE_VIDEO,
00106 .get_video_buffer= ff_null_get_video_buffer,
00107 .start_frame = ff_null_start_frame,
00108 .draw_slice = ff_null_draw_slice,
00109 .end_frame = ff_null_end_frame, },
00110 { .name = NULL}},
00111 .outputs = (const AVFilterPad[]) {{ .name = "default",
00112 .type = AVMEDIA_TYPE_VIDEO },
00113 { .name = NULL}},
00114 };
00115 #endif
00116
00117 #if CONFIG_NOFORMAT_FILTER
00118 static int query_formats_noformat(AVFilterContext *ctx)
00119 {
00120 avfilter_set_common_pixel_formats(ctx, make_format_list(ctx->priv, 0));
00121 return 0;
00122 }
00123
00124 AVFilter avfilter_vf_noformat = {
00125 .name = "noformat",
00126 .description = NULL_IF_CONFIG_SMALL("Force libavfilter not to use any of the specified pixel formats for the input to the next filter."),
00127
00128 .init = init,
00129
00130 .query_formats = query_formats_noformat,
00131
00132 .priv_size = sizeof(FormatContext),
00133
00134 .inputs = (const AVFilterPad[]) {{ .name = "default",
00135 .type = AVMEDIA_TYPE_VIDEO,
00136 .get_video_buffer= ff_null_get_video_buffer,
00137 .start_frame = ff_null_start_frame,
00138 .draw_slice = ff_null_draw_slice,
00139 .end_frame = ff_null_end_frame, },
00140 { .name = NULL}},
00141 .outputs = (const AVFilterPad[]) {{ .name = "default",
00142 .type = AVMEDIA_TYPE_VIDEO },
00143 { .name = NULL}},
00144 };
00145 #endif