demux: add crop to mp_codec_params

This commit is contained in:
Kacper Michajłow 2023-09-01 22:26:05 +02:00 committed by Dudemanguy
parent 63ca12d7bc
commit c40b064e38
4 changed files with 35 additions and 0 deletions

View File

@ -2965,6 +2965,12 @@ Property list
``track-list/N/demux-w``, ``track-list/N/demux-h``
Video size hint as indicated by the container. (Not always accurate.)
``track-list/N/demux-crop-x``, ``track-list/N/demux-crop-y``
Crop offset of the source video frame.
``track-list/N/demux-crop-w``, ``track-list/N/demux-crop-h``
Video size after cropping.
``track-list/N/demux-channel-count``
Number of audio channels as indicated by the container. (Not always
accurate - in particular, the track could be decoded as a different
@ -3027,6 +3033,10 @@ Property list
"decoder-desc" MPV_FORMAT_STRING
"demux-w" MPV_FORMAT_INT64
"demux-h" MPV_FORMAT_INT64
"demux-crop-x" MPV_FORMAT_INT64
"demux-crop-y" MPV_FORMAT_INT64
"demux-crop-w" MPV_FORMAT_INT64
"demux-crop-h" MPV_FORMAT_INT64
"demux-channel-count" MPV_FORMAT_INT64
"demux-channels" MPV_FORMAT_STRING
"demux-samplerate" MPV_FORMAT_INT64

View File

@ -106,6 +106,7 @@ struct mp_codec_params {
int rotate; // intended display rotation, in degrees, [0, 359]
int stereo_mode; // mp_stereo3d_mode (0 if none/unknown)
struct mp_colorspace color; // colorspace info where available
struct mp_rect crop; // crop to be applied
// STREAM_VIDEO + STREAM_AUDIO
int bits_per_coded_sample;

View File

@ -593,6 +593,25 @@ static void fix_image_params(struct priv *p,
m.stereo3d = p->codec->stereo_mode;
if (!mp_rect_equals(&p->codec->crop, &(struct mp_rect){0})) {
struct mp_rect crop = p->codec->crop;
// Offset to respect existing decoder crop.
crop.x0 += m.crop.x0;
crop.x1 += m.crop.x0;
crop.y0 += m.crop.y0;
crop.y1 += m.crop.y0;
// Crop has to be inside existing image bounds.
if (mp_image_crop_valid(&(struct mp_image_params) {
.w = mp_rect_w(m.crop), .h = mp_rect_h(m.crop), .crop = crop }))
{
m.crop = crop;
} else {
MP_WARN(p, "Invalid container crop %dx%d+%d+%d for %dx%d image\n",
mp_rect_w(crop), mp_rect_h(crop), crop.x0, crop.y0,
mp_rect_w(m.crop), mp_rect_h(m.crop));
}
}
if (opts->video_rotate < 0) {
m.rotate = 0;
} else {

View File

@ -1959,6 +1959,7 @@ static int get_track_entry(int item, int action, void *arg, void *ctx)
}
}
bool has_crop = mp_rect_w(p.crop) > 0 && mp_rect_h(p.crop) > 0;
struct m_sub_property props[] = {
{"id", SUB_PROP_INT(track->user_tid)},
{"type", SUB_PROP_STR(stream_type_name(track->type)),
@ -1994,6 +1995,10 @@ static int get_track_entry(int item, int action, void *arg, void *ctx)
.unavailable = !p.codec},
{"demux-w", SUB_PROP_INT(p.disp_w), .unavailable = !p.disp_w},
{"demux-h", SUB_PROP_INT(p.disp_h), .unavailable = !p.disp_h},
{"demux-crop-x",SUB_PROP_INT(p.crop.x0), .unavailable = !has_crop},
{"demux-crop-y",SUB_PROP_INT(p.crop.y0), .unavailable = !has_crop},
{"demux-crop-w",SUB_PROP_INT(mp_rect_w(p.crop)), .unavailable = !has_crop},
{"demux-crop-h",SUB_PROP_INT(mp_rect_h(p.crop)), .unavailable = !has_crop},
{"demux-channel-count", SUB_PROP_INT(p.channels.num),
.unavailable = !p.channels.num},
{"demux-channels", SUB_PROP_STR(mp_chmap_to_str(&p.channels)),