Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New LUT calibration based on mp4 test videos (part I) #896

Merged
merged 74 commits into from
Nov 8, 2024

Conversation

awawa-dev
Copy link
Owner

@awawa-dev awawa-dev commented Jul 7, 2024

I don't know what the final effect will be, but since AI is currently very popular ;) Let's use Deep Learning Function Approximation to calibrate SDR/HDR/whatever video source. We will use Python and its related libraries here but it is an optional functionality and you do not have to use it nor will we install it: it must be present in the system.
But first, let's sort out the calibrator code because it needs cleaning before further work. We will use a new library for linear algebra that will help us.


Main changes (non-AI):

  • Old method using Windows 10 and a web browser is no longer mandatory, you can use the old method using browser or simply play the video test file in your favorite video player.

  • New algos that support even video source trans-coded to full BT2020 range and provide better quality

  • Captured colors are saved in the HyperHDR directory after calibration as calibration_captured_yuv.txt and can be provided to me for analysis if I have some spare time.

  • Support only for YUV/NV12/MJPEG modes. RGB mode is not supported anymore.

  • Confirmed support for webos calibration with backend that supports NV12 flatbuffers communication. Each webos mode (SDR/HDR/DV) may require its own calibration.

  • Grabber benchmark supports flatbuffers source

  • Video source noise detection

  • multi-threading support for calibration and LUT creation. But what we gained by using all cores went to...

  • LCH color corrector. Jokes aside, this algorithm eats up huge amounts of CPU resources, but I think the effect is worth it because we get clean main colors and I didn't notice any side effects. If anything, you can disable it. More at the end.

  • Increased the number of test vertices focusing on the most problematic issues: yellow (green shift) and magenta (red shift).

  • USB grabber and flatbuffer server are disabled during calibration to save resources. We enable them at the end. Known issue: there is some issue on the webos client side that does not detect that the connection has been lost and does not reconnect it later. You have to manually restart the piccap service.

  • Added PQ in sRGB linear signal detection for AV access grabber. You can see in the first post what this grabber is capable of due to its wide range, it avoids quantization characteristic of all other grabbers.

  • Added 2-step calibration which allowed to speed up the whole process. The first step is general and is only intended to detect the appropriate tactic. The second step is detailed.

  • Moved calibration to a separate thread. Thanks to this we do not block the interface which now displays information about the progress on an ongoing basis.

  • Change some backlight behavior: only turn on the background light if the LED would otherwise be off.

  • If calibrating using Windows (using the web browser or the video player as a video source) please disable features like 'Night mode' or 'Auto-HDR'. Do not change the color balance in your graphic driver.


Video test files:
https://github.com/awawa-dev/awawa-dev.github.io/tree/master/calibration
Use SDR video only if your OS or video player will automatically apply SDR to HDR tone mapping. Or if you are calibrating eg. webos.

The web browser method and playing yuv444 file usually provides the best calibration quality but yuv444 is supported probably only by the PC players. yuv420 has better compatibility but worse quality (the risk the player is starting using its own filters like dithering).


Presenting capabilities of new tone mapping algos:

Source desktop (Windows 11 HDR enabled):
source

AV Access 4KVC00 (this wide-range grabber was ahead of its time + HDR/SDR detection on the COM port 👍 )

Captured by MS2130 (F3 firmware !!!) with and without tone mapping:

@awawa-dev
Copy link
Owner Author

There is a verification procedure for SDR: #1000 (comment)

@awawa-dev
Copy link
Owner Author

awawa-dev commented Dec 9, 2024

[FLATBUFSERVER] (LutLoader.cpp:74) Index 2 for YUV

This indicates that you have disabled tone mapping in flatbutffers configuration if Index does not switch to 1 when you enable tone mapping.

@satgit62
Copy link

satgit62 commented Dec 9, 2024

@NatyaSadella
Copy link

@satgit62 Thank you but I'm not really sure if I should do that. I need a way to have different LED gamma values at different picture modes and if HyperHDR is in HDR-always-on mode that wouldn't work anymore

