bendavid / aiopylgtv

Library to control webOS based LG Tv devices
MIT License
147 stars 48 forks source link

Uploading 3DLUTs to B8 (Alpha7 2nd gen chipset) #1

Closed chros73 closed 5 years ago

chros73 commented 5 years ago

Hi!

First of all, thanks for your work! Let me know if you need any help with B8 (Alpha7 2nd gen chipset, 17 points cube).

bendavid commented 5 years ago

Implemented now in principle, but needs to be tested.

3D LUTs can be loaded from .cube files using upload_3d_lut_bt709_from_file(self, picMode, filename) or upload_3d_lut_bt2020_from_file(self, picMode, filename)

in principle it should autodetect the proper capabilities based on the TV model, so for the B8 you should indeed give it a 17 point cube file.

chros73 commented 5 years ago

Sounds amazing! Thank You for your work!

Have you tested these by yourself? :) Are we sure that it doesn't break our TV?

Can you create a file for usage with examples? (e. g. uploading SDR and HDR 3dluts) You can create a docs directory, and a Calibration file into it. Definitions are also welcome in it, since I don't know anything about LG TV calibration.

Thank you!

bendavid commented 5 years ago

I have tested this extensively with the C8, but not at all with any other models. I am reasonably sure there is no danger from any of the functions here, but as I have stated elsewhere, I did manage to outright brick my TV by uploading problematic Dolby Vision config data previously (and this is one of the reasons that functionality is not yet exposed in the library).

chros73 commented 5 years ago

Thanks for confirming this. I'll try to create a 3dlut for HDR mode (that is what I'm missing) with DisplayCal (following janos666 suggestion) then exporting it to Iridas 17 points cube and I'll be ready to try it out.

chros73 commented 5 years ago

