• Main Page
  • Related Pages
  • Modules
  • Data Structures
  • Files
  • File List
  • Globals

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 
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     /* parse the list of formats */
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_formats(ctx, make_format_list(ctx->priv, 1));
00092     return 0;
00093 }
00094 
00095 AVFilter avfilter_vf_format = {
00096     .name      = "format",
00097     .description = "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 /* CONFIG_FORMAT_FILTER */
00117 
00118 #if CONFIG_NOFORMAT_FILTER
00119 static int query_formats_noformat(AVFilterContext *ctx)
00120 {
00121     avfilter_set_common_formats(ctx, make_format_list(ctx->priv, 0));
00122     return 0;
00123 }
00124 
00125 AVFilter avfilter_vf_noformat = {
00126     .name      = "noformat",
00127     .description = "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 /* CONFIG_NOFORMAT_FILTER */
00147 

Generated on Fri Sep 16 2011 17:17:47 for FFmpeg by  doxygen 1.7.1