1
0
mirror of https://github.com/mpv-player/mpv synced 2024-12-27 01:22:30 +00:00

video: allow overriding container crop if it is present

Setting `--video-crop=0x0+0+0` applies full frame crop, ignoring the
container one. Setting --video-crop=0 disables manual crop and restores
container one if it is available.
This commit is contained in:
Kacper Michajłow 2023-09-01 12:24:13 +02:00 committed by Dudemanguy
parent ff7da2f5c0
commit 37d0deadd4
3 changed files with 21 additions and 10 deletions

View File

@ -1570,8 +1570,11 @@ Video
Crop the video by starting at the x, y offset for w, h pixels. The crop is
applied to the source video rectangle (before anamorphic stretch) by the VO.
A crop rectangle that is not within the video rectangle will be ignored.
This works with hwdec, unlike the equivalent 'lavfi-crop'. Setting the crop
to '0' disables it. When offset is omitted, the central area will be cropped.
This works with hwdec, unlike the equivalent 'lavfi-crop'. When offset is
omitted, the central area will be cropped. Setting the crop to empty one
``--video-crop=0x0+0+0`` overrides container crop and disables cropping.
Setting the crop to ``--video-crop=0`` disables manual cropping and restores
the container crop if it's specified.
``--video-zoom=<value>``
Adjust the video display scale factor by the given value. The parameter is

View File

@ -2332,8 +2332,12 @@ static struct mp_image_params get_video_out_params(struct MPContext *mpctx)
struct mp_image_params o_params = mpctx->vo_chain->filter->output_params;
if (mpctx->video_out) {
m_rect_apply(&o_params.crop, o_params.w, o_params.h,
&mpctx->video_out->opts->video_crop);
struct m_geometry *gm = &mpctx->video_out->opts->video_crop;
if (gm->xy_valid || (gm->wh_valid && (gm->w > 0 || gm->w_per > 0 ||
gm->h > 0 || gm->h_per > 0)))
{
m_rect_apply(&o_params.crop, o_params.w, o_params.h, gm);
}
}
return o_params;

View File

@ -1130,19 +1130,23 @@ void write_video(struct MPContext *mpctx)
// Filter output is different from VO input?
struct mp_image_params *p = &mpctx->next_frames[0]->params;
// Inject vo crop to notify and reconfig if needed
struct mp_rect rc;
m_rect_apply(&rc, p->w, p->h, &vo->opts->video_crop);
if (rc.x1 > 0 && rc.y1 > 0)
struct m_geometry *gm = &vo->opts->video_crop;
struct mp_rect rc = {0};
if (gm->xy_valid || (gm->wh_valid && (gm->w > 0 || gm->w_per > 0 ||
gm->h > 0 || gm->h_per > 0)))
{
m_rect_apply(&rc, p->w, p->h, gm);
}
if (rc.x1 > 0 && rc.y1 > 0) {
p->crop = rc;
if (!mp_image_crop_valid(p)) {
char *str = m_option_type_rect.print(NULL, &vo->opts->video_crop);
char *str = m_option_type_rect.print(NULL, gm);
MP_WARN(vo, "Ignoring invalid --video-crop=%s for %dx%d image\n",
str, p->w, p->h);
talloc_free(str);
if (vo->params) {
p->crop = vo->params->crop;
vo->opts->video_crop = (struct m_geometry){
*gm = (struct m_geometry){
.x = p->crop.x0,
.y = p->crop.y0,
.w = mp_rect_w(p->crop),
@ -1153,7 +1157,7 @@ void write_video(struct MPContext *mpctx)
}
if (!mp_image_crop_valid(p)) {
p->crop = (struct mp_rect){0};
vo->opts->video_crop = (struct m_geometry){0};
*gm = (struct m_geometry){0};
}
}
}