I try to run ("install") the util on Windows (I can't compile python 3.8 on Ubuntu 14.04 for whatever reason). So, pip and python is working from command line, but when I fire up this command pip install aiopylgtv it says:

d:\Progs\aiopylgtv>pip3 install aiopylgtv
ERROR: Could not find a version that satisfies the requirement aiopylgtv (from versions: none)
ERROR: No matching distribution found for aiopylgtv
bendavid commented 5 years ago

The package is not released/uploaded yet, so you'll have to build it from source for the moment.

python setup.py sdist pip install dist/aiopylgtv-0.2.0b1.tar.gz

bendavid commented 5 years ago

(You can also try it in an earlier python version. It for sure needs at least python 3.5 though.)

chros73 commented 5 years ago

Thanks, that's good news, I can get 3.6 working. I'll take a look later.

chros73 commented 5 years ago

Thanks for the help, now 3.6 is fine and I have the command line util:

$ aiopylgtvcommand
usage: aiopylgtvcommand [-h] host command [parameters [parameters ...]]

What commands would you use to create and upload a 3dlut to hdr_technicolorExpert HDR10 preset? And I do not want to deal with 1dlut for this preset.

Thanks

bendavid commented 5 years ago

You can just do

aiopylgtvcommand <hostname> start_calibration hdr_technicolorExpert
aiopylgtvcommand <hostname> upload_3d_lut_bt2020_from_file hdr_technicolorExpert "test3d.cube"
aiopylgtvcommand <hostname> end_calibration hdr_technicolorExpert

The input file for lut upload can be produced from DisplayCal by selecting the IRIDAS(.cube) format, and 17x17x17 or 33x33x33 (17x17x17 for the B8 of course)

If you want to upload a unity 3d lut, you can do it without any file input by doing

aiopylgtvcommand <hostname> start_calibration hdr_technicolorExpert
aiopylgtvcommand <hostname> upload_3d_lut_bt2020 hdr_technicolorExpert
aiopylgtvcommand <hostname> end_calibration hdr_technicolorExpert
chros73 commented 5 years ago

Thanks, that helps a lot. More questions about creating only a 3dlut (not 1dlut) for HDR10 (with DisplayCal):

bendavid commented 5 years ago

ddc_reset WILL upload a unity 1dlut as well, and this IS a problem if you want to keep the factory 1dlut.

You don't need to do the ddc_reset though, calibration mode is enabled just with start_calibration (and this does not modify anything permanently).

So yes, you should start measuring patches after start_calibration in order to bypass the tone mapping. (but can skip ddc_reset entirely).

On the other hand, I have seen in SDR mode that start_calibration significantly changes the behaviour of the image processing without having done a ddc_reset, but that this is not the case after doing the ddc reset. In that case doing the patch measurement after start_calibration would invalidate the calibration. If the set behaves similarly in HDR10 mode this would suggest that it's preferable to use a unity or calibrated 1D LUT as well rather than the factory one (but I think this should be tried both ways and compared.)

Of course after uploading any 1D LUT you would need to do a factory reset in order to get back the factory one.

bendavid commented 5 years ago

Btw you can see here that ddc_reset doesn't do anything magic or special, it just sets brightness, contrast, oled light and color to defaults and uploads unity 1d and 3d luts. https://github.com/bendavid/aiopylgtv/blob/0ff7a63b50f0f6be73ac97670f4875fe6a0dcf3f/aiopylgtv/webos_client.py#L965-L972

chros73 commented 5 years ago

ddc_reset doesn't do anything magic or special

Yes, thanks, I saw that.

I have seen in SDR mode that start_calibration significantly changes the behaviour of the image processing without having done a ddc_reset

Since ddc_reset doesn't do anything special (only setting the factory values): maybe one of these settings weren't at its default when you tried that?

One more question about this: in "ddc_reset" oled light and contrast is default to 80 / 85. But HDR10 uses 100 / 100 for these by default. Isn't it an issue? (And DV mode uses 50 / 100 for 2018 models and 100/100 for 2019.)

bendavid commented 5 years ago

Ah yes, you're right, that's a mistake on my side, I'll implement a more dynamic lookup of default values in the next version.

chros73 commented 5 years ago

I got this error (websockets 8.1, asyncio 3.4.3, numpy 1.17.4 are installed in virtualenv by pip3):

$ aiopylgtvcommand 192.168.1.78 connect
Traceback (most recent call last):
  File "/home/chros/virtualenvs/venv_lg/bin/aiopylgtvcommand", line 8, in <module>
    sys.exit(aiopylgtvcommand())
  File "/home/chros/virtualenvs/venv_lg/lib/python3.6/site-packages/aiopylgtv/utils.py", line 23, in aiopylgtvcommand
    asyncio.get_event_loop().run_until_complete(runloop(client, args.command, args.parameters))
  File "/usr/lib/python3.6/asyncio/base_events.py", line 467, in run_until_complete
    return future.result()
  File "/home/chros/virtualenvs/venv_lg/lib/python3.6/site-packages/aiopylgtv/utils.py", line 6, in runloop
    await client.connect()
  File "/home/chros/virtualenvs/venv_lg/lib/python3.6/site-packages/aiopylgtv/webos_client.py", line 118, in connect
    self.connect_task = asyncio.create_task(self.connect_handler(self.connect_result))
AttributeError: module 'asyncio' has no attribute 'create_task'
bendavid commented 5 years ago

You shouldn't explicitly call "connect" from the command line tool (connect and disconnect get called implicitly in this case)

But in any case it looks like the issue is python version compatibility.

chros73 commented 5 years ago

Hmm, so should I just start with this command and will it take care of pairing? (Same error as above)

aiopylgtvcommand 192.168.1.78 start_calibration hdr_technicolorExpert

I'll try out from windows with 3.8.

chros73 commented 5 years ago

aiopylgtvcommand 192.168.1.78 start_calibration hdr_technicolorExpert I'll try out from windows with 3.8.

Thanks, it works with 3.8 from Windows!

chros73 commented 5 years ago

Well, this one doesn't do anything, although it returns "yes": picture is the same and there was no toast message that calibration is ended.

aiopylgtvcommand 192.168.1.78 end_calibration technicolorExpert
{'returnValue': True}
bendavid commented 5 years ago

It should restore the tone mapping when you end the calibration assuming you're in hdr mode. In SDR indeed there should be no change (and in practice in the cases where there are it's subtle)

