mirror of
https://github.com/mpv-player/mpv.git
synced 2025-12-26 04:40:20 +00:00
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.
This commit is contained in:
@@ -110,7 +110,6 @@ typedef struct mkv_track {
|
|||||||
int stereo_mode;
|
int stereo_mode;
|
||||||
struct mp_colorspace color;
|
struct mp_colorspace color;
|
||||||
uint32_t v_crop_top, v_crop_left, v_crop_right, v_crop_bottom;
|
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;
|
float v_projection_pose_roll;
|
||||||
bool v_projection_pose_roll_set;
|
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) {
|
if (video->n_pixel_crop_top) {
|
||||||
track->v_crop_top = video->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);
|
MP_DBG(demuxer, "| + Crop top: %"PRIu32"\n", track->v_crop_top);
|
||||||
}
|
}
|
||||||
if (video->n_pixel_crop_left) {
|
if (video->n_pixel_crop_left) {
|
||||||
track->v_crop_left = video->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);
|
MP_DBG(demuxer, "| + Crop left: %"PRIu32"\n", track->v_crop_left);
|
||||||
}
|
}
|
||||||
if (video->n_pixel_crop_right) {
|
if (video->n_pixel_crop_right) {
|
||||||
track->v_crop_right = video->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);
|
MP_DBG(demuxer, "| + Crop right: %"PRIu32"\n", track->v_crop_right);
|
||||||
}
|
}
|
||||||
if (video->n_pixel_crop_bottom) {
|
if (video->n_pixel_crop_bottom) {
|
||||||
track->v_crop_bottom = video->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);
|
MP_DBG(demuxer, "| + Crop bottom: %"PRIu32"\n", track->v_crop_bottom);
|
||||||
}
|
}
|
||||||
if (video->n_colour)
|
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_w = track->v_width;
|
||||||
sh_v->disp_h = track->v_height;
|
sh_v->disp_h = track->v_height;
|
||||||
|
|
||||||
sh_v->crop.x0 = track->v_crop_left_set ? track->v_crop_left : 0;
|
struct mp_rect crop;
|
||||||
sh_v->crop.y0 = track->v_crop_top_set ? track->v_crop_top : 0;
|
crop.x0 = track->v_crop_left;
|
||||||
sh_v->crop.x1 = track->v_width -
|
crop.y0 = track->v_crop_top;
|
||||||
(track->v_crop_right_set ? track->v_crop_right : 0);
|
crop.x1 = track->v_width - track->v_crop_right;
|
||||||
sh_v->crop.y1 = track->v_height -
|
crop.y1 = track->v_height - track->v_crop_bottom;
|
||||||
(track->v_crop_bottom_set ? track->v_crop_bottom : 0);
|
|
||||||
|
|
||||||
int dw = track->v_dwidth_set ? track->v_dwidth : mp_rect_w(sh_v->crop);
|
// Keep the codec crop rect as 0s if we have no cropping since the
|
||||||
int dh = track->v_dheight_set ? track->v_dheight : mp_rect_h(sh_v->crop);
|
// file may have broken width/height tags.
|
||||||
struct mp_image_params p = {.w = mp_rect_w(sh_v->crop), .h = mp_rect_h(sh_v->crop)};
|
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);
|
mp_image_params_set_dsize(&p, dw, dh);
|
||||||
sh_v->par_w = p.p_w;
|
sh_v->par_w = p.p_w;
|
||||||
sh_v->par_h = p.p_h;
|
sh_v->par_h = p.p_h;
|
||||||
|
|||||||
Reference in New Issue
Block a user