summaryrefslogtreecommitdiffstats
path: root/video/filter
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2015-12-19 20:04:31 +0100
committerwm4 <wm4@nowhere>2015-12-19 20:45:36 +0100
commit0a0bb9059f42671c267ea5d0c8faa3ac71a8c742 (patch)
tree89cbdee7748d36f98cc5d0efbfc8a3fc810b2016 /video/filter
parent1f7c099dc0feb9a160d9018ad6ad068e0295341a (diff)
downloadmpv-0a0bb9059f42671c267ea5d0c8faa3ac71a8c742.tar.bz2
mpv-0a0bb9059f42671c267ea5d0c8faa3ac71a8c742.tar.xz
video: switch from using display aspect to sample aspect
MPlayer traditionally always used the display aspect ratio, e.g. 16:9, while FFmpeg uses the sample (aka pixel) aspect ratio. Both have a bunch of advantages and disadvantages. Actually, it seems using sample aspect ratio is generally nicer. The main reason for the change is making mpv closer to how FFmpeg works in order to make life easier. It's also nice that everything uses integer fractions instead of floats now (except --video-aspect option/property). Note that there is at least 1 user-visible change: vf_dsize now does not set the display size, only the display aspect ratio. This is because the image_params d_w/d_h fields did not just set the display aspect, but also the size (except in encoding mode).
Diffstat (limited to 'video/filter')
-rw-r--r--video/filter/vf.c25
-rw-r--r--video/filter/vf.h6
-rw-r--r--video/filter/vf_crop.c6
-rw-r--r--video/filter/vf_dlopen.c9
-rw-r--r--video/filter/vf_dsize.c7
-rw-r--r--video/filter/vf_expand.c5
-rw-r--r--video/filter/vf_format.c12
-rw-r--r--video/filter/vf_lavfi.c41
-rw-r--r--video/filter/vf_scale.c8
-rw-r--r--video/filter/vf_sub.c12
-rw-r--r--video/filter/vf_vapoursynth.c7
11 files changed, 35 insertions, 103 deletions
diff --git a/video/filter/vf.c b/video/filter/vf.c
index c5d11ef222..dd5b560df3 100644
--- a/video/filter/vf.c
+++ b/video/filter/vf.c
@@ -700,28 +700,3 @@ void vf_destroy(struct vf_chain *c)
vf_chain_forget_frames(c);
talloc_free(c);
}
-
-// When changing the size of an image that had old_w/old_h with
-// DAR *d_width/*d_height to the new size new_w/new_h, adjust
-// *d_width/*d_height such that the new image has the same pixel aspect ratio.
-void vf_rescale_dsize(int *d_width, int *d_height, int old_w, int old_h,
- int new_w, int new_h)
-{
- *d_width = *d_width * new_w / old_w;
- *d_height = *d_height * new_h / old_h;
-}
-
-// Set *d_width/*d_height to display aspect ratio with the givem source size
-void vf_set_dar(int *d_w, int *d_h, int w, int h, double dar)
-{
- *d_w = w;
- *d_h = h;
- if (dar > 0.01) {
- *d_w = h * dar + 0.5;
- // we don't like horizontal downscale
- if (*d_w < w) {
- *d_w = w;
- *d_h = w / dar + 0.5;
- }
- }
-}
diff --git a/video/filter/vf.h b/video/filter/vf.h
index 2bca682fbc..2e253b88e3 100644
--- a/video/filter/vf.h
+++ b/video/filter/vf.h
@@ -174,10 +174,4 @@ void vf_add_output_frame(struct vf_instance *vf, struct mp_image *img);
// default wrappers:
int vf_next_query_format(struct vf_instance *vf, unsigned int fmt);
-// Helpers
-
-void vf_rescale_dsize(int *d_width, int *d_height, int old_w, int old_h,
- int new_w, int new_h);
-void vf_set_dar(int *d_width, int *d_height, int w, int h, double dar);
-
#endif /* MPLAYER_VF_H */
diff --git a/video/filter/vf_crop.c b/video/filter/vf_crop.c
index 79e915fd4a..89b2b6fde1 100644
--- a/video/filter/vf_crop.c
+++ b/video/filter/vf_crop.c
@@ -42,7 +42,7 @@ static const struct vf_priv_s {
static int reconfig(struct vf_instance *vf, struct mp_image_params *in,
struct mp_image_params *out)
{
- int width = in->w, height = in->h, d_width = in->d_w, d_height = in->d_h;
+ int width = in->w, height = in->h;
// calculate the missing parameters:
if(vf->priv->crop_w<=0 || vf->priv->crop_w>width) vf->priv->crop_w=width;
@@ -63,13 +63,9 @@ static int reconfig(struct vf_instance *vf, struct mp_image_params *in,
return -1;
}
- vf_rescale_dsize(&d_width, &d_height, width, height,
- vf->priv->crop_w, vf->priv->crop_h);
*out = *in;
out->w = vf->priv->crop_w;
out->h = vf->priv->crop_h;
- out->d_w = d_width;
- out->d_h = d_height;
return 0;
}
diff --git a/video/filter/vf_dlopen.c b/video/filter/vf_dlopen.c
index 7cf04ca428..bd85583a96 100644
--- a/video/filter/vf_dlopen.c
+++ b/video/filter/vf_dlopen.c
@@ -93,10 +93,11 @@ static void set_imgprop(struct vf_dlopen_picdata *out, const mp_image_t *mpi)
static int reconfig(struct vf_instance *vf, struct mp_image_params *in,
struct mp_image_params *out)
{
+ mp_image_params_get_dsize(in, &vf->priv->filter.in_d_width,
+ &vf->priv->filter.in_d_height);
+
vf->priv->filter.in_width = in->w;
vf->priv->filter.in_height = in->h;
- vf->priv->filter.in_d_width = in->d_w;
- vf->priv->filter.in_d_height = in->d_h;
vf->priv->filter.in_fmt = talloc_strdup(vf, mp_imgfmt_to_name(in->imgfmt));
vf->priv->filter.out_width = vf->priv->filter.in_width;
vf->priv->filter.out_height = vf->priv->filter.in_height;
@@ -164,8 +165,8 @@ static int reconfig(struct vf_instance *vf, struct mp_image_params *in,
*out = *in;
out->w = vf->priv->out_width;
out->h = vf->priv->out_height;
- out->d_w = vf->priv->filter.out_d_width;
- out->d_h = vf->priv->filter.out_d_height;
+ mp_image_params_set_dsize(out, vf->priv->filter.out_d_width,
+ vf->priv->filter.out_d_height);
out->imgfmt = vf->priv->outfmt;
return 0;
}
diff --git a/video/filter/vf_dsize.c b/video/filter/vf_dsize.c
index eafcaf3472..b498b317f6 100644
--- a/video/filter/vf_dsize.c
+++ b/video/filter/vf_dsize.c
@@ -39,7 +39,9 @@ struct vf_priv_s {
static int reconfig(struct vf_instance *vf, struct mp_image_params *in,
struct mp_image_params *out)
{
- int width = in->w, height = in->h, d_width = in->d_w, d_height = in->d_h;
+ int width = in->w, height = in->h;
+ int d_width, d_height;
+ mp_image_params_get_dsize(in, &d_width, &d_height);
int w = vf->priv->w;
int h = vf->priv->h;
if (vf->priv->aspect < 0.001) { // did the user input aspect or w,h params
@@ -75,8 +77,7 @@ static int reconfig(struct vf_instance *vf, struct mp_image_params *in,
}
}
*out = *in;
- out->d_w = d_width;
- out->d_h = d_height;
+ mp_image_params_set_dsize(out, d_width, d_height);
return 0;
}
diff --git a/video/filter/vf_expand.c b/video/filter/vf_expand.c
index 69574efff3..a788568e14 100644
--- a/video/filter/vf_expand.c
+++ b/video/filter/vf_expand.c
@@ -72,7 +72,7 @@ static int reconfig(struct vf_instance *vf, struct mp_image_params *in,
else if( vf->priv->exp_h<height ) vf->priv->exp_h=height;
if (vf->priv->aspect) {
float adjusted_aspect = vf->priv->aspect;
- adjusted_aspect *= ((double)width/height) / ((double)in->d_w/in->d_h);
+ adjusted_aspect *= (double)in->p_w/in->p_h;
if (vf->priv->exp_h < vf->priv->exp_w / adjusted_aspect) {
vf->priv->exp_h = vf->priv->exp_w / adjusted_aspect + 0.5;
} else {
@@ -96,9 +96,6 @@ static int reconfig(struct vf_instance *vf, struct mp_image_params *in,
out->w = vf->priv->exp_w;
out->h = vf->priv->exp_h;
- vf_rescale_dsize(&out->d_w, &out->d_h, width, height,
- vf->priv->exp_w, vf->priv->exp_h);
-
return 0;
}
diff --git a/video/filter/vf_format.c b/video/filter/vf_format.c
index 83d697b412..ff7389cb7a 100644
--- a/video/filter/vf_format.c
+++ b/video/filter/vf_format.c
@@ -20,6 +20,8 @@
#include <string.h>
#include <inttypes.h>
+#include <libavutil/rational.h>
+
#include "common/msg.h"
#include "common/common.h"
@@ -100,12 +102,16 @@ static int reconfig(struct vf_instance *vf, struct mp_image_params *in,
out->stereo_out = p->stereo_out;
if (p->rotate >= 0)
out->rotate = p->rotate;
+
+ AVRational dsize;
+ mp_image_params_get_dsize(out, &dsize.num, &dsize.den);
if (p->dw > 0)
- out->d_w = p->dw;
+ dsize.num = p->dw;
if (p->dh > 0)
- out->d_h = p->dh;
+ dsize.den = p->dh;
if (p->dar > 0)
- vf_set_dar(&out->d_w, &out->d_h, out->w, out->h, p->dar);
+ dsize = av_d2q(p->dar, INT_MAX);
+ mp_image_params_set_dsize(out, dsize.num, dsize.den);
// Make sure the user-overrides are consistent (no RGB csp for YUV, etc.).
mp_image_params_guess_csp(out);
diff --git a/video/filter/vf_lavfi.c b/video/filter/vf_lavfi.c
index a64738d355..16aeb52338 100644
--- a/video/filter/vf_lavfi.c
+++ b/video/filter/vf_lavfi.c
@@ -103,30 +103,7 @@ static void destroy_graph(struct vf_instance *vf)
p->eof = false;
}
-static AVRational par_from_sar_dar(int width, int height,
- int d_width, int d_height)
-{
- return av_div_q((AVRational){d_width, d_height},
- (AVRational){width, height});
-}
-
-static void dar_from_sar_par(int width, int height, AVRational par,
- int *out_dw, int *out_dh)
-{
- *out_dw = width;
- *out_dh = height;
- if (par.num != 0 && par.den != 0) {
- double d = av_q2d(par);
- if (d > 1.0) {
- *out_dw = floor(*out_dw * d + 0.5);
- } else {
- *out_dh = floor(*out_dh / d + 0.5);
- }
- }
-}
-
-static bool recreate_graph(struct vf_instance *vf, int width, int height,
- int d_width, int d_height, unsigned int fmt)
+static bool recreate_graph(struct vf_instance *vf, struct mp_image_params *fmt)
{
void *tmp = talloc_new(NULL);
struct vf_priv_s *p = vf->priv;
@@ -168,13 +145,12 @@ static bool recreate_graph(struct vf_instance *vf, int width, int height,
char *sws_flags = talloc_asprintf(tmp, "flags=%"PRId64, p->cfg_sws_flags);
graph->scale_sws_opts = av_strdup(sws_flags);
- AVRational par = par_from_sar_dar(width, height, d_width, d_height);
AVRational timebase = AV_TIME_BASE_Q;
char *src_args = talloc_asprintf(tmp, "%d:%d:%d:%d:%d:%d:%d",
- width, height, imgfmt2pixfmt(fmt),
+ fmt->w, fmt->h, imgfmt2pixfmt(fmt->imgfmt),
timebase.num, timebase.den,
- par.num, par.den);
+ fmt->p_w, fmt->p_h);
if (avfilter_graph_create_filter(&in, avfilter_get_by_name("buffer"),
"src", src_args, NULL, graph) < 0)
@@ -225,7 +201,7 @@ static void reset(vf_instance_t *vf)
struct vf_priv_s *p = vf->priv;
struct mp_image_params *f = &vf->fmt_in;
if (p->graph && f->imgfmt)
- recreate_graph(vf, f->w, f->h, f->d_w, f->d_h, f->imgfmt);
+ recreate_graph(vf, f);
}
static int reconfig(struct vf_instance *vf, struct mp_image_params *in,
@@ -240,7 +216,7 @@ static int reconfig(struct vf_instance *vf, struct mp_image_params *in,
return -1;
}
- if (!recreate_graph(vf, in->w, in->h, in->d_w, in->d_h, in->imgfmt))
+ if (!recreate_graph(vf, in))
return -1;
AVFilterLink *l_out = p->out->inputs[0];
@@ -251,13 +227,10 @@ static int reconfig(struct vf_instance *vf, struct mp_image_params *in,
p->par_in = l_in->sample_aspect_ratio;
- int dw, dh;
- dar_from_sar_par(l_out->w, l_out->h, l_out->sample_aspect_ratio, &dw, &dh);
-
out->w = l_out->w;
out->h = l_out->h;
- out->d_w = dw;
- out->d_h = dh;
+ out->p_w = l_out->sample_aspect_ratio.num;
+ out->p_h = l_out->sample_aspect_ratio.den;
out->imgfmt = pixfmt2imgfmt(l_out->format);
return 0;
}
diff --git a/video/filter/vf_scale.c b/video/filter/vf_scale.c
index a71f2c1038..518ff41beb 100644
--- a/video/filter/vf_scale.c
+++ b/video/filter/vf_scale.c
@@ -76,7 +76,10 @@ static int find_best_out(vf_instance_t *vf, int in_format)
static int reconfig(struct vf_instance *vf, struct mp_image_params *in,
struct mp_image_params *out)
{
- int width = in->w, height = in->h, d_width = in->d_w, d_height = in->d_h;
+ int width = in->w, height = in->h;
+ int d_width, d_height;
+ mp_image_params_get_dsize(in, &d_width, &d_height);
+
unsigned int best = find_best_out(vf, in->imgfmt);
int round_w = 0, round_h = 0;
@@ -154,8 +157,7 @@ static int reconfig(struct vf_instance *vf, struct mp_image_params *in,
*out = *in;
out->w = vf->priv->w;
out->h = vf->priv->h;
- out->d_w = d_width;
- out->d_h = d_height;
+ mp_image_params_set_dsize(out, d_width, d_height);
out->imgfmt = best;
// Second-guess what libswscale is going to output and what not.
diff --git a/video/filter/vf_sub.c b/video/filter/vf_sub.c
index f44c4c0a67..a3680a3b9a 100644
--- a/video/filter/vf_sub.c
+++ b/video/filter/vf_sub.c
@@ -52,31 +52,23 @@ struct vf_priv_s {
static int reconfig(struct vf_instance *vf, struct mp_image_params *in,
struct mp_image_params *out)
{
- int width = in->w, height = in->h, d_width = in->d_w, d_height = in->d_h;
+ int width = in->w, height = in->h;
vf->priv->outh = height + vf->priv->opt_top_margin +
vf->priv->opt_bottom_margin;
vf->priv->outw = width;
- double dar = (double)d_width / d_height;
- double sar = (double)width / height;
-
- vf_rescale_dsize(&d_width, &d_height, width, height,
- vf->priv->outw, vf->priv->outh);
-
vf->priv->dim = (struct mp_osd_res) {
.w = vf->priv->outw,
.h = vf->priv->outh,
.mt = vf->priv->opt_top_margin,
.mb = vf->priv->opt_bottom_margin,
- .display_par = sar / dar,
+ .display_par = in->p_w / (double)in->p_h,
};
*out = *in;
out->w = vf->priv->outw;
out->h = vf->priv->outh;
- out->d_w = d_width;
- out->d_h = d_height;
return 0;
}
diff --git a/video/filter/vf_vapoursynth.c b/video/filter/vf_vapoursynth.c
index 68a43d8210..57ffe4d535 100644
--- a/video/filter/vf_vapoursynth.c
+++ b/video/filter/vf_vapoursynth.c
@@ -651,8 +651,6 @@ error:
static int reconfig(struct vf_instance *vf, struct mp_image_params *in,
struct mp_image_params *out)
{
- int width = in->w, height = in->h, d_width = in->d_w, d_height = in->d_h;
-
struct vf_priv_s *p = vf->priv;
p->fmt_in = *in;
@@ -669,18 +667,15 @@ static int reconfig(struct vf_instance *vf, struct mp_image_params *in,
}
struct mp_imgfmt_desc desc = mp_imgfmt_get_desc(in->imgfmt);
- if (width % desc.align_x || height % desc.align_y) {
+ if (in->w % desc.align_x || in->h % desc.align_y) {
MP_FATAL(vf, "VapourSynth does not allow unaligned/cropped video sizes.\n");
destroy_vs(vf);
return -1;
}
- vf_rescale_dsize(&d_width, &d_height, width, height, vi->width, vi->height);
*out = *in;
out->w = vi->width;
out->h = vi->height;
- out->d_w = d_width;
- out->d_h = d_height;
return 0;
}