summaryrefslogtreecommitdiffstats
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
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).
-rw-r--r--DOCS/man/vf.rst8
-rw-r--r--demux/demux_disc.c5
-rw-r--r--demux/demux_lavf.c8
-rw-r--r--demux/demux_mkv.c13
-rw-r--r--demux/stheader.h2
-rw-r--r--player/command.c22
-rw-r--r--player/playloop.c2
-rw-r--r--player/screenshot.c9
-rw-r--r--player/video.c7
-rw-r--r--sub/osd.c5
-rw-r--r--sub/sd_ass.c6
-rw-r--r--sub/sd_lavc.c7
-rw-r--r--video/decode/dec_video.c30
-rw-r--r--video/decode/vd_lavc.c8
-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
-rw-r--r--video/image_writer.c4
-rw-r--r--video/mp_image.c43
-rw-r--r--video/mp_image.h6
-rw-r--r--video/out/aspect.c8
-rw-r--r--video/out/vo.c3
-rw-r--r--video/out/vo_drm.c4
-rw-r--r--video/out/vo_lavc.c9
-rw-r--r--video/out/vo_wayland.c4
-rw-r--r--video/out/vo_x11.c4
-rw-r--r--video/out/win_state.c6
-rw-r--r--video/sws_utils.c4
-rw-r--r--video/vdpau.c4
37 files changed, 154 insertions, 215 deletions
diff --git a/DOCS/man/vf.rst b/DOCS/man/vf.rst
index ff42608d81..b8d10f4683 100644
--- a/DOCS/man/vf.rst
+++ b/DOCS/man/vf.rst
@@ -151,15 +151,15 @@ Available filters are:
:yes: Enable accurate rounding.
``dsize[=w:h:aspect-method:r:aspect]``
- Changes the intended display size/aspect at an arbitrary point in the
+ Changes the intended display aspect at an arbitrary point in the
filter chain. Aspect can be given as a fraction (4/3) or floating point
- number (1.33). Alternatively, you may specify the exact display width and
- height desired. Note that this filter does *not* do any scaling itself; it
+ number (1.33). Note that this filter does *not* do any scaling itself; it
just affects what later scalers (software or hardware) will do when
auto-scaling to the correct aspect.
``<w>,<h>``
- New display width and height.
+ New aspect ratio given by a display width and height. Unlike older mpv
+ versions or MPlayer, this does not set the display size.
Can also be these special values:
diff --git a/demux/demux_disc.c b/demux/demux_disc.c
index b994b3cf11..4c27393f5c 100644
--- a/demux/demux_disc.c
+++ b/demux/demux_disc.c
@@ -147,7 +147,10 @@ static void add_streams(demuxer_t *demuxer)
double ar;
if (stream_control(demuxer->stream, STREAM_CTRL_GET_ASPECT_RATIO, &ar)
== STREAM_OK)
- sh->video->aspect = ar;
+ {
+ sh->video->par_w = 1728 * ar; // being lazy here
+ sh->video->par_h = 1728 / ar;
+ }
}
if (src->audio)
sh->audio = src->audio;
diff --git a/demux/demux_lavf.c b/demux/demux_lavf.c
index 0eb93b6e91..ea66ded09b 100644
--- a/demux/demux_lavf.c
+++ b/demux/demux_lavf.c
@@ -589,12 +589,8 @@ static void handle_stream(demuxer_t *demuxer, int i)
sh_video->fps = fps;
if (priv->format_hack.image_format)
sh_video->fps = demuxer->opts->mf_fps;
- if (st->sample_aspect_ratio.num)
- sh_video->aspect = codec->width * st->sample_aspect_ratio.num
- / (float)(codec->height * st->sample_aspect_ratio.den);
- else
- sh_video->aspect = codec->width * codec->sample_aspect_ratio.num
- / (float)(codec->height * codec->sample_aspect_ratio.den);
+ sh_video->par_w = st->sample_aspect_ratio.num;
+ sh_video->par_h = st->sample_aspect_ratio.den;
uint8_t *sd = av_stream_get_side_data(st, AV_PKT_DATA_DISPLAYMATRIX, NULL);
if (sd) {
diff --git a/demux/demux_mkv.c b/demux/demux_mkv.c
index a11691b317..562bddbfc6 100644
--- a/demux/demux_mkv.c
+++ b/demux/demux_mkv.c
@@ -48,6 +48,7 @@
#include "misc/bstr.h"
#include "stream/stream.h"
#include "video/csputils.h"
+#include "video/mp_image.h"
#include "demux.h"
#include "stheader.h"
#include "ebml.h"
@@ -1367,10 +1368,14 @@ static int demux_mkv_open_video(demuxer_t *demuxer, mkv_track_t *track)
sh_v->fps = track->v_frate;
sh_v->disp_w = track->v_width;
sh_v->disp_h = track->v_height;
- uint32_t dw = track->v_dwidth_set ? track->v_dwidth : track->v_width;
- uint32_t dh = track->v_dheight_set ? track->v_dheight : track->v_height;
- sh_v->aspect = (dw && dh) ? (double) dw / dh : 0;
- MP_VERBOSE(demuxer, "Aspect: %f\n", sh_v->aspect);
+
+ int dw = track->v_dwidth_set ? track->v_dwidth : track->v_width;
+ int dh = track->v_dheight_set ? track->v_dheight : track->v_height;
+ struct mp_image_params p = {.w = track->v_width, .h = track->v_height};
+ mp_image_params_set_dsize(&p, dw, dh);
+ sh_v->par_w = p.p_w;
+ sh_v->par_h = p.p_h;
+
sh_v->stereo_mode = track->stereo_mode;
return 0;
diff --git a/demux/stheader.h b/demux/stheader.h
index 7a11832c24..e325b52bf1 100644
--- a/demux/stheader.h
+++ b/demux/stheader.h
@@ -83,7 +83,7 @@ typedef struct sh_audio {
typedef struct sh_video {
bool avi_dts; // use DTS timing; first frame and DTS is 0
float fps; // frames per second (set only if constant fps)
- float aspect; // aspect ratio stored in the file (for prescaling)
+ int par_w, par_h; // pixel aspect ratio (0 if unknown/square)
int bits_per_coded_sample;
int disp_w, disp_h; // display size
int rotate; // intended display rotation, in degrees, [0, 359]
diff --git a/player/command.c b/player/command.c
index cc30d2b21a..ecae0df1a9 100644
--- a/player/command.c
+++ b/player/command.c
@@ -2449,8 +2449,8 @@ static int property_imgparams(struct mp_image_params p, int action, void *arg)
if (!p.imgfmt)
return M_PROPERTY_UNAVAILABLE;
- double dar = p.d_w / (double)p.d_h;
- double sar = p.w / (double)p.h;
+ int d_w, d_h;
+ mp_image_params_get_dsize(&p, &d_w, &d_h);
struct mp_imgfmt_desc desc = mp_imgfmt_get_desc(p.imgfmt);
int bpp = 0;
@@ -2465,10 +2465,10 @@ static int property_imgparams(struct mp_image_params p, int action, void *arg)
.unavailable = !(desc.flags & MP_IMGFLAG_PLANAR)},
{"w", SUB_PROP_INT(p.w)},
{"h", SUB_PROP_INT(p.h)},
- {"dw", SUB_PROP_INT(p.d_w)},
- {"dh", SUB_PROP_INT(p.d_h)},
- {"aspect", SUB_PROP_FLOAT(dar)},
- {"par", SUB_PROP_FLOAT(dar / sar)},
+ {"dw", SUB_PROP_INT(d_w)},
+ {"dh", SUB_PROP_INT(d_h)},
+ {"aspect", SUB_PROP_FLOAT(d_w / (double)d_h)},
+ {"par", SUB_PROP_FLOAT(p.p_w / (double)p.p_h)},
{"colormatrix",
SUB_PROP_STR(m_opt_choice_str(mp_csp_names, p.colorspace))},
{"colorlevels",
@@ -2561,8 +2561,8 @@ static int mp_property_window_scale(void *ctx, struct m_property *prop,
return M_PROPERTY_UNAVAILABLE;
struct mp_image_params params = get_video_out_params(mpctx);
- int vid_w = params.d_w;
- int vid_h = params.d_h;
+ int vid_w, vid_h;
+ mp_image_params_get_dsize(&params, &vid_w, &vid_h);
if (vid_w < 1 || vid_h < 1)
return M_PROPERTY_UNAVAILABLE;
@@ -2781,8 +2781,10 @@ static int mp_property_aspect(void *ctx, struct m_property *prop,
struct dec_video *d_video = mpctx->d_video;
struct sh_video *sh_video = d_video->header->video;
struct mp_image_params *params = &d_video->vfilter->override_params;
- if (params && params->d_w && params->d_h) {
- aspect = (float)params->d_w / params->d_h;
+ if (params && params->p_w > 0 && params->p_h > 0) {
+ int d_w, d_h;
+ mp_image_params_get_dsize(params, &d_w, &d_h);
+ aspect = (float)d_w / d_h;
} else if (sh_video->disp_w && sh_video->disp_h) {
aspect = (float)sh_video->disp_w / sh_video->disp_h;
}
diff --git a/player/playloop.c b/player/playloop.c
index 5efb048cb2..892baf1a09 100644
--- a/player/playloop.c
+++ b/player/playloop.c
@@ -889,7 +889,7 @@ int handle_force_window(struct MPContext *mpctx, bool force)
struct mp_image_params p = {
.imgfmt = config_format,
.w = w, .h = h,
- .d_w = w, .d_h = h,
+ .p_w = 1, .p_h = 1,
};
if (vo_reconfig(vo, &p) < 0)
goto err;
diff --git a/player/screenshot.c b/player/screenshot.c
index 9c4f5cc84e..76c7874498 100644
--- a/player/screenshot.c
+++ b/player/screenshot.c
@@ -308,14 +308,7 @@ static char *gen_fname(screenshot_ctx *ctx, const char *file_ext)
static void add_subs(struct MPContext *mpctx, struct mp_image *image)
{
- double sar = (double)image->w / image->h;
- double dar = (double)image->params.d_w / image->params.d_h;
- struct mp_osd_res res = {
- .w = image->w,
- .h = image->h,
- .display_par = sar / dar,
- };
-
+ struct mp_osd_res res = osd_res_from_image_params(&image->params);
osd_draw_on_image(mpctx->osd, res, mpctx->video_pts,
OSD_DRAW_SUB_ONLY, image);
}
diff --git a/player/video.c b/player/video.c
index 9be4f6a9a0..1178557e24 100644
--- a/player/video.c
+++ b/player/video.c
@@ -1186,8 +1186,11 @@ void write_video(struct MPContext *mpctx, double endpts)
const struct vo_driver *info = mpctx->video_out->driver;
char extra[20] = {0};
- if (p.w != p.d_w || p.h != p.d_h)
- snprintf(extra, sizeof(extra), " => %dx%d", p.d_w, p.d_h);
+ if (p.p_w != p.p_h) {
+ int d_w, d_h;
+ mp_image_params_get_dsize(&p, &d_w, &d_h);
+ snprintf(extra, sizeof(extra), " => %dx%d", d_w, d_h);
+ }
MP_INFO(mpctx, "VO: [%s] %dx%d%s %s\n",
info->name, p.w, p.h, extra, vo_format_name(p.imgfmt));
MP_VERBOSE(mpctx, "VO: Description: %s\n", info->description);
diff --git a/sub/osd.c b/sub/osd.c
index 2d11b80cbb..ba4011c040 100644
--- a/sub/osd.c
+++ b/sub/osd.c
@@ -388,13 +388,10 @@ void osd_draw_on_image_p(struct osd_state *osd, struct mp_osd_res res,
// ratio if the image does not have a 1:1 pixel aspect ratio.
struct mp_osd_res osd_res_from_image_params(const struct mp_image_params *p)
{
- double sar = (double)p->w / p->h;
- double dar = (double)p->d_w / p->d_h;
-
return (struct mp_osd_res) {
.w = p->w,
.h = p->h,
- .display_par = sar / dar,
+ .display_par = p->p_h / (double)p->p_w,
};
}
diff --git a/sub/sd_ass.c b/sub/sd_ass.c
index baf35b5d30..32179c843d 100644
--- a/sub/sd_ass.c
+++ b/sub/sd_ass.c
@@ -343,11 +343,9 @@ static void get_bitmaps(struct sd *sd, struct mp_osd_res dim, double pts,
opts->ass_vsfilter_aspect_compat))
{
// Let's use the original video PAR for vsfilter compatibility:
- double par = scale
- * (ctx->video_params.d_w / (double)ctx->video_params.d_h)
- / (ctx->video_params.w / (double)ctx->video_params.h);
+ double par = ctx->video_params.p_w / (double)ctx->video_params.p_h;
if (isnormal(par))
- scale = par;
+ scale *= par;
}
configure_ass(sd, &dim, converted, track);
ass_set_pixel_aspect(renderer, scale);
diff --git a/sub/sd_lavc.c b/sub/sd_lavc.c
index 08fff28d8a..86aaf4fda9 100644
--- a/sub/sd_lavc.c
+++ b/sub/sd_lavc.c
@@ -318,11 +318,10 @@ static void get_bitmaps(struct sd *sd, struct mp_osd_res d, double pts,
double video_par = 0;
if (priv->avctx->codec_id == AV_CODEC_ID_DVD_SUBTITLE &&
- opts->stretch_dvd_subs) {
+ opts->stretch_dvd_subs)
+ {
// For DVD subs, try to keep the subtitle PAR at display PAR.
- double par =
- (priv->video_params.d_w / (double)priv->video_params.d_h)
- / (priv->video_params.w / (double)priv->video_params.h);
+ double par = priv->video_params.p_w / (double)priv->video_params.p_h;
if (isnormal(par))
video_par = par;
}
diff --git a/video/decode/dec_video.c b/video/decode/dec_video.c
index 509daf7cd8..9409ce146f 100644
--- a/video/decode/dec_video.c
+++ b/video/decode/dec_video.c
@@ -15,14 +15,15 @@
* with mpv. If not, see <http://www.gnu.org/licenses/>.
*/
-#include "config.h"
-#include "options/options.h"
-
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <assert.h>
+#include <libavutil/rational.h>
+
+#include "config.h"
+#include "options/options.h"
#include "common/msg.h"
#include "osdep/timer.h"
@@ -342,7 +343,7 @@ int video_reconfig_filters(struct dec_video *d_video,
// While mp_image_params normally always have to have d_w/d_h set, the
// decoder signals unknown bitstream aspect ratio with both set to 0.
- float dec_aspect = p.d_w > 0 && p.d_h > 0 ? p.d_w / (float)p.d_h : 0;
+ float dec_aspect = p.p_w > 0 && p.p_h > 0 ? p.p_w / (float)p.p_h : 0;
if (d_video->initial_decoder_aspect == 0)
d_video->initial_decoder_aspect = dec_aspect;
@@ -363,22 +364,25 @@ int video_reconfig_filters(struct dec_video *d_video,
break;
}
- if (use_container && sh->aspect > 0) {
+ if (use_container && sh->par_w > 0 && sh->par_h) {
MP_VERBOSE(d_video, "Using container aspect ratio.\n");
- vf_set_dar(&p.d_w, &p.d_h, p.w, p.h, sh->aspect);
+ p.p_w = sh->par_w;
+ p.p_h = sh->par_h;
}
- float force_aspect = opts->movie_aspect;
- if (force_aspect >= 0.0) {
+ if (opts->movie_aspect >= 0) {
MP_VERBOSE(d_video, "Forcing user-set aspect ratio.\n");
- vf_set_dar(&p.d_w, &p.d_h, p.w, p.h, force_aspect);
+ if (opts->movie_aspect == 0) {
+ p.p_w = p.p_h = 1;
+ } else {
+ AVRational a = av_d2q(opts->movie_aspect, INT_MAX);
+ mp_image_params_set_dsize(&p, a.num, a.den);
+ }
}
// Assume square pixels if no aspect ratio is set at all.
- if (p.d_w <= 0 || p.d_h <= 0) {
- p.d_w = p.w;
- p.d_h = p.h;
- }
+ if (p.p_w <= 0 || p.p_h <= 0)
+ p.p_w = p.p_h = 1;
// Detect colorspace from resolution.
mp_image_params_guess_csp(&p);
diff --git a/video/decode/vd_lavc.c b/video/decode/vd_lavc.c
index 92ea8bd0d8..89fa21c4e1 100644
--- a/video/decode/vd_lavc.c
+++ b/video/decode/vd_lavc.c
@@ -484,7 +484,6 @@ static void update_image_params(struct dec_video *vd, AVFrame *frame,
struct MPOpts *opts = ctx->opts;
int width = frame->width;
int height = frame->height;
- float aspect = av_q2d(frame->sample_aspect_ratio) * width / height;
int pix_fmt = frame->format;
if (pix_fmt != ctx->pix_fmt) {
@@ -499,8 +498,8 @@ static void update_image_params(struct dec_video *vd, AVFrame *frame,
.imgfmt = ctx->best_csp,
.w = width,
.h = height,
- .d_w = 0,
- .d_h = 0,
+ .p_w = frame->sample_aspect_ratio.num,
+ .p_h = frame->sample_aspect_ratio.den,
.colorspace = avcol_spc_to_mp_csp(ctx->avctx->colorspace),
.colorlevels = avcol_range_to_mp_csp_levels(ctx->avctx->color_range),
.primaries = avcol_pri_to_mp_csp_prim(ctx->avctx->color_primaries),
@@ -511,9 +510,6 @@ static void update_image_params(struct dec_video *vd, AVFrame *frame,
.stereo_in = vd->header->video->stereo_mode,
};
- if (aspect > 0)
- vf_set_dar(&out_params->d_w, &out_params->d_h, width, height, aspect);
-
if (opts->video_rotate < 0) {
out_params->rotate = 0;
} else {
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 -