00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
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
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
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
00123