mpv-player / mpv

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

Ability to get histogram data. #10974

Closed natural-harmonia-gropius closed 1 year ago

natural-harmonia-gropius commented 1 year ago

Expected behavior of the wanted feature

I'm using custom shaders for tone mapping. https://github.com/mpv-player/mpv/pull/10827 gives the ability to change parameters at runtime. I want to go further to get the exact luminance informations of frame to control the shoulderStrength.

This is the position I want it to work.

[hdr]
profile-cond=get("video-params/sig-peak") > 1
profile-restore=copy
target-trc=pq
target-prim=bt.2020
glsl-shader=~~/shaders/hdr-toys/utils/clip_both.glsl
glsl-shader=~~/shaders/hdr-toys/transfer-function/pq_to_l.glsl
glsl-shader=~~/shaders/hdr-toys/transfer-function/l_to_linear.glsl
glsl-shader=~~/shaders/hdr-toys/utils/exposure.glsl
glsl-shader=~~/shaders/hdr-toys/utils/crosstalk.glsl
glsl-shader=~~/shaders/hdr-toys/utils/chroma_correction_hsv.glsl
# get_histogram_data
glsl-shader=~~/shaders/hdr-toys/tone-mapping/piecewise.glsl    # use_histogram_data
glsl-shader=~~/shaders/hdr-toys/tone-mapping/heatmap.glsl
glsl-shader=~~/shaders/hdr-toys/utils/crosstalk_inverse.glsl
glsl-shader=~~/shaders/hdr-toys/gamut-mapping/bt2407_matrix.glsl
glsl-shader=~~/shaders/hdr-toys/transfer-function/linear_to_bt1886.glsl
haasn commented 1 year ago

At this point, why not just estimate the histogram in your own shader?

natural-harmonia-gropius commented 1 year ago

How to do it? Not familiar with glsl ......

I don't know how to port this to mpv shader https://www.shadertoy.com/view/3dBXRW

piecewise_dyna.glsl It works. But

haasn commented 1 year ago

Err, no, that's completely not the way to do it. You need to use a compute shader, have each work group compute a local histogram then write that (using atomic integer addition) to a shader storage buffer shared between all work groups. (This also needs to be initialized to 0 by an earlier pass)

And then you can evaluate its result, preferably also in a separate sub-pass done only once, and generate your LUT which you can sample from a later pass.