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