]> git.sesse.net Git - ffmpeg/blob - libavfilter/vf_aspect.c
Remove redundant information in header.
[ffmpeg] / libavfilter / vf_aspect.c
1 /*
2  * Copyright (c) 2010 Bobby Bingham
3
4  * This file is part of FFmpeg.
5  *
6  * FFmpeg is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * FFmpeg is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with FFmpeg; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19  */
20
21 /**
22  * @file
23  * aspect ratio modification video filters
24  */
25
26 #include "avfilter.h"
27
28 typedef struct {
29     AVRational aspect;
30 } AspectContext;
31
32 static av_cold int init(AVFilterContext *ctx, const char *args, void *opaque)
33 {
34     AspectContext *aspect = ctx->priv;
35     double  ratio;
36     int64_t gcd;
37
38     if(args) {
39         if(sscanf(args, "%d:%d", &aspect->aspect.num, &aspect->aspect.den) < 2) {
40             if(sscanf(args, "%lf", &ratio) < 1)
41                 return -1;
42             aspect->aspect = av_d2q(ratio, 100);
43         } else {
44             gcd = av_gcd(FFABS(aspect->aspect.num), FFABS(aspect->aspect.den));
45             if(gcd) {
46                 aspect->aspect.num /= gcd;
47                 aspect->aspect.den /= gcd;
48             }
49         }
50     }
51
52     if(aspect->aspect.den == 0)
53         aspect->aspect = (AVRational) {0, 1};
54
55     return 0;
56 }
57
58 static void start_frame(AVFilterLink *link, AVFilterBufferRef *picref)
59 {
60     AspectContext *aspect = link->dst->priv;
61
62     picref->video->pixel_aspect = aspect->aspect;
63     avfilter_start_frame(link->dst->outputs[0], picref);
64 }
65
66 #if CONFIG_ASPECT_FILTER
67 /* for aspect filter, convert from frame aspect ratio to pixel aspect ratio */
68 static int frameaspect_config_props(AVFilterLink *inlink)
69 {
70     AspectContext *aspect = inlink->dst->priv;
71
72     av_reduce(&aspect->aspect.num, &aspect->aspect.den,
73                aspect->aspect.num * inlink->h,
74                aspect->aspect.den * inlink->w, 100);
75
76     return 0;
77 }
78
79 AVFilter avfilter_vf_aspect = {
80     .name      = "aspect",
81     .description = NULL_IF_CONFIG_SMALL("Set the frame aspect ratio."),
82
83     .init      = init,
84
85     .priv_size = sizeof(AspectContext),
86
87     .inputs    = (AVFilterPad[]) {{ .name             = "default",
88                                     .type             = AVMEDIA_TYPE_VIDEO,
89                                     .config_props     = frameaspect_config_props,
90                                     .get_video_buffer = avfilter_null_get_video_buffer,
91                                     .start_frame      = start_frame,
92                                     .end_frame        = avfilter_null_end_frame },
93                                   { .name = NULL}},
94
95     .outputs   = (AVFilterPad[]) {{ .name             = "default",
96                                     .type             = AVMEDIA_TYPE_VIDEO, },
97                                   { .name = NULL}},
98 };
99 #endif /* CONFIG_ASPECT_FILTER */
100
101 #if CONFIG_PIXELASPECT_FILTER
102 AVFilter avfilter_vf_pixelaspect = {
103     .name      = "pixelaspect",
104     .description = NULL_IF_CONFIG_SMALL("Set the pixel aspect ratio."),
105
106     .init      = init,
107
108     .priv_size = sizeof(AspectContext),
109
110     .inputs    = (AVFilterPad[]) {{ .name             = "default",
111                                     .type             = AVMEDIA_TYPE_VIDEO,
112                                     .get_video_buffer = avfilter_null_get_video_buffer,
113                                     .start_frame      = start_frame,
114                                     .end_frame        = avfilter_null_end_frame },
115                                   { .name = NULL}},
116
117     .outputs   = (AVFilterPad[]) {{ .name             = "default",
118                                     .type             = AVMEDIA_TYPE_VIDEO, },
119                                   { .name = NULL}},
120 };
121 #endif /* CONFIG_PIXELASPECT_FILTER */
122