mpv-player / mpv

🎥 Command line video player
https://mpv.io
Other
28.69k stars 2.93k forks source link

add an argument to select chroma downscaler #13313

Closed gaitas13 closed 10 months ago

gaitas13 commented 10 months ago

The same way that for luma you can chose the upscaler (scale) and the downscale (dscale) , it would be nice if we got an argument to downscale chroma (cdscale) and cscale is keep for choosing the chroma upscaler

Expected behavior of the wanted feature

The chroma downscaler works as intended

Alternative behavior of the wanted feature

N/A

Log file

N/A

ghost commented 10 months ago

Chroma is not downscaled at any point during mpv's rendering unless you're using some kind of weird custom shader setup (Ex: a luma downscaler that goes below chroma resolution), so being able to choose a chroma downscaler doesn't make too much sense.

See: https://github.com/mpv-player/mpv/wiki/Video-output---shader-stage-diagram

Jules-A commented 10 months ago

Chroma is not downscaled at any point during mpv's rendering, so being able to choose a chroma downscaler doesn't make sense.

See: https://github.com/mpv-player/mpv/wiki/Video-output---shader-stage-diagram

I really don't get what happens when you play a video with a resolution >2x larger than output... It seems bugged to me... It says that's it's upscaling chroma even in that scenario: image

but even if you use a shader to increase Chroma res to 2x output it will still say it's upscaling chroma using built-in but really it shouldn't it be downscaling to match luma res?

llyyr commented 10 months ago

It says that's it's upscaling chroma even in that scenario:

If the video is 4:2:0 then it still needs to upscale chroma...

Jules-A commented 10 months ago

Oh whoops, my bad, I didn't play a frame, it updates to say downscaling in the OSD if you play: image

Turns out it uses the set downscaler, not the cscale.

If the video is 4:2:0 then it still needs to upscale chroma...

Ah right.

hooke007 commented 10 months ago

I never heard about any video playera would downscale the chroma.

Jules-A commented 10 months ago

I never heard about any video playera would downscale the chroma.

It's not like there's many players that do Chroma scaling without also scaling Luma though? EDIT: I meant scaling Chroma > video res.

hooke007 commented 10 months ago

I think you don't understand chroma downscale, right? I do not know why luma scaling is mentioned here.

Jules-A commented 10 months ago

I think you don't understand chroma downscale, right? I do not know why luma scaling is mentioned here.

Not really, chroma confuses the hell out of me. I think I get it now, for some reason I was thinking that if the output window was < half the source res, chroma could be downscaled first to match luma's output res.

hooke007 commented 10 months ago

chroma plane's size is always smaller than luma for common videos. Two planes need to be align first. There is no steps to downscale the chroma.

ghost commented 10 months ago

As I stated in my edit, this is possible with luma-only user shaders, as these can downscale the luma plane early in the rendering stages. If you're downscaling the luma to a resolution that is below the chroma plane, then the chroma plane has to be downscaled to align with the new reference plane resolution before it can be merged. So yes, it's technically possible to trigger a chroma downscale.

If you want a reliable way of triggering it (credit to a random kind stranger)

  1. Find a yuv444 video
  2. Use a luma downscaling shader such as this.
  3. Set your window scale to half of the native resolution

And you'll notice that chroma is being downscaled. Is there any actual use case for doing this on yuv444 videos? Not really. But yes, it's technically possible.

Without user shaders, mpv will always upscale the chroma plane to match the luma plane (assuming that the chroma is subsampled), merge them, then covert them to a single RGB plane. After this, the RGB image will be scaled to a target resolution. There's no way to scale the luma and chroma planes independently to meet a target resolution (and there's no reason to outside of performance reasons, as this will result in a quality reduction).

Jules-A commented 10 months ago

chroma plane's size is always smaller than luma for common videos. Two planes need to be align first. There is no steps to downscale the chroma.

Then what is going on here when I specifically scale the chroma to 2x output? https://github.com/mpv-player/mpv/issues/13313#issuecomment-1899313804

hooke007 commented 10 months ago

I do not see any chroma steps. The first line is merging planes. Then everything works on RGB plane.

Jules-A commented 10 months ago

I do not see any chroma steps. The first line is merging planes. Then everything works on RGB plane.

Don't you see 2 lots of downscaling steps? The usershader was meant to scale main but I specifically changed it to hook and save chroma only.

hooke007 commented 10 months ago

I have no idea what you actually did in the shader.

