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

libavfilter/vf_aspect.c

Go to the documentation of this file.
00001 /*
00002  * Aspect ratio modification video filter
00003  * Copyright (c) 2010 Bobby Bingham
00004 
00005  * This file is part of FFmpeg.
00006  *
00007  * FFmpeg is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU Lesser General Public
00009  * License as published by the Free Software Foundation; either
00010  * version 2.1 of the License, or (at your option) any later version.
00011  *
00012  * FFmpeg is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015  * Lesser General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU Lesser General Public
00018  * License along with FFmpeg; if not, write to the Free Software
00019  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
00020  */
00021 
00027 #include "avfilter.h"
00028 
00029 typedef struct {
00030     AVRational aspect;
00031 } AspectContext;
00032 
00033 static av_cold int init(AVFilterContext *ctx, const char *args, void *opaque)
00034 {
00035     AspectContext *aspect = ctx->priv;
00036     double  ratio;
00037     int64_t gcd;
00038 
00039     if(args) {
00040         if(sscanf(args, "%d:%d", &aspect->aspect.num, &aspect->aspect.den) < 2) {
00041             if(sscanf(args, "%lf", &ratio) < 1)
00042                 return -1;
00043             aspect->aspect = av_d2q(ratio, 100);
00044         } else {
00045             gcd = av_gcd(FFABS(aspect->aspect.num), FFABS(aspect->aspect.den));
00046             if(gcd) {
00047                 aspect->aspect.num /= gcd;
00048                 aspect->aspect.den /= gcd;
00049             }
00050         }
00051     }
00052 
00053     if(aspect->aspect.den == 0)
00054         aspect->aspect = (AVRational) {0, 1};
00055 
00056     return 0;
00057 }
00058 
00059 static void start_frame(AVFilterLink *link, AVFilterPicRef *picref)
00060 {
00061     AspectContext *aspect = link->dst->priv;
00062 
00063     picref->pixel_aspect = aspect->aspect;
00064     avfilter_start_frame(link->dst->outputs[0], picref);
00065 }
00066 
00067 #if CONFIG_ASPECT_FILTER
00068 /* for aspect filter, convert from frame aspect ratio to pixel aspect ratio */
00069 static int frameaspect_config_props(AVFilterLink *inlink)
00070 {
00071     AspectContext *aspect = inlink->dst->priv;
00072 
00073     av_reduce(&aspect->aspect.num, &aspect->aspect.den,
00074                aspect->aspect.num * inlink->h,
00075                aspect->aspect.den * inlink->w, 100);
00076 
00077     return 0;
00078 }
00079 
00080 AVFilter avfilter_vf_aspect = {
00081     .name      = "aspect",
00082     .description = NULL_IF_CONFIG_SMALL("Set the frame aspect ratio."),
00083 
00084     .init      = init,
00085 
00086     .priv_size = sizeof(AspectContext),
00087 
00088     .inputs    = (AVFilterPad[]) {{ .name             = "default",
00089                                     .type             = AVMEDIA_TYPE_VIDEO,
00090                                     .config_props     = frameaspect_config_props,
00091                                     .get_video_buffer = avfilter_null_get_video_buffer,
00092                                     .start_frame      = start_frame,
00093                                     .end_frame        = avfilter_null_end_frame },
00094                                   { .name = NULL}},
00095 
00096     .outputs   = (AVFilterPad[]) {{ .name             = "default",
00097                                     .type             = AVMEDIA_TYPE_VIDEO, },
00098                                   { .name = NULL}},
00099 };
00100 #endif /* CONFIG_ASPECT_FILTER */
00101 
00102 #if CONFIG_PIXELASPECT_FILTER
00103 AVFilter avfilter_vf_pixelaspect = {
00104     .name      = "pixelaspect",
00105     .description = NULL_IF_CONFIG_SMALL("Set the pixel aspect ratio."),
00106 
00107     .init      = init,
00108 
00109     .priv_size = sizeof(AspectContext),
00110 
00111     .inputs    = (AVFilterPad[]) {{ .name             = "default",
00112                                     .type             = AVMEDIA_TYPE_VIDEO,
00113                                     .get_video_buffer = avfilter_null_get_video_buffer,
00114                                     .start_frame      = start_frame,
00115                                     .end_frame        = avfilter_null_end_frame },
00116                                   { .name = NULL}},
00117 
00118     .outputs   = (AVFilterPad[]) {{ .name             = "default",
00119                                     .type             = AVMEDIA_TYPE_VIDEO, },
00120                                   { .name = NULL}},
00121 };
00122 #endif /* CONFIG_PIXELASPECT_FILTER */
00123 

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