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[AV_PIX_FMT_NB];
00043 } FormatContext;
00044
00045 #define AV_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[AV_PIX_FMT_NAME_MAXSIZE];
00052 int pix_fmt_name_len, ret;
00053 enum AVPixelFormat 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 >= AV_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 AVPixelFormat pix_fmt;
00082
00083 formats = av_mallocz(sizeof(AVFilterFormats));
00084 formats->formats = av_malloc(sizeof(enum AVPixelFormat) * AV_PIX_FMT_NB);
00085
00086 for (pix_fmt = 0; pix_fmt < AV_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 static const AVFilterPad avfilter_vf_format_inputs[] = {
00101 {
00102 .name = "default",
00103 .type = AVMEDIA_TYPE_VIDEO,
00104 .get_video_buffer = ff_null_get_video_buffer,
00105 },
00106 { NULL }
00107 };
00108
00109 static const AVFilterPad avfilter_vf_format_outputs[] = {
00110 {
00111 .name = "default",
00112 .type = AVMEDIA_TYPE_VIDEO
00113 },
00114 { NULL }
00115 };
00116
00117 AVFilter avfilter_vf_format = {
00118 .name = "format",
00119 .description = NULL_IF_CONFIG_SMALL("Convert the input video to one of the specified pixel formats."),
00120
00121 .init = init,
00122
00123 .query_formats = query_formats_format,
00124
00125 .priv_size = sizeof(FormatContext),
00126
00127 .inputs = avfilter_vf_format_inputs,
00128 .outputs = avfilter_vf_format_outputs,
00129 };
00130 #endif
00131
00132 #if CONFIG_NOFORMAT_FILTER
00133 static int query_formats_noformat(AVFilterContext *ctx)
00134 {
00135 ff_set_common_formats(ctx, make_format_list(ctx->priv, 0));
00136 return 0;
00137 }
00138
00139 static const AVFilterPad avfilter_vf_noformat_inputs[] = {
00140 {
00141 .name = "default",
00142 .type = AVMEDIA_TYPE_VIDEO,
00143 .get_video_buffer = ff_null_get_video_buffer,
00144 },
00145 { NULL }
00146 };
00147
00148 static const AVFilterPad avfilter_vf_noformat_outputs[] = {
00149 {
00150 .name = "default",
00151 .type = AVMEDIA_TYPE_VIDEO
00152 },
00153 { NULL }
00154 };
00155
00156 AVFilter avfilter_vf_noformat = {
00157 .name = "noformat",
00158 .description = NULL_IF_CONFIG_SMALL("Force libavfilter not to use any of the specified pixel formats for the input to the next filter."),
00159
00160 .init = init,
00161
00162 .query_formats = query_formats_noformat,
00163
00164 .priv_size = sizeof(FormatContext),
00165
00166 .inputs = avfilter_vf_noformat_inputs,
00167 .outputs = avfilter_vf_noformat_outputs,
00168 };
00169 #endif