sundermann added a commit to sundermann/hyperion-webos that referenced this pull request Dec 9, 2024
@NatyaSadella
Copy link

@satgit62
Sorry that I have to dig up the old thread again. I just updated to PicCap 0.5.0 and am now a bit confused about the HDR-Always-On feature they mention in changelogs. When I play an SDR video, the HDR switch on the remote tab stays off like on version 0.4.3. Is this intentional? To me, it doesn't look like it's working.

@satgit62
Copy link

@satgit62 Sorry that I have to dig up the old thread again. I just updated to PicCap 0.5.0 and am now a bit confused about the HDR-Always-On feature they mention in changelogs. When I play an SDR video, the HDR switch on the remote tab stays off like on version 0.4.3. Is this intentional? To me, it doesn't look like it's working.

Hello, disconnect the TV from the mains for a minute and check after the restart whether everything works as usual. Everything works as it should for us.
I don't use the HDR-Always-On option with multiple LUT's, because now when using NV12 with multiple LUT's the HDR Global stays on even with SDR content. See: https://github.com/satgit62/Ultimate-HyperHDR-Ambilight-fine-tuning-experience-for-LG-webOS-with-new-LUT-calibration-

@NatyaSadella
Copy link

@satgit62 Sorry that I have to dig up the old thread again. I just updated to PicCap 0.5.0 and am now a bit confused about the HDR-Always-On feature they mention in changelogs. When I play an SDR video, the HDR switch on the remote tab stays off like on version 0.4.3. Is this intentional? To me, it doesn't look like it's working.

Hello, disconnect the TV from the mains for a minute and check after the restart whether everything works as usual. Everything works as it should for us.

I don't use the HDR-Always-On option with multiple LUT's, because now when using NV12 with multiple LUT's the HDR Global stays on even with SDR content. See: https://github.com/satgit62/Ultimate-HyperHDR-Ambilight-fine-tuning-experience-for-LG-webOS-with-new-LUT-calibration-

No changes after restart. HDR toggle stays off in SDR mode.

"I don't use the HDR-Always-On option"

I thought this is always enabled now? where is the toggle for this in PicCap? Are you talking about the "Disable SDR/HDR switch" in advanced settings?

Because I'm talking about this:

"Keep HDR always active webosbrew/hyperion-webos#124 by sundermann"

The "Disable SDR/HDR switch" in advanced PicCap settings was there loooooong time before all this NV12 thing so it can't be the toggle for the new change. I'm more confused right now. But nonetheless it doesn't work for me.

In HyperHDR under Advanced -> Flatbuffer Server -> HDR to SDR tone-mapping is always enabled, but the actual HDR switch in Remote tab is only activated if I'm playing a HDR/DV movie file. Everything is like on version 0.4.3 for me.

@satgit62
Copy link

You need to enable NV12 in PicCap UI. Even if you are not using multiple LUTs.

@NatyaSadella
Copy link

NatyaSadella commented Jan 29, 2025

NV12 was of course enabled the second I opened PicCap 0.5.0 for the first time.

Then I checked if HDR stays on even in SDR mode but nope, same behaviour like 0.4.3

@satgit62
Copy link

NV12 was of course enabled the second I opened PicCap 0.5.0 for the first time.

Then I checked if HDR stays on even in SDR mode but nope, same behaviour like 0.4.3

Post a fresh HyperHDR protocol. Switch once to HDR and then to SDR content.

@NatyaSadella
Copy link

Switch from SDR to DV:

