2010-03-17 04:43:14 +01:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2010 Bobby Bingham
|
|
|
|
|
|
|
|
* This file is part of FFmpeg.
|
|
|
|
*
|
|
|
|
* FFmpeg is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* FFmpeg is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with FFmpeg; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2010-04-20 16:45:34 +02:00
|
|
|
* @file
|
2010-11-18 21:37:17 +01:00
|
|
|
* aspect ratio modification video filters
|
2010-03-17 04:43:14 +01:00
|
|
|
*/
|
|
|
|
|
2012-08-06 15:49:32 +02:00
|
|
|
#include "libavutil/common.h"
|
2011-06-04 13:58:23 +02:00
|
|
|
#include "libavutil/mathematics.h"
|
2012-01-17 15:25:14 +01:00
|
|
|
#include "libavutil/parseutils.h"
|
2010-03-17 04:43:14 +01:00
|
|
|
#include "avfilter.h"
|
2012-06-12 20:12:42 +02:00
|
|
|
#include "internal.h"
|
2012-05-19 10:37:56 +02:00
|
|
|
#include "video.h"
|
2010-03-17 04:43:14 +01:00
|
|
|
|
|
|
|
typedef struct {
|
2012-01-24 22:47:32 +01:00
|
|
|
AVRational ratio;
|
2010-03-17 04:43:14 +01:00
|
|
|
} AspectContext;
|
|
|
|
|
2012-06-21 07:55:56 +02:00
|
|
|
static av_cold int init(AVFilterContext *ctx, const char *args)
|
2010-03-17 04:43:14 +01:00
|
|
|
{
|
|
|
|
AspectContext *aspect = ctx->priv;
|
2012-02-18 11:41:53 +01:00
|
|
|
aspect->ratio = (AVRational) {0, 1};
|
2010-03-17 04:43:14 +01:00
|
|
|
|
2010-11-18 21:37:20 +01:00
|
|
|
if (args) {
|
2012-03-21 14:39:24 +01:00
|
|
|
if (av_parse_ratio(&aspect->ratio, args, 100, 0, ctx) < 0 ||
|
2012-01-24 22:47:32 +01:00
|
|
|
aspect->ratio.num < 0 || aspect->ratio.den <= 0) {
|
2010-11-22 23:03:30 +01:00
|
|
|
av_log(ctx, AV_LOG_ERROR,
|
|
|
|
"Invalid string '%s' for aspect ratio.\n", args);
|
2012-03-19 20:06:06 +01:00
|
|
|
return AVERROR(EINVAL);
|
2010-11-22 23:03:30 +01:00
|
|
|
}
|
2010-03-17 04:43:14 +01:00
|
|
|
}
|
2012-02-18 11:31:28 +01:00
|
|
|
|
2012-06-27 01:58:09 +02:00
|
|
|
av_log(ctx, AV_LOG_VERBOSE, "a:%d/%d\n", aspect->ratio.num, aspect->ratio.den);
|
2010-03-17 04:43:14 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-07-08 17:29:42 +02:00
|
|
|
static int start_frame(AVFilterLink *link, AVFilterBufferRef *picref)
|
2010-03-17 04:43:14 +01:00
|
|
|
{
|
|
|
|
AspectContext *aspect = link->dst->priv;
|
|
|
|
|
2012-01-24 22:47:32 +01:00
|
|
|
picref->video->sample_aspect_ratio = aspect->ratio;
|
2012-07-11 09:58:43 +02:00
|
|
|
link->cur_buf = NULL;
|
2012-07-08 17:29:42 +02:00
|
|
|
return ff_start_frame(link->dst->outputs[0], picref);
|
2010-03-17 04:43:14 +01:00
|
|
|
}
|
|
|
|
|
2010-11-22 23:03:24 +01:00
|
|
|
#if CONFIG_SETDAR_FILTER
|
|
|
|
static int setdar_config_props(AVFilterLink *inlink)
|
2010-03-17 04:43:14 +01:00
|
|
|
{
|
|
|
|
AspectContext *aspect = inlink->dst->priv;
|
2012-01-24 22:47:32 +01:00
|
|
|
AVRational dar = aspect->ratio;
|
2010-03-17 04:43:14 +01:00
|
|
|
|
2012-01-24 22:47:32 +01:00
|
|
|
av_reduce(&aspect->ratio.num, &aspect->ratio.den,
|
|
|
|
aspect->ratio.num * inlink->h,
|
|
|
|
aspect->ratio.den * inlink->w, 100);
|
2010-03-17 04:43:14 +01:00
|
|
|
|
2012-06-25 06:31:38 +02:00
|
|
|
av_log(inlink->dst, AV_LOG_VERBOSE, "w:%d h:%d -> dar:%d/%d sar:%d/%d\n",
|
2012-01-24 22:47:32 +01:00
|
|
|
inlink->w, inlink->h, dar.num, dar.den, aspect->ratio.num, aspect->ratio.den);
|
2011-01-31 18:51:47 +01:00
|
|
|
|
2012-01-24 22:47:32 +01:00
|
|
|
inlink->sample_aspect_ratio = aspect->ratio;
|
2011-01-31 18:51:47 +01:00
|
|
|
|
2010-03-17 04:43:14 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-11-22 23:03:24 +01:00
|
|
|
AVFilter avfilter_vf_setdar = {
|
|
|
|
.name = "setdar",
|
|
|
|
.description = NULL_IF_CONFIG_SMALL("Set the frame display aspect ratio."),
|
2010-03-17 04:43:14 +01:00
|
|
|
|
|
|
|
.init = init,
|
|
|
|
|
|
|
|
.priv_size = sizeof(AspectContext),
|
|
|
|
|
2012-07-21 18:45:52 +02:00
|
|
|
.inputs = (const AVFilterPad[]) {{ .name = "default",
|
|
|
|
.type = AVMEDIA_TYPE_VIDEO,
|
|
|
|
.config_props = setdar_config_props,
|
|
|
|
.get_video_buffer = ff_null_get_video_buffer,
|
|
|
|
.start_frame = start_frame,
|
|
|
|
.end_frame = ff_null_end_frame },
|
|
|
|
{ .name = NULL}},
|
|
|
|
|
|
|
|
.outputs = (const AVFilterPad[]) {{ .name = "default",
|
|
|
|
.type = AVMEDIA_TYPE_VIDEO, },
|
|
|
|
{ .name = NULL}},
|
2010-03-17 04:43:14 +01:00
|
|
|
};
|
2010-11-22 23:03:24 +01:00
|
|
|
#endif /* CONFIG_SETDAR_FILTER */
|
2010-03-17 04:43:14 +01:00
|
|
|
|
2010-11-22 23:03:24 +01:00
|
|
|
#if CONFIG_SETSAR_FILTER
|
2011-01-31 18:51:47 +01:00
|
|
|
static int setsar_config_props(AVFilterLink *inlink)
|
|
|
|
{
|
|
|
|
AspectContext *aspect = inlink->dst->priv;
|
|
|
|
|
2012-01-24 22:47:32 +01:00
|
|
|
inlink->sample_aspect_ratio = aspect->ratio;
|
2011-01-31 18:51:47 +01:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-11-22 23:03:24 +01:00
|
|
|
AVFilter avfilter_vf_setsar = {
|
|
|
|
.name = "setsar",
|
|
|
|
.description = NULL_IF_CONFIG_SMALL("Set the pixel sample aspect ratio."),
|
2010-03-17 04:43:14 +01:00
|
|
|
|
|
|
|
.init = init,
|
|
|
|
|
|
|
|
.priv_size = sizeof(AspectContext),
|
|
|
|
|
2012-07-21 18:45:52 +02:00
|
|
|
.inputs = (const AVFilterPad[]) {{ .name = "default",
|
|
|
|
.type = AVMEDIA_TYPE_VIDEO,
|
|
|
|
.config_props = setsar_config_props,
|
|
|
|
.get_video_buffer = ff_null_get_video_buffer,
|
|
|
|
.start_frame = start_frame,
|
|
|
|
.end_frame = ff_null_end_frame },
|
|
|
|
{ .name = NULL}},
|
|
|
|
|
|
|
|
.outputs = (const AVFilterPad[]) {{ .name = "default",
|
|
|
|
.type = AVMEDIA_TYPE_VIDEO, },
|
|
|
|
{ .name = NULL}},
|
2010-03-17 04:43:14 +01:00
|
|
|
};
|
2010-11-22 23:03:24 +01:00
|
|
|
#endif /* CONFIG_SETSAR_FILTER */
|