From 112d2a2c500682003798ae60fc6cd0d5dabbe174 Mon Sep 17 00:00:00 2001 From: wm4 Date: Sat, 15 Aug 2020 12:04:35 +0200 Subject: command: export alpha type in format properties --- DOCS/man/input.rst | 7 +++++++ player/command.c | 11 +++++++++++ 2 files changed, 18 insertions(+) diff --git a/DOCS/man/input.rst b/DOCS/man/input.rst index 6c589e7521..6213eb29fb 100644 --- a/DOCS/man/input.rst +++ b/DOCS/man/input.rst @@ -2328,6 +2328,11 @@ Property list Source file stereo 3D mode. (See the ``format`` video filter's ``stereo-in`` option.) + ``video-params/alpha`` + Alpha type. If the format has no alpha channel, this will be unavailable + (but in future releases, it could change to ``no``). If alpha is + present, this is set to ``straight`` or ``premul``. + When querying the property with the client API using ``MPV_FORMAT_NODE``, or with Lua ``mp.get_property_native``, this will return a mpv_node with the following contents: @@ -2351,6 +2356,8 @@ Property list "chroma-location" MPV_FORMAT_STRING "rotate" MPV_FORMAT_INT64 "stereo-in" MPV_FORMAT_STRING + "average-bpp" MPV_FORMAT_INT64 + "alpha" MPV_FORMAT_STRING ``dwidth``, ``dheight`` Video display size. This is the video size after filters and aspect scaling diff --git a/player/command.c b/player/command.c index 1a20962c29..560b9d71e2 100644 --- a/player/command.c +++ b/player/command.c @@ -2175,6 +2175,13 @@ static int property_imgparams(struct mp_image_params p, int action, void *arg) for (int i = 0; i < desc.num_planes; i++) bpp += desc.bpp[i] >> (desc.xs[i] + desc.ys[i]); + // Alpha type is not supported by FFmpeg, so MP_ALPHA_AUTO may mean alpha + // is of an unknown type, or simply not present. Normalize to AUTO=no alpha. + if (!!(desc.flags & MP_IMGFLAG_ALPHA) != (p.alpha != MP_ALPHA_AUTO)) { + p.alpha = + (desc.flags & MP_IMGFLAG_ALPHA) ? MP_ALPHA_STRAIGHT : MP_ALPHA_AUTO; + } + struct m_sub_property props[] = { {"pixelformat", SUB_PROP_STR(mp_imgfmt_to_name(p.imgfmt))}, {"average-bpp", SUB_PROP_INT(bpp), @@ -2201,6 +2208,10 @@ static int property_imgparams(struct mp_image_params p, int action, void *arg) {"stereo-in", SUB_PROP_STR(m_opt_choice_str(mp_stereo3d_names, p.stereo3d))}, {"rotate", SUB_PROP_INT(p.rotate)}, + {"alpha", + SUB_PROP_STR(m_opt_choice_str(mp_alpha_names, p.alpha)), + // avoid using "auto" for "no", so just make it unavailable + .unavailable = p.alpha == MP_ALPHA_AUTO}, {0} }; -- cgit v1.2.3