[FFmpeg-devel] [PATCH] lavfi: tweak aspect-ratio computation in pad and scale filters
Stefano Sabatini
stefano.sabatini-lala at poste.it
Wed Jul 27 11:12:23 CEST 2011
Previously, "dar" and "a" were documented like "input sample aspect
ratio", but their actual value was "in_w/in_h", which is not the very
same thing.
In order to avoid to break scripts which rely on the "a" variable, the
patch keeps the same semantics but fixes the corresponding docs, while
fixes the semantics of the recently added "dar" variable, which
correctly express the Display Aspect Ratio value as (inw_w/in_h)*sar.
---
doc/filters.texi | 14 ++++++++++----
libavfilter/vf_pad.c | 9 ++++++---
libavfilter/vf_scale.c | 9 ++++++---
3 files changed, 22 insertions(+), 10 deletions(-)
diff --git a/doc/filters.texi b/doc/filters.texi
index 8054bff..2e419a8 100644
--- a/doc/filters.texi
+++ b/doc/filters.texi
@@ -1184,12 +1184,15 @@ same as @var{out_w} and @var{out_h}
x and y offsets as specified by the @var{x} and @var{y}
expressions, or NAN if not yet specified
- at item dar, a
-input display aspect ratio, same as @var{iw} / @var{ih}
+ at item a
+same as @var{iw} / @var{ih}
@item sar
input sample aspect ratio
+ at item dar
+input display aspect ratio, it is the same as (@var{iw} / @var{ih}) * @var{sar}
+
@item hsub, vsub
horizontal and vertical chroma subsample values. For example for the
pixel format "yuv422p" @var{hsub} is 2 and @var{vsub} is 1.
@@ -1289,12 +1292,15 @@ the output (cropped) width and heigth
@item ow, oh
same as @var{out_w} and @var{out_h}
- at item dar, a
-input display aspect ratio, same as @var{iw} / @var{ih}
+ at item a
+same as @var{iw} / @var{ih}
@item sar
input sample aspect ratio
+ at item dar
+input display aspect ratio, it is the same as (@var{iw} / @var{ih}) * @var{sar}
+
@item hsub, vsub
horizontal and vertical chroma subsample values. For example for the
pixel format "yuv422p" @var{hsub} is 2 and @var{vsub} is 1.
diff --git a/libavfilter/vf_pad.c b/libavfilter/vf_pad.c
index e01a750..c4edc23 100644
--- a/libavfilter/vf_pad.c
+++ b/libavfilter/vf_pad.c
@@ -45,8 +45,9 @@ static const char *var_names[] = {
"out_h", "oh",
"x",
"y",
- "a", "dar",
+ "a",
"sar",
+ "dar",
"hsub",
"vsub",
NULL
@@ -62,8 +63,9 @@ enum var_name {
VAR_OUT_H, VAR_OH,
VAR_X,
VAR_Y,
- VAR_A, VAR_DAR,
+ VAR_A,
VAR_SAR,
+ VAR_DAR,
VAR_HSUB,
VAR_VSUB,
VARS_NB
@@ -158,9 +160,10 @@ static int config_input(AVFilterLink *inlink)
var_values[VAR_IN_H] = var_values[VAR_IH] = inlink->h;
var_values[VAR_OUT_W] = var_values[VAR_OW] = NAN;
var_values[VAR_OUT_H] = var_values[VAR_OH] = NAN;
- var_values[VAR_DAR] = var_values[VAR_A] = (float) inlink->w / inlink->h;
+ var_values[VAR_A] = (float) inlink->w / inlink->h;
var_values[VAR_SAR] = inlink->sample_aspect_ratio.num ?
(float) inlink->sample_aspect_ratio.num / inlink->sample_aspect_ratio.den : 1;
+ var_values[VAR_DAR] = var_values[VAR_A] * var_values[VAR_SAR];
var_values[VAR_HSUB] = 1<<pad->hsub;
var_values[VAR_VSUB] = 1<<pad->vsub;
diff --git a/libavfilter/vf_scale.c b/libavfilter/vf_scale.c
index 3be5d99..044b284 100644
--- a/libavfilter/vf_scale.c
+++ b/libavfilter/vf_scale.c
@@ -39,8 +39,9 @@ static const char *var_names[] = {
"in_h", "ih",
"out_w", "ow",
"out_h", "oh",
- "a", "dar",
+ "a",
"sar",
+ "dar",
"hsub",
"vsub",
NULL
@@ -54,8 +55,9 @@ enum var_name {
VAR_IN_H, VAR_IH,
VAR_OUT_W, VAR_OW,
VAR_OUT_H, VAR_OH,
- VAR_A, VAR_DAR,
+ VAR_A,
VAR_SAR,
+ VAR_DAR,
VAR_HSUB,
VAR_VSUB,
VARS_NB
@@ -160,9 +162,10 @@ static int config_props(AVFilterLink *outlink)
var_values[VAR_IN_H] = var_values[VAR_IH] = inlink->h;
var_values[VAR_OUT_W] = var_values[VAR_OW] = NAN;
var_values[VAR_OUT_H] = var_values[VAR_OH] = NAN;
- var_values[VAR_DAR] = var_values[VAR_A] = (float) inlink->w / inlink->h;
+ var_values[VAR_A] = (float) inlink->w / inlink->h;
var_values[VAR_SAR] = inlink->sample_aspect_ratio.num ?
(float) inlink->sample_aspect_ratio.num / inlink->sample_aspect_ratio.den : 1;
+ var_values[VAR_DAR] = var_values[VAR_A] * var_values[VAR_SAR];
var_values[VAR_HSUB] = 1<<av_pix_fmt_descriptors[inlink->format].log2_chroma_w;
var_values[VAR_VSUB] = 1<<av_pix_fmt_descriptors[inlink->format].log2_chroma_h;
--
1.7.2.5
More information about the ffmpeg-devel
mailing list