chros73 commented 5 years ago

Sorry, I'm only experimenting with SDR technicolorExpert preset:

bendavid commented 5 years ago

I don't believe there is supposed to be any visual feedback when ending the calibration.

chros73 commented 5 years ago

It seems, you are right: it worked in HDR (ending the session, it was a bigger difference in brightness).

chros73 commented 5 years ago

I generated and uploaded an Iridas 17x17x17 3dlut for HDR10 successfully :)

aiopylgtvcommand 192.168.1.78 start_calibration hdr_technicolorExpert
aiopylgtvcommand 192.168.1.78 upload_3d_lut_bt2020 hdr_technicolorExpert
aiopylgtvcommand 192.168.1.78 upload_3d_lut_bt2020_from_file hdr_technicolorExpert "b8bt2020g22p17t1.cube"
aiopylgtvcommand 192.168.1.78 end_calibration hdr_technicolorExpert

Used DisplayCal settings: capture_001_01122019_203628 capture_002_01122019_203639 capture_003_01122019_203644 capture_006_01122019_205550 capture_003_02122019_191500

bendavid commented 5 years ago

The third command should be rather

aiopylgtvcommand 192.168.1.78 upload_3d_lut_bt2020_from_file hdr_technicolorExpert "b8t1p17.cube"
chros73 commented 5 years ago

Oh, crap :) It was too late and I fought too much already with python :) Thanks, I'll try it out tonight. Btw janos666 pointed out that my 3dlut settings in DisplayCal are definitely wrong, I'll update that one as well.

I'll implement a more dynamic lookup of default values

No worries, thanks. And since we can run the uploading unity commands separately, probably it's a good idea to remove all the 3 of them from the "ddc_reset" method:

So I think just remove them from ddc_reset, and we have to document it.

And thanks for your work and your amazing support as well! :)

bendavid commented 5 years ago

Well if someone want to only partially reset things then they can just skip the ddc_reset and call the individual commands manually. It's just a convenience function, and I think the documentation is reasonably clear about what it does.

chros73 commented 5 years ago

Thanks, that command worked, I edited the above post :) So, it seems B8 works fine as well (although I haven't tried every command yet), so I close this issue.

chros73 commented 5 years ago

The new set_bt2020_3by3_gamut_data should not be be "BT709_3BY3_GAMUT_DATA", right? Or is it just for DV and not for HDR10?

bendavid commented 5 years ago

No indeed that's a copy-paste error on my part.

chros73 commented 5 years ago

The updated install from source documantion doesn't work (the old one does) in readme at least on Windows (with v3.8):

d:\Progs\aiopylgtv>python setup.py sdist bdist_wheel
usage: setup.py [global_opts] cmd1 [cmd1_opts] [cmd2 [cmd2_opts] ...]
   or: setup.py --help [cmd1 cmd2 ...]
   or: setup.py --help-commands
   or: setup.py cmd --help

error: invalid command 'bdist_wheel'

And hence this one doesn't work either (the old one does):

pip install --upgrade dist/aiopylgtv-0.2.1-py3-none-any.whl
bendavid commented 5 years ago

you need to have "wheel" installed

pip install wheel
chros73 commented 5 years ago

Yes, thanks, that's solved the problem. XYZLUT matrix WBRGB patch set: c8_hdr_test4_p5.zip XYZLUT p68 patch set for unity 1dlut + user 3dlut: c8_hdr_test2_p68.zip