Jules-A commented 10 months ago

I have no idea what you actually did in the shader.

It's just the RGB version of the Ravu-Zoom-AR shader but with this:

//!DESC RAVU-Zoom-AR (rgb, r3)
//!HOOK CHROMA
//!BIND HOOKED
//!BIND ravu_zoom_lut3
//!BIND ravu_zoom_lut3_ar
//!WIDTH OUTPUT.w 2 *
//!HEIGHT OUTPUT.h 2 *
//!OFFSET ALIGN
hooke007 commented 10 months ago

I am not the expert of shader but I am sure you just mess up the hook... You'd better to check ravu chroma variant to know how to properly handle chroma plane.

Jules-A commented 10 months ago

I am not the expert of shader but I am sure you just mess up the hook...

You don't need to be an expert to copy and paste and try it yourself... I can assure you it works, though scaling 2x output is a lot worse than just scaling to output. PSNR, DSSIM, MAE (test image from: https://github.com/Artoriuz/artoriuz.github.io/tree/main/blog/images/mpv_upscaling/chroma)

1x Output: 41.2092, 0.129701, 169.436 (0.00258543) ![mpv-shot0001](https://github.com/mpv-player/mpv/assets/1760158/ef7a7e77-c33d-4827-be07-b472fab8a638)
2x Output: 40.8395, 0.129932, 179.417 (0.00273773) ![mpv-shot0002](https://github.com/mpv-player/mpv/assets/1760158/901e7340-d7bb-4dff-857a-5eeca152a108)
EwaLanczosSharp 40.4248, 0.130374, 182.356 (0.00278257) ![mpv-shot0003](https://github.com/mpv-player/mpv/assets/1760158/ebb579ef-1dd3-4153-84a3-23eae42d8221)
hooke007 commented 10 months ago

As I said, check those real chroma shaders to learn the proper codes to handle chroma plane.

hooke007 commented 10 months ago

You just mess up the chroma plane and tell me it became worse. Of course, how could it be better? You didn't know what chroma is hours ago...

Jules-A commented 10 months ago

You just mess up the chroma plane and tell me it became worse. Of course, how could it be better? You didn't know what chroma is hours ago...

Check the 1x OUTPUT, it's not worse, 2x is obviously worse than scaling just to output, it was a test to demonstrate that chroma downscaling is real and yet it still seems to be slightly better than ewaLanczosSharp imo.

hooke007 commented 10 months ago

It's not 1x 2x chroma... Jesus, you do not even know what you were doing.

hooke007 commented 10 months ago

So that is why I am saying "you do not even know what you were doing."

hooke007 commented 10 months ago

You didn't even add any codes to handle the pixels out of range. Jesus, I cannot believe why you are so convident on the field you do not understand.

Jules-A commented 10 months ago

You didn't even add any codes to handle the pixels out of range. Jesus, I cannot believe why you are so convident on the field you do not understand.

I figured the AR clamping was enough and even adding that code to it doesn't seem to improve results much and I couldn't spot any major visual changes. I'm not confident that it's correct but I am confident that it is at least improving the result, I'm not blind (the automated tests also seem to agree).

Besides, you are completely missing the point, I'm not trying to get a perfect chroma shader, it's just to test scaling chroma > luma to show that chroma downscaling is happening.

hooke007 commented 10 months ago

Besides, you are completely missing the point, I'm not trying to get a perfect chroma shader

The key of this issue should be: Is there any pratical and valueable use case for mpv to add an option dcsale? I do not see any useful msg from the comments before.

Artoriuz commented 10 months ago

My only input to this is that the behaviour of vo=gpu and vo=gpu-next are different. I'm typing this from memory and it could be entirely wrong, but I think vo=gpu-next uses your dscale filter to downscale chroma while vo=gpu uses what you have set in cscale.

As @dokur0chan mentioned this is only ever possible if you use a custom shader to downscale luma below chroma resolution, so in any case I don't think it matters.

NotMithical commented 10 months ago

Like everyone else has said I don't think there's any practical use for this, but I'm fairly certain you could specify the filter used for chroma downscaling with --libplacebo-opts-append=plane_downscaler=

Jules-A commented 10 months ago

Like everyone else has said I don't think there's any practical use for this, but I'm fairly certain you could specify the filter used for chroma downscaling with --libplacebo-opts-append=plane_downscaler=

Oh wow, the option already existed. I can confirm it works: image

Dudemanguy commented 10 months ago

Closing since said option does actually exist.