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
00029 typedef struct {
00034 int listed_pix_fmt_flags[PIX_FMT_NB];
00035 } FormatContext;
00036
00037 #define PIX_FMT_NAME_MAXSIZE 32
00038
00039 static av_cold int init(AVFilterContext *ctx, const char *args, void *opaque)
00040 {
00041 FormatContext *format = ctx->priv;
00042 const char *cur, *sep;
00043 char pix_fmt_name[PIX_FMT_NAME_MAXSIZE];
00044 int pix_fmt_name_len;
00045 enum PixelFormat pix_fmt;
00046
00047
00048 for (cur = args; cur; cur = sep ? sep+1 : NULL) {
00049 if (!(sep = strchr(cur, ':')))
00050 pix_fmt_name_len = strlen(cur);
00051 else
00052 pix_fmt_name_len = sep - cur;
00053 if (pix_fmt_name_len >= PIX_FMT_NAME_MAXSIZE) {
00054 av_log(ctx, AV_LOG_ERROR, "Format name too long\n");
00055 return -1;
00056 }
00057
00058 memcpy(pix_fmt_name, cur, pix_fmt_name_len);
00059 pix_fmt_name[pix_fmt_name_len] = 0;
00060 pix_fmt = av_get_pix_fmt(pix_fmt_name);
00061
00062 if (pix_fmt == PIX_FMT_NONE) {
00063 av_log(ctx, AV_LOG_ERROR, "Unknown pixel format: %s\n", pix_fmt_name);
00064 return -1;
00065 }
00066
00067 format->listed_pix_fmt_flags[pix_fmt] = 1;
00068 }
00069
00070 return 0;
00071 }
00072
00073 static AVFilterFormats *make_format_list(FormatContext *format, int flag)
00074 {
00075 AVFilterFormats *formats;
00076 enum PixelFormat pix_fmt;
00077
00078 formats = av_mallocz(sizeof(AVFilterFormats));
00079 formats->formats = av_malloc(sizeof(enum PixelFormat) * PIX_FMT_NB);
00080
00081 for (pix_fmt = 0; pix_fmt < PIX_FMT_NB; pix_fmt++)
00082 if (format->listed_pix_fmt_flags[pix_fmt] == flag)
00083 formats->formats[formats->format_count++] = pix_fmt;
00084
00085 return formats;
00086 }
00087
00088 #if CONFIG_FORMAT_FILTER
00089 static int query_formats_format(AVFilterContext *ctx)
00090 {
00091 avfilter_set_common_pixel_formats(ctx, make_format_list(ctx->priv, 1));
00092 return 0;
00093 }
00094
00095 AVFilter avfilter_vf_format = {
00096 .name = "format",
00097 .description = NULL_IF_CONFIG_SMALL("Convert the input video to one of the specified pixel formats."),
00098
00099 .init = init,
00100
00101 .query_formats = query_formats_format,
00102
00103 .priv_size = sizeof(FormatContext),
00104
00105 .inputs = (AVFilterPad[]) {{ .name = "default",
00106 .type = AVMEDIA_TYPE_VIDEO,
00107 .get_video_buffer= avfilter_null_get_video_buffer,
00108 .start_frame = avfilter_null_start_frame,
00109 .draw_slice = avfilter_null_draw_slice,
00110 .end_frame = avfilter_null_end_frame, },
00111 { .name = NULL}},
00112 .outputs = (AVFilterPad[]) {{ .name = "default",
00113 .type = AVMEDIA_TYPE_VIDEO },
00114 { .name = NULL}},
00115 };
00116 #endif
00117
00118 #if CONFIG_NOFORMAT_FILTER
00119 static int query_formats_noformat(AVFilterContext *ctx)
00120 {
00121 avfilter_set_common_pixel_formats(ctx, make_format_list(ctx->priv, 0));
00122 return 0;
00123 }
00124
00125 AVFilter avfilter_vf_noformat = {
00126 .name = "noformat",
00127 .description = NULL_IF_CONFIG_SMALL("Force libavfilter not to use any of the specified pixel formats for the input to the next filter."),
00128
00129 .init = init,
00130
00131 .query_formats = query_formats_noformat,
00132
00133 .priv_size = sizeof(FormatContext),
00134
00135 .inputs = (AVFilterPad[]) {{ .name = "default",
00136 .type = AVMEDIA_TYPE_VIDEO,
00137 .get_video_buffer= avfilter_null_get_video_buffer,
00138 .start_frame = avfilter_null_start_frame,
00139 .draw_slice = avfilter_null_draw_slice,
00140 .end_frame = avfilter_null_end_frame, },
00141 { .name = NULL}},
00142 .outputs = (AVFilterPad[]) {{ .name = "default",
00143 .type = AVMEDIA_TYPE_VIDEO },
00144 { .name = NULL}},
00145 };
00146 #endif
00147