summaryrefslogtreecommitdiffstats
path: root/demux
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 /demux
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 'demux')
-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
4 files changed, 16 insertions, 12 deletions
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]