detuur / mpv-scripts

This is a collection of my own mpv scripts.
MIT License
54 stars 9 forks source link

Fix toggleFilter function and change key binding from Ctrl+h to Alt+h #6

Closed microraptor closed 2 years ago

microraptor commented 2 years ago

Thank you for the very useful script! Since I noticed very weird behavior on one of my computers I took a look at the code and fixed the toggleFilter function. This resolves the weird behavior described in issue #5, and makes the script function as it should ~on one of the computers~.

The function had two bugs:

  1. If no video filter existed before, the toggle function would not create the histogram video filter as it should. Because skiptosilence.lua creates a video filter, this has probably gone unnoticed.
  2. There is a return statement inside the for loop. So the loop would only run once and detect the histogram only, if it is the last video filter. This probably has gone unnoticed, because the histogram is mostly the last filter created.

Besides these fixes I also added comments and log messages.

The similar rebuildGraph functioned also correctly before, but I removed the unnecessary if statement, because in Lua a for i = 0, 1, -1 do loop doesn't even run the loop once.

microraptor commented 2 years ago

I also changed the Ctrl+h key binding to Alt+h. mpv's default Ctrl+h is used to toggle hardware decoding on/off. This key binding is useful, because the script doesn't work with at least some types of hardware decoding, as I noted in the new readme. There is no default mpv key binding for Alt+h.

microraptor commented 2 years ago

I added some code now to automatically disable hardware decoding, if it is detected. After the histogram is toggled off the HW decoding is enabled again. I also changed the commands are are used for filter management, which simplifies stuff a little.

detuur commented 2 years ago

Great catch on the bugs. Glad the script was of any use to anyone in the first place. The no-osd command is neat, I must've missed it back when I wrote this.