2025-01-29T12:45:37.624Z [FLATBUFSERVER] Setting user LUT filename to: 'lut_lin_tables_dv.3d'
2025-01-29T12:45:37.624Z [AUTOTONEMAPPING] Tone mapping is currently: enabled
2025-01-29T12:45:37.624Z [FLATBUFSERVER] Tone mapping: 1
2025-01-29T12:45:37.624Z [FLATBUFSERVER] (FlatBuffersServer.cpp:301) Adding user LUT file for searching: /home/X/.hyperhdr/lut_lin_tables_dv.3d
2025-01-29T12:45:37.624Z [COMPONENTCTRL0] HDR (global): enabled
2025-01-29T12:45:37.624Z [FLATBUFSERVER] (LutLoader.cpp:73) LUT file found: /home/X/.hyperhdr/lut_lin_tables_dv.3d (uncompressed)
2025-01-29T12:45:37.624Z [FLATBUFSERVER] (LutLoader.cpp:84) Index 1 for HDR YUV
2025-01-29T12:45:37.632Z [COLORSPACE_CALIBRATION0] (ColorSpaceCalibration.cpp:129) setGamma to [1.500000, 1.500000, 1.500000]
2025-01-29T12:45:37.632Z [COLORSPACE_CALIBRATION0] (ColorSpaceCalibration.cpp:213) setBacklightColored: 0
2025-01-29T12:45:37.632Z [COLORSPACE_CALIBRATION0] (ColorSpaceCalibration.cpp:149) set LuminanceGain to 0.950000
2025-01-29T12:45:37.645Z [FLATBUFSERVER] Found and loaded LUT: '/home/X/.hyperhdr/lut_lin_tables_dv.3d'
2025-01-29T12:45:42.630Z [AUTOTONEMAPPING] Tone mapping is currently: enabled
2025-01-29T12:45:42.630Z [FLATBUFSERVER] Setting user LUT filename to: 'lut_lin_tables_dv.3d'
2025-01-29T12:45:42.630Z [FLATBUFSERVER] Tone mapping: 1
2025-01-29T12:45:42.630Z [FLATBUFSERVER] (FlatBuffersServer.cpp:301) Adding user LUT file for searching: /home/X/.hyperhdr/lut_lin_tables_dv.3d
2025-01-29T12:45:42.630Z [FLATBUFSERVER] (LutLoader.cpp:73) LUT file found: /home/X/.hyperhdr/lut_lin_tables_dv.3d (uncompressed)
2025-01-29T12:45:42.630Z [FLATBUFSERVER] (LutLoader.cpp:84) Index 1 for HDR YUV
2025-01-29T12:45:42.651Z [FLATBUFSERVER] Found and loaded LUT: '/home/X/.hyperhdr/lut_lin_tables_dv.3d'

Then I switched from DV to SDR:

