summaryrefslogtreecommitdiffstats
path: root/video/decode
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/decode
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/decode')
-rw-r--r--video/decode/dec_video.c30
-rw-r--r--video/decode/vd_lavc.c8
2 files changed, 19 insertions, 19 deletions
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 {