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