2025-01-29T12:45:42.706Z [FLATBUFSERVER] Setting
user LUT filename to: 'lut_lin_tables.3d'
2025-01-29T12:45:42.706Z [AUTOTONEMAPPING] Tone mapping is currently: disabled
2025-01-29T12:45:42.706Z [FLATBUFSERVER] Tone mapping: 0
2025-01-29T12:45:42.706Z [FLATBUFSERVER] (FlatBuffersServer.cpp:301) Adding user LUT file for searching: /home/X/.hyperhdr/lut_lin_tables.3d
2025-01-29T12:45:42.706Z [COMPONENTCTRL0] HDR (global): disabled
2025-01-29T12:45:42.706Z [FLATBUFSERVER] (LutLoader.cpp:73) LUT file found: /home/X/.hyperhdr/lut_lin_tables.3d (uncompressed)
2025-01-29T12:45:42.706Z [FLATBUFSERVER] (LutLoader.cpp:89) Index 2 for YUV
2025-01-29T12:45:42.717Z [COLORSPACE_CALIBRATION0] (ColorSpaceCalibration.cpp:129) setGamma to [2.000000, 2.000000, 2.000000]
2025-01-29T12:45:42.717Z [COLORSPACE_CALIBRATION0] (ColorSpaceCalibration.cpp:213) setBacklightColored: 0
2025-01-29T12:45:42.718Z [COLORSPACE_CALIBRATION0] (ColorSpaceCalibration.cpp:240) setBrightness: 50
2025-01-29T12:45:42.718Z [COLORSPACE_CALIBRATION0] (ColorSpaceCalibration.cpp:149) set LuminanceGain to 1.000000
2025-01-29T12:45:42.739Z [FLATBUFSERVER] Found and loaded LUT: '/home/X/.hyperhdr/lut_lin_tables.3d'
2025-01-29T12:45:43.804Z [FLATBUFSERVER] Setting user LUT filename to: 'lut_lin_tables.3d'
2025-01-29T12:45:43.804Z [FLATBUFSERVER] Tone mapping: 0
2025-01-29T12:45:43.804Z [FLATBUFSERVER] (FlatBuffersServer.cpp:301) Adding user LUT file for searching: /home/X/.hyperhdr/lut_lin_tables.3d
2025-01-29T12:45:43.804Z [AUTOTONEMAPPING] Tone mapping is currently: disabled
2025-01-29T12:45:43.804Z [FLATBUFSERVER] (LutLoader.cpp:73) LUT file found: /home/X/.hyperhdr/lut_lin_tables.3d (uncompressed)
2025-01-29T12:45:43.804Z [FLATBUFSERVER] (LutLoader.cpp:89) Index 2 for YUV
2025-01-29T12:45:43.822Z [FLATBUFSERVER] Found and loaded LUT: '/home/X/.hyperhdr/lut_lin_tables.3d'
2025-01-29T12:45:43.983Z [FLATBUFSERVER] Setting user LUT filename to: 'lut_lin_tables.3d'
2025-01-29T12:45:43.983Z [FLATBUFSERVER] Tone mapping: 0
2025-01-29T12:45:43.983Z [FLATBUFSERVER] (FlatBuffersServer.cpp:301) Adding user LUT file for searching: /home/X/.hyperhdr/lut_lin_tables.3d
2025-01-29T12:45:43.983Z [FLATBUFSERVER] (LutLoader.cpp:73) LUT file found: /home/X/.hyperhdr/lut_lin_tables.3d (uncompressed)
2025-01-29T12:45:43.983Z [FLATBUFSERVER] (LutLoader.cpp:89) Index 2 for YUV
2025-01-29T12:45:43.983Z [AUTOTONEMAPPING] Tone mapping is currently: disabled
2025-01-29T12:45:44.002Z [FLATBUFSERVER] Found and loaded LUT: '/home/X/.hyperhdr/lut_lin_tables.3d'

@satgit62
Copy link

Yes, that is not correct. The YUV index must not be 0 or 2. To activate tone mapping, the YUV index must be 1, just as with your DV LUT (Tone mapping: 1)

You need to delete the 50MB flat_lut_lin_tables.3d file from /media/developer/apps/usr/palm/services/org.webosbrew.hyperhdr.loader.service/hyperhdr/.

Only LUTs with a size of 150 MB, e.g. 'lut_lin_tables.3d', may be present either in /media/developer/apps/usr/palm/services/org.webosbrew.hyperhdr.loader.service/hyperhdr/ or in /home/root/.hyperhdr/.

1 similar comment
@satgit62
Copy link

Yes, that is not correct. The YUV index must not be 0 or 2. To activate tone mapping, the YUV index must be 1, just as with your DV LUT (Tone mapping: 1)

You need to delete the 50MB flat_lut_lin_tables.3d file from /media/developer/apps/usr/palm/services/org.webosbrew.hyperhdr.loader.service/hyperhdr/.

Only LUTs with a size of 150 MB, e.g. 'lut_lin_tables.3d', may be present either in /media/developer/apps/usr/palm/services/org.webosbrew.hyperhdr.loader.service/hyperhdr/ or in /home/root/.hyperhdr/.

@NatyaSadella
Copy link

I'm using HyperHDR 21b2 on a RPI5, not on my LG TV. LUT space is not a problem in my case and there are no LUT's on my TV

@satgit62
Copy link

I'm using HyperHDR 21b2 on a RPI5, not on my LG TV. LUT space is not a problem in my case and there are no LUT's on my TV

I don't think it makes a difference if you run HyperHDR on the Raspberry Pi. The NV12 should also be included in the branch for Raspberry. I see in your log that the new compression method is also included. See: https://github.com/satgit62/How-to-compress-the-LUT-table-and-use-it-in-HyperHDR.
Just try out the compressed LUT for SDR that I provided.

@NatyaSadella
Copy link

Just for the sake of trying, I did try your SDR LUT and the log doesn't look different than what I have posted above, HDR stays off on SDR content.

I mean, why should it work now out of a sudden by using your LUT instead of mine..?

@awawa-dev
Copy link
Owner Author

Seems the same issue like here: #1062 (comment) I propose you to verify your md5 of the backend libraries. Or maybe the old version refused to uninstall while running and needs hard reset of the service?

@satgit62
Copy link

Yes, exactly, PicCap finishes with:

 pgrep -fl piccap | while read -r pid _; do kill "$pid"; done

Uninstall and reinstall, reboot and configure.

@NatyaSadella
Copy link

No luck yet, I have installed the latest HyperHDR version from the GitHub Actions tab and reinstalled PicCap. Still doesn't work.

@awawa-dev
Copy link
Owner Author

It's only about the backend/piccap, HyperHDR in this case is only a client. And it's instructed to disable tone mapping for SDR which is an incorrect command.

@satgit62
Copy link

No luck yet, I have installed the latest HyperHDR version from the GitHub Actions tab and reinstalled PicCap. Still doesn't work.

Very strange this behaviour, try this PicCap build: https://github.com/satgit62/PicCap-hyperion-webos-NV12-Test/raw/refs/heads/main/org.webosbrew.piccap_0.5.0_all.ipk

@NatyaSadella
Copy link

I have tried that in the meantime but it still didn't work.

Then I manually copied the backends and hyperion-webos file to the PicCap folder and now it's working:

2025-01-29T14:51:51.173Z [AUTOTONEMAPPING] Tone mapping is currently: enabled
2025-01-29T14:51:51.173Z [FLATBUFSERVER] Tone mapping: 1
2025-01-29T14:51:51.173Z [FLATBUFSERVER] (FlatBuffersServer.cpp:301) Adding user LUT file for searching: /home/X/.hyperhdr/lut_lin_tables.3d
2025-01-29T14:51:51.173Z [FLATBUFSERVER] (LutLoader.cpp:73) LUT file found: /home/X/.hyperhdr/lut_lin_tables.3d (uncompressed)
2025-01-29T14:51:51.173Z [FLATBUFSERVER] (LutLoader.cpp:84) Index 1 for HDR YUV
2025-01-29T14:51:51.199Z [FLATBUFSERVER] Found and loaded LUT: '/home/X/.hyperhdr/lut_lin_tables.3d'

😃

@awawa-dev
Copy link
Owner Author

awawa-dev commented Jan 29, 2025

So definitely something wrong is with the installer. Can you compare MD5 files you used with MD5 in the official package? 7-zip can compute it if you right click on the file or open the archive/ipk.

@NatyaSadella
Copy link

I compared the working and non-working hyperion-webos and backends with "md5sum" on my RPI and they don't match.

@satgit62
Copy link

satgit62 commented Jan 29, 2025

I compared the working and non-working hyperion-webos and backends with "md5sum" on my RPI and they don't match.

Can you please test this again? I have replaced it, and it works straight away:https://github.com/satgit62/PicCap-hyperion-webos-NV12-Test/raw/refs/heads/main/org.webosbrew.piccap_0.5.0_all.ipk This version is compiled on my PC Ubuntu Node 22.

@NatyaSadella
Copy link

Can you please test this again? I have replaced it, and it works straight away:https://github.com/satgit62/PicCap-hyperion-webos-NV12-Test/raw/refs/heads/main/org.webosbrew.piccap_0.5.0_all.ipk This version is compiled on my PC Ubuntu Node 22.

Yep, this version works out of the box.

@satgit62
Copy link

Can you please test this again? I have replaced it, and it works straight away:https://github.com/satgit62/PicCap-hyperion-webos-NV12-Test/raw/refs/heads/main/org.webosbrew.piccap_0.5.0_all.ipk This version is compiled on my PC Ubuntu Node 22.

Yep, this version works out of the box.

Thanks for testing, I still have to clarify why the PicCap built on the PC with Node 22 works, with the same cloned branch and in Git with Node 18 that doesn't work.

@satgit62
Copy link

@NatyaSadella
The bug in the PicCap has been fixed and is released officially now. https://github.com/TBSniller/piccap/releases/tag/0.5.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants