mpv-player / mpv

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

Add support for pre-calculated 3D-LUTs #2711

Closed kkkrackpot closed 8 years ago

kkkrackpot commented 8 years ago

Hi!

Thanks for your work on MPV!

Is it possible to add support for .3dlut files, i.e. ready-made, pre-calculated 3D-LUTs (like this one https://dropmefiles.com/RV1mx )?

Regards, Alex

ghost commented 8 years ago

You should convert the LUT to an icc profile.

Other than this, I don't think anyone is interested in implementing this. (Could change if there's a volunteer.)

kkkrackpot commented 8 years ago

Hi!

"You should convert the LUT to an icc profile." -- not sure if 3dlut to icc is possible...

wontfix is a pity, especially because some other players already have 3D LUT support. I would volonteer, if I only could something more than a "hello, world". Sorry...

Anyway, mpv is pretty good even without it.

Regards, Alex

ghost commented 8 years ago

ICC profiles can contain 3D LUTs. (Most probably store a more efficient representation, but it should be possible.)

haasn commented 8 years ago

mpv uses 3DLUTS for colorimetry, not for special effects.

Colorimetry only requires a device profile. “Precomputing” an ICC profile would be redundant because mpv already computes it on the fly and caches the result.

If you want to use a 3DLUT for special effects (e.g. saturation), it would be better to use a shader.

kkkrackpot commented 8 years ago

@haasn A 3D-LUT from my link above was not computed "on the fly" from an ICC profile, it's a result of several hours of measurements with the device (Klein spectrophotometer with Calman soft, as far as I know). As far as I can understand, it maps every GPU's physically measured output color to correspondent TV's physically measured color. However, I must readily admit, that my knowledge of all those things is rather basic, if none. Actually, all that I can confidently tell is only that "other players" already support "this feature"...

Unfortunately, I don't know how "to use a shader" in this situation. But I've found a way that solves the problem a bit -- an FFMPEG filter: mpv -v --vf vdpaurb,lavfi=[lut3d=3dlut.cube] movie.mkv. The result (i.e. shifted colors) of applying a .cube 3D-LUT is definitely seen on screen. But unfortunately, FFMPEG doesn't work with .3dlut files.

haasn commented 8 years ago

What you are describing is a colorimetry situation, so you can safely ignore my comment about shaders and effects.

The 3DLUT mpv uses is different from the 3DLUT you have measured as you are describing it.

The basic idea is that there are two directions that mpv needs to transform colors: “video -> intermediate” and “intermediate -> display”. (Where “intermediate” describes an objective representation of color that is not dependent on the source or device)

Your measurements are for measuring the “intermediate -> display” response. This information gets stored in ICC profiles.

What mpv does on the fly is connect the “video -> intermediate” transformation with the “intermediate -> display” transformation and compute a combined 3DLUT of the entire operation (that is “video -> display”). (With some caveats that I won't go into here)

Your 3DLUT only describes the latter operation, so mpv can't use it directly. The correct place to store it would be in an ICC profile.

As mentioned, ICC profiles can (and often do) include 3DLUTs of measurement table like yours. Software like calman etc. should be able to output ICC profiles, so try and find an ICC export option in your software. If you can't find one, it would be a Calman bug. (Or you could use other third party tools like ArgyllCMS to get the job done)

kkkrackpot commented 8 years ago

@haasn Do you mean that MPV "on the fly" creates an "ICC device link" in the sense described below?

Video calibration typically involves trying to make your actual display device emulate an ideal video display, one which matches what your Video media was intended to be displayed on. An ICC device link embodies the machinery to do exactly this, to take device values in the target source colorspace and transform them into an actual output device colorspace. In the Video and Film industries a very similar, but less sophisticated means of doing this is to use 3DLuts, which come in a multitude of different format. ICC device links have the advantage of being a superset of 3dLuts, encapsulated in a standard file format. http://www.argyllcms.com/doc/Scenarios.html#TV1

haasn commented 8 years ago

In a sense, yes. What mpv does is “bake” the operation embedded within the .ICC profile into a 3DLUT for internal use, using an intermediate space of its own choice (BT.2020 with gamma 2.4 iirc).

(This way it doesn't matter whether the ICC profile was matrix-based, LUT-based, curve-based or otherwise - the way of using it inside mpv is consistent. Implementing a full, conformant implementation of ICC and all its various modes of operation is way outside the scope of mpv)