00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00026 #include "avfilter.h"
00027
00028 typedef struct {
00029 AVRational aspect;
00030 } AspectContext;
00031
00032 static av_cold int init(AVFilterContext *ctx, const char *args, void *opaque)
00033 {
00034 AspectContext *aspect = ctx->priv;
00035 double ratio;
00036 int64_t gcd;
00037 char c = 0;
00038
00039 if (args) {
00040 if (sscanf(args, "%d:%d%c", &aspect->aspect.num, &aspect->aspect.den, &c) != 2)
00041 if (sscanf(args, "%lf%c", &ratio, &c) == 1)
00042 aspect->aspect = av_d2q(ratio, 100);
00043
00044 if (c || aspect->aspect.num <= 0 || aspect->aspect.den <= 0) {
00045 av_log(ctx, AV_LOG_ERROR,
00046 "Invalid string '%s' for aspect ratio.\n", args);
00047 return AVERROR(EINVAL);
00048 }
00049
00050 gcd = av_gcd(FFABS(aspect->aspect.num), FFABS(aspect->aspect.den));
00051 if (gcd) {
00052 aspect->aspect.num /= gcd;
00053 aspect->aspect.den /= gcd;
00054 }
00055 }
00056
00057 if (aspect->aspect.den == 0)
00058 aspect->aspect = (AVRational) {0, 1};
00059
00060 av_log(ctx, AV_LOG_INFO, "a:%d/%d\n", aspect->aspect.num, aspect->aspect.den);
00061 return 0;
00062 }
00063
00064 static void start_frame(AVFilterLink *link, AVFilterBufferRef *picref)
00065 {
00066 AspectContext *aspect = link->dst->priv;
00067
00068 picref->video->pixel_aspect = aspect->aspect;
00069 avfilter_start_frame(link->dst->outputs[0], picref);
00070 }
00071
00072 #if CONFIG_SETDAR_FILTER
00073
00074 static int setdar_config_props(AVFilterLink *inlink)
00075 {
00076 AspectContext *aspect = inlink->dst->priv;
00077 AVRational dar = aspect->aspect;
00078
00079 av_reduce(&aspect->aspect.num, &aspect->aspect.den,
00080 aspect->aspect.num * inlink->h,
00081 aspect->aspect.den * inlink->w, 100);
00082
00083 av_log(inlink->dst, AV_LOG_INFO, "w:%d h:%d -> dar:%d/%d par:%d/%d\n",
00084 inlink->w, inlink->h, dar.num, dar.den, aspect->aspect.num, aspect->aspect.den);
00085 return 0;
00086 }
00087
00088 AVFilter avfilter_vf_setdar = {
00089 .name = "setdar",
00090 .description = NULL_IF_CONFIG_SMALL("Set the frame display aspect ratio."),
00091
00092 .init = init,
00093
00094 .priv_size = sizeof(AspectContext),
00095
00096 .inputs = (AVFilterPad[]) {{ .name = "default",
00097 .type = AVMEDIA_TYPE_VIDEO,
00098 .config_props = setdar_config_props,
00099 .get_video_buffer = avfilter_null_get_video_buffer,
00100 .start_frame = start_frame,
00101 .end_frame = avfilter_null_end_frame },
00102 { .name = NULL}},
00103
00104 .outputs = (AVFilterPad[]) {{ .name = "default",
00105 .type = AVMEDIA_TYPE_VIDEO, },
00106 { .name = NULL}},
00107 };
00108 #endif
00109
00110 #if CONFIG_SETSAR_FILTER
00111 AVFilter avfilter_vf_setsar = {
00112 .name = "setsar",
00113 .description = NULL_IF_CONFIG_SMALL("Set the pixel sample aspect ratio."),
00114
00115 .init = init,
00116
00117 .priv_size = sizeof(AspectContext),
00118
00119 .inputs = (AVFilterPad[]) {{ .name = "default",
00120 .type = AVMEDIA_TYPE_VIDEO,
00121 .get_video_buffer = avfilter_null_get_video_buffer,
00122 .start_frame = start_frame,
00123 .end_frame = avfilter_null_end_frame },
00124 { .name = NULL}},
00125
00126 .outputs = (AVFilterPad[]) {{ .name = "default",
00127 .type = AVMEDIA_TYPE_VIDEO, },
00128 { .name = NULL}},
00129 };
00130 #endif
00131