00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00026 #include "libavutil/common.h"
00027 #include "libavutil/mathematics.h"
00028 #include "libavutil/parseutils.h"
00029 #include "avfilter.h"
00030 #include "internal.h"
00031 #include "video.h"
00032
00033 typedef struct {
00034 AVRational ratio;
00035 } AspectContext;
00036
00037 static av_cold int init(AVFilterContext *ctx, const char *args)
00038 {
00039 AspectContext *aspect = ctx->priv;
00040 aspect->ratio = (AVRational) {0, 1};
00041
00042 if (args) {
00043 if (av_parse_ratio(&aspect->ratio, args, 100, 0, ctx) < 0 ||
00044 aspect->ratio.num < 0 || aspect->ratio.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
00051 av_log(ctx, AV_LOG_VERBOSE, "a:%d/%d\n", aspect->ratio.num, aspect->ratio.den);
00052 return 0;
00053 }
00054
00055 static int start_frame(AVFilterLink *link, AVFilterBufferRef *picref)
00056 {
00057 AspectContext *aspect = link->dst->priv;
00058
00059 picref->video->sample_aspect_ratio = aspect->ratio;
00060 link->cur_buf = NULL;
00061 return ff_start_frame(link->dst->outputs[0], picref);
00062 }
00063
00064 #if CONFIG_SETDAR_FILTER
00065 static int setdar_config_props(AVFilterLink *inlink)
00066 {
00067 AspectContext *aspect = inlink->dst->priv;
00068 AVRational dar = aspect->ratio;
00069
00070 av_reduce(&aspect->ratio.num, &aspect->ratio.den,
00071 aspect->ratio.num * inlink->h,
00072 aspect->ratio.den * inlink->w, 100);
00073
00074 av_log(inlink->dst, AV_LOG_VERBOSE, "w:%d h:%d -> dar:%d/%d sar:%d/%d\n",
00075 inlink->w, inlink->h, dar.num, dar.den, aspect->ratio.num, aspect->ratio.den);
00076
00077 inlink->sample_aspect_ratio = aspect->ratio;
00078
00079 return 0;
00080 }
00081
00082 AVFilter avfilter_vf_setdar = {
00083 .name = "setdar",
00084 .description = NULL_IF_CONFIG_SMALL("Set the frame display aspect ratio."),
00085
00086 .init = init,
00087
00088 .priv_size = sizeof(AspectContext),
00089
00090 .inputs = (const AVFilterPad[]) {{ .name = "default",
00091 .type = AVMEDIA_TYPE_VIDEO,
00092 .config_props = setdar_config_props,
00093 .get_video_buffer = ff_null_get_video_buffer,
00094 .start_frame = start_frame,
00095 .end_frame = ff_null_end_frame },
00096 { .name = NULL}},
00097
00098 .outputs = (const AVFilterPad[]) {{ .name = "default",
00099 .type = AVMEDIA_TYPE_VIDEO, },
00100 { .name = NULL}},
00101 };
00102 #endif
00103
00104 #if CONFIG_SETSAR_FILTER
00105 static int setsar_config_props(AVFilterLink *inlink)
00106 {
00107 AspectContext *aspect = inlink->dst->priv;
00108
00109 inlink->sample_aspect_ratio = aspect->ratio;
00110
00111 return 0;
00112 }
00113
00114 AVFilter avfilter_vf_setsar = {
00115 .name = "setsar",
00116 .description = NULL_IF_CONFIG_SMALL("Set the pixel sample aspect ratio."),
00117
00118 .init = init,
00119
00120 .priv_size = sizeof(AspectContext),
00121
00122 .inputs = (const AVFilterPad[]) {{ .name = "default",
00123 .type = AVMEDIA_TYPE_VIDEO,
00124 .config_props = setsar_config_props,
00125 .get_video_buffer = ff_null_get_video_buffer,
00126 .start_frame = start_frame,
00127 .end_frame = ff_null_end_frame },
00128 { .name = NULL}},
00129
00130 .outputs = (const AVFilterPad[]) {{ .name = "default",
00131 .type = AVMEDIA_TYPE_VIDEO, },
00132 { .name = NULL}},
00133 };
00134 #endif