Originally committed as revision 22573 to svn://svn.ffmpeg.org/ffmpeg/trunk
Showing the changes to libavfilter (3 of 3 files). Show all
Unified · Split
| @@ -14,10 +14,12 @@ OBJS = allfilters.o \ · 13 unmodified lines | ||
| 14 | 14 | graphparser.o \ |
| 15 | 15 | parseutils.o \ |
| 16 | 16 | |
| 17 | +OBJS-$(CONFIG_ASPECT_FILTER) += vf_aspect.o | |
| 17 | 18 | OBJS-$(CONFIG_CROP_FILTER) += vf_crop.o |
| 18 | 19 | OBJS-$(CONFIG_FORMAT_FILTER) += vf_format.o |
| 19 | 20 | OBJS-$(CONFIG_NOFORMAT_FILTER) += vf_format.o |
| 20 | 21 | OBJS-$(CONFIG_NULL_FILTER) += vf_null.o |
| 22 | +OBJS-$(CONFIG_PIXELASPECT_FILTER) += vf_aspect.o | |
| 21 | 23 | OBJS-$(CONFIG_SCALE_FILTER) += vf_scale.o |
| 22 | 24 | OBJS-$(CONFIG_SLICIFY_FILTER) += vf_slicify.o |
| 23 | 25 | OBJS-$(CONFIG_VFLIP_FILTER) += vf_vflip.o |
| @@ -34,15 +34,17 @@ void avfilter_register_all(void) · 33 unmodified lines | ||
| 34 | 34 | return; |
| 35 | 35 | initialized = 1; |
| 36 | 36 | |
| 37 | + REGISTER_FILTER (ASPECT, aspect, vf); | |
| 37 | 38 | REGISTER_FILTER (CROP, crop, vf); |
| 38 | 39 | REGISTER_FILTER (FORMAT, format, vf); |
| 39 | 40 | REGISTER_FILTER (NOFORMAT, noformat, vf); |
| 40 | 41 | REGISTER_FILTER (NULL, null, vf); |
| 42 | + REGISTER_FILTER (PIXELASPECT, pixelaspect, vf); | |
| 41 | 43 | REGISTER_FILTER (SCALE, scale, vf); |
| 42 | 44 | REGISTER_FILTER (SLICIFY, slicify, vf); |
| 43 | 45 | REGISTER_FILTER (VFLIP, vflip, vf); |
| 44 | 46 | |
| 45 | 47 | REGISTER_FILTER (NULLSRC, nullsrc, vsrc); |
| 46 | 48 | |
| 47 | − REGISTER_FILTER(NULLSINK, nullsink, vsink); | |
| 49 | + REGISTER_FILTER (NULLSINK, nullsink, vsink); | |
| 48 | 50 | } |
| @@ -0,0 +1,135 @@ | ||
| 1 | +/* | |
| 2 | + * Aspect ratio modification video filter | |
| 3 | + * Copyright (c) 2010 Bobby Bingham | |
| 4 | + | |
| 5 | + * This file is part of FFmpeg. | |
| 6 | + * | |
| 7 | + * FFmpeg is free software; you can redistribute it and/or | |
| 8 | + * modify it under the terms of the GNU Lesser General Public | |
| 9 | + * License as published by the Free Software Foundation; either | |
| 10 | + * version 2.1 of the License, or (at your option) any later version. | |
| 11 | + * | |
| 12 | + * FFmpeg is distributed in the hope that it will be useful, | |
| 13 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 14 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
| 15 | + * Lesser General Public License for more details. | |
| 16 | + * | |
| 17 | + * You should have received a copy of the GNU Lesser General Public | |
| 18 | + * License along with FFmpeg; if not, write to the Free Software | |
| 19 | + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | |
| 20 | + */ | |
| 21 | + | |
| 22 | +/** | |
| 23 | + * @file libavfilter/vf_aspect.c | |
| 24 | + * aspect ratio modification video filter | |
| 25 | + */ | |
| 26 | + | |
| 27 | +#include "avfilter.h" | |
| 28 | + | |
| 29 | +typedef struct { | |
| 30 | + AVRational aspect; | |
| 31 | +} AspectContext; | |
| 32 | + | |
| 33 | +static av_cold int init(AVFilterContext *ctx, const char *args, void *opaque) | |
| 34 | +{ | |
| 35 | + AspectContext *aspect = ctx->priv; | |
| 36 | + double ratio; | |
| 37 | + int64_t gcd; | |
| 38 | + | |
| 39 | + if(args) { | |
| 40 | + if(sscanf(args, "%d:%d", &aspect->aspect.num, &aspect->aspect.den) < 2) { | |
| 41 | + if(sscanf(args, "%lf", &ratio) < 1) | |
| 42 | + return -1; | |
| 43 | + aspect->aspect = av_d2q(ratio, 100); | |
| 44 | + } else { | |
| 45 | + gcd = av_gcd(FFABS(aspect->aspect.num), FFABS(aspect->aspect.den)); | |
| 46 | + if(gcd) { | |
| 47 | + aspect->aspect.num /= gcd; | |
| 48 | + aspect->aspect.den /= gcd; | |
| 49 | + } | |
| 50 | + } | |
| 51 | + } | |
| 52 | + | |
| 53 | + if(aspect->aspect.den == 0) | |
| 54 | + aspect->aspect = (AVRational) {0, 1}; | |
| 55 | + | |
| 56 | + return 0; | |
| 57 | +} | |
| 58 | + | |
| 59 | + | |
| 60 | +static AVFilterPicRef *get_video_buffer(AVFilterLink *link, int perms, | |
| 61 | + int w, int h) | |
| 62 | +{ | |
| 63 | + return avfilter_get_video_buffer(link->dst->outputs[0], perms, w, h); | |
| 64 | +} | |
| 65 | + | |
| 66 | +static void start_frame(AVFilterLink *link, AVFilterPicRef *picref) | |
| 67 | +{ | |
| 68 | + AspectContext *aspect = link->dst->priv; | |
| 69 | + | |
| 70 | + picref->pixel_aspect = aspect->aspect; | |
| 71 | + avfilter_start_frame(link->dst->outputs[0], picref); | |
| 72 | +} | |
| 73 | + | |
| 74 | +static void end_frame(AVFilterLink *link) | |
| 75 | +{ | |
| 76 | + avfilter_end_frame(link->dst->outputs[0]); | |
| 77 | +} | |
| 78 | + | |
| 79 | +#if CONFIG_ASPECT_FILTER | |
| 80 | +/* for aspect filter, convert from frame aspect ratio to pixel aspect ratio */ | |
| 81 | +static int frameaspect_config_props(AVFilterLink *inlink) | |
| 82 | +{ | |
| 83 | + AspectContext *aspect = inlink->dst->priv; | |
| 84 | + | |
| 85 | + av_reduce(&aspect->aspect.num, &aspect->aspect.den, | |
| 86 | + aspect->aspect.num * inlink->h, | |
| 87 | + aspect->aspect.den * inlink->w, 100); | |
| 88 | + | |
| 89 | + return 0; | |
| 90 | +} | |
| 91 | + | |
| 92 | +AVFilter avfilter_vf_aspect = { | |
| 93 | + .name = "aspect", | |
| 94 | + .description = NULL_IF_CONFIG_SMALL("Set the frame aspect ratio."), | |
| 95 | + | |
| 96 | + .init = init, | |
| 97 | + | |
| 98 | + .priv_size = sizeof(AspectContext), | |
| 99 | + | |
| 100 | + .inputs = (AVFilterPad[]) {{ .name = "default", | |
| 101 | + .type = CODEC_TYPE_VIDEO, | |
| 102 | + .config_props = frameaspect_config_props, | |
| 103 | + .get_video_buffer = get_video_buffer, | |
| 104 | + .start_frame = start_frame, | |
| 105 | + .end_frame = end_frame }, | |
| 106 | + { .name = NULL}}, | |
| 107 | + | |
| 108 | + .outputs = (AVFilterPad[]) {{ .name = "default", | |
| 109 | + .type = CODEC_TYPE_VIDEO, }, | |
| 110 | + { .name = NULL}}, | |
| 111 | +}; | |
| 112 | +#endif /* CONFIG_ASPECT_FILTER */ | |
| 113 | + | |
| 114 | +#if CONFIG_PIXELASPECT_FILTER | |
| 115 | +AVFilter avfilter_vf_pixelaspect = { | |
| 116 | + .name = "pixelaspect", | |
| 117 | + .description = NULL_IF_CONFIG_SMALL("Set the pixel aspect ratio."), | |
| 118 | + | |
| 119 | + .init = init, | |
| 120 | + | |
| 121 | + .priv_size = sizeof(AspectContext), | |
| 122 | + | |
| 123 | + .inputs = (AVFilterPad[]) {{ .name = "default", | |
| 124 | + .type = CODEC_TYPE_VIDEO, | |
| 125 | + .get_video_buffer = get_video_buffer, | |
| 126 | + .start_frame = start_frame, | |
| 127 | + .end_frame = end_frame }, | |
| 128 | + { .name = NULL}}, | |
| 129 | + | |
| 130 | + .outputs = (AVFilterPad[]) {{ .name = "default", | |
| 131 | + .type = CODEC_TYPE_VIDEO, }, | |
| 132 | + { .name = NULL}}, | |
| 133 | +}; | |
| 134 | +#endif /* CONFIG_PIXELASPECT_FILTER */ | |
| 135 | + | |