libavfilter/vf_format.c
Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2007 Bobby Bingham
00003  *
00004  * This file is part of FFmpeg.
00005  *
00006  * FFmpeg is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU Lesser General Public
00008  * License as published by the Free Software Foundation; either
00009  * version 2.1 of the License, or (at your option) any later version.
00010  *
00011  * FFmpeg is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014  * Lesser General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU Lesser General Public
00017  * License along with FFmpeg; if not, write to the Free Software
00018  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
00019  */
00020 
00026 #include "libavutil/pixdesc.h"
00027 #include "avfilter.h"
00028 #include "internal.h"
00029 
00030 typedef struct {
00035     int listed_pix_fmt_flags[PIX_FMT_NB];
00036 } FormatContext;
00037 
00038 #define PIX_FMT_NAME_MAXSIZE 32
00039 
00040 static av_cold int init(AVFilterContext *ctx, const char *args, void *opaque)
00041 {
00042     FormatContext *format = ctx->priv;
00043     const char *cur, *sep;
00044     char             pix_fmt_name[PIX_FMT_NAME_MAXSIZE];
00045     int              pix_fmt_name_len, ret;
00046     enum PixelFormat pix_fmt;
00047 
00048     /* parse the list of formats */
00049     for (cur = args; cur; cur = sep ? sep+1 : NULL) {
00050         if (!(sep = strchr(cur, ':')))
00051             pix_fmt_name_len = strlen(cur);
00052         else
00053             pix_fmt_name_len = sep - cur;
00054         if (pix_fmt_name_len >= PIX_FMT_NAME_MAXSIZE) {
00055             av_log(ctx, AV_LOG_ERROR, "Format name too long\n");
00056             return -1;
00057         }
00058 
00059         memcpy(pix_fmt_name, cur, pix_fmt_name_len);
00060         pix_fmt_name[pix_fmt_name_len] = 0;
00061 
00062         if ((ret = ff_parse_pixel_format(&pix_fmt, pix_fmt_name, ctx)) < 0)
00063             return ret;
00064 
00065         format->listed_pix_fmt_flags[pix_fmt] = 1;
00066     }
00067 
00068     return 0;
00069 }
00070 
00071 static AVFilterFormats *make_format_list(FormatContext *format, int flag)
00072 {
00073     AVFilterFormats *formats;
00074     enum PixelFormat pix_fmt;
00075 
00076     formats = av_mallocz(sizeof(AVFilterFormats));
00077     formats->formats = av_malloc(sizeof(enum PixelFormat) * PIX_FMT_NB);
00078 
00079     for (pix_fmt = 0; pix_fmt < PIX_FMT_NB; pix_fmt++)
00080         if (format->listed_pix_fmt_flags[pix_fmt] == flag)
00081             formats->formats[formats->format_count++] = pix_fmt;
00082 
00083     return formats;
00084 }
00085 
00086 #if CONFIG_FORMAT_FILTER
00087 static int query_formats_format(AVFilterContext *ctx)
00088 {
00089     avfilter_set_common_pixel_formats(ctx, make_format_list(ctx->priv, 1));
00090     return 0;
00091 }
00092 
00093 AVFilter avfilter_vf_format = {
00094     .name      = "format",
00095     .description = NULL_IF_CONFIG_SMALL("Convert the input video to one of the specified pixel formats."),
00096 
00097     .init      = init,
00098 
00099     .query_formats = query_formats_format,
00100 
00101     .priv_size = sizeof(FormatContext),
00102 
00103     .inputs    = (const AVFilterPad[]) {{ .name      = "default",
00104                                     .type            = AVMEDIA_TYPE_VIDEO,
00105                                     .get_video_buffer= avfilter_null_get_video_buffer,
00106                                     .start_frame     = avfilter_null_start_frame,
00107                                     .draw_slice      = avfilter_null_draw_slice,
00108                                     .end_frame       = avfilter_null_end_frame, },
00109                                   { .name = NULL}},
00110     .outputs   = (const AVFilterPad[]) {{ .name      = "default",
00111                                     .type            = AVMEDIA_TYPE_VIDEO },
00112                                   { .name = NULL}},
00113 };
00114 #endif /* CONFIG_FORMAT_FILTER */
00115 
00116 #if CONFIG_NOFORMAT_FILTER
00117 static int query_formats_noformat(AVFilterContext *ctx)
00118 {
00119     avfilter_set_common_pixel_formats(ctx, make_format_list(ctx->priv, 0));
00120     return 0;
00121 }
00122 
00123 AVFilter avfilter_vf_noformat = {
00124     .name      = "noformat",
00125     .description = NULL_IF_CONFIG_SMALL("Force libavfilter not to use any of the specified pixel formats for the input to the next filter."),
00126 
00127     .init      = init,
00128 
00129     .query_formats = query_formats_noformat,
00130 
00131     .priv_size = sizeof(FormatContext),
00132 
00133     .inputs    = (const AVFilterPad[]) {{ .name      = "default",
00134                                     .type            = AVMEDIA_TYPE_VIDEO,
00135                                     .get_video_buffer= avfilter_null_get_video_buffer,
00136                                     .start_frame     = avfilter_null_start_frame,
00137                                     .draw_slice      = avfilter_null_draw_slice,
00138                                     .end_frame       = avfilter_null_end_frame, },
00139                                   { .name = NULL}},
00140     .outputs   = (const AVFilterPad[]) {{ .name      = "default",
00141                                     .type            = AVMEDIA_TYPE_VIDEO },
00142                                   { .name = NULL}},
00143 };
00144 #endif /* CONFIG_NOFORMAT_FILTER */
00145