summaryrefslogtreecommitdiffstats
path: root/demux
diff options
context:
space:
mode:
authorDudemanguy <random342@airmail.cc>2023-10-19 16:05:19 -0500
committerDudemanguy <random342@airmail.cc>2023-10-21 16:37:03 +0000
commitdc2298f4da0aeea19868058e158bc4e27c0d8ebb (patch)
tree3116943e7ad5973e802eb79ebc7f1da1b3932303 /demux
parent9ea9279cf4fdfbe529a3146b33aaa51389338b2f (diff)
downloadmpv-dc2298f4da0aeea19868058e158bc4e27c0d8ebb.tar.bz2
mpv-dc2298f4da0aeea19868058e158bc4e27c0d8ebb.tar.xz
demux_mkv: don't set codec crop rect when there is no crop
Unfortunately there are files out there with broken tags where the width/height doesn't match the actual width/height of the file. That means the cropping logic which normally should be a no-op resulting in (0, 0, w, h) ends up being a crop which is probably not wanted by the user. Workaround this by simply keeping the entire crop rect as 0 when there is no container cropping. All zeros is internally treated the same as (0, 0, w, h) and avoids bad container data messing up the width or height of the window. Also simplify the logic a bit and get rid of some superflorous bools that had no real use. Fixes #12680.
Diffstat (limited to 'demux')
-rw-r--r--demux/demux_mkv.c30
1 files changed, 16 insertions, 14 deletions
diff --git a/demux/demux_mkv.c b/demux/demux_mkv.c
index 6f5600b7f1..7f2220f552 100644
--- a/demux/demux_mkv.c
+++ b/demux/demux_mkv.c
@@ -110,7 +110,6 @@ typedef struct mkv_track {
int stereo_mode;
struct mp_colorspace color;
uint32_t v_crop_top, v_crop_left, v_crop_right, v_crop_bottom;
- bool v_crop_top_set, v_crop_left_set, v_crop_right_set, v_crop_bottom_set;
float v_projection_pose_roll;
bool v_projection_pose_roll_set;
@@ -663,22 +662,18 @@ static void parse_trackvideo(struct demuxer *demuxer, struct mkv_track *track,
}
if (video->n_pixel_crop_top) {
track->v_crop_top = video->pixel_crop_top;
- track->v_crop_top_set = true;
MP_DBG(demuxer, "| + Crop top: %"PRIu32"\n", track->v_crop_top);
}
if (video->n_pixel_crop_left) {
track->v_crop_left = video->pixel_crop_left;
- track->v_crop_left_set = true;
MP_DBG(demuxer, "| + Crop left: %"PRIu32"\n", track->v_crop_left);
}
if (video->n_pixel_crop_right) {
track->v_crop_right = video->pixel_crop_right;
- track->v_crop_right_set = true;
MP_DBG(demuxer, "| + Crop right: %"PRIu32"\n", track->v_crop_right);
}
if (video->n_pixel_crop_bottom) {
track->v_crop_bottom = video->pixel_crop_bottom;
- track->v_crop_bottom_set = true;
MP_DBG(demuxer, "| + Crop bottom: %"PRIu32"\n", track->v_crop_bottom);
}
if (video->n_colour)
@@ -1510,16 +1505,23 @@ static int demux_mkv_open_video(demuxer_t *demuxer, mkv_track_t *track)
sh_v->disp_w = track->v_width;
sh_v->disp_h = track->v_height;
- sh_v->crop.x0 = track->v_crop_left_set ? track->v_crop_left : 0;
- sh_v->crop.y0 = track->v_crop_top_set ? track->v_crop_top : 0;
- sh_v->crop.x1 = track->v_width -
- (track->v_crop_right_set ? track->v_crop_right : 0);
- sh_v->crop.y1 = track->v_height -
- (track->v_crop_bottom_set ? track->v_crop_bottom : 0);
+ struct mp_rect crop;
+ crop.x0 = track->v_crop_left;
+ crop.y0 = track->v_crop_top;
+ crop.x1 = track->v_width - track->v_crop_right;
+ crop.y1 = track->v_height - track->v_crop_bottom;
- int dw = track->v_dwidth_set ? track->v_dwidth : mp_rect_w(sh_v->crop);
- int dh = track->v_dheight_set ? track->v_dheight : mp_rect_h(sh_v->crop);
- struct mp_image_params p = {.w = mp_rect_w(sh_v->crop), .h = mp_rect_h(sh_v->crop)};
+ // Keep the codec crop rect as 0s if we have no cropping since the
+ // file may have broken width/height tags.
+ if (track->v_crop_left || track->v_crop_top ||
+ track->v_crop_right || track->v_crop_bottom)
+ {
+ sh_v->crop = crop;
+ }
+
+ int dw = track->v_dwidth_set ? track->v_dwidth : mp_rect_w(crop);
+ int dh = track->v_dheight_set ? track->v_dheight : mp_rect_h(crop);
+ struct mp_image_params p = {.w = mp_rect_w(crop), .h = mp_rect_h(crop)};
mp_image_params_set_dsize(&p, dw, dh);
sh_v->par_w = p.p_w;
sh_v->par_h = p.p_h;