Ashyni / mpv-scripts

dynamic-crop.lua script for mpv player/lib.
MIT License
81 stars 4 forks source link

Difficulty to validate odd meta (e.g. height moving back and forth from 816 to 818 regularly) #5

Closed FitzWM closed 3 years ago

FitzWM commented 3 years ago

Hi, and let me say first, thanks for the great script. It certainly makes watching the Nolan Batman films significantly more enjoyable. I'd like to use it all the time, but unfortunately, it's failing for me on seemingly random files, no matter what options I change, even though the "traditional" autocrop.lua script seems to handle them fine. When I say failing, I mean that the script runs - I can see that in the stats screen - but it doesn't do anything, no matter how long or wait, skip around, or toggle it off and on. Changing modes doesn't help either, nor do turning off the "reset" or "skip" options, though I admit my understanding of those is less than minimal. I tried activating debug mode, but I couldn't figure out where to find the debug info; I'd be glad to provide it if you could tell me where it is.

The really annoying thing (since I'd like to provide a more useful bug report) is that there doesn't seem to be anything tying the "problem files" together. A few examples:

There are a couple others, but those are the ones I can recall right now. What's weird is that I have dozens of movies with exactly the same specs that all work just fine with your script. I can't figure out what the issue is. Obviously, the problem goes away if I run them through Handbrake and crop them, but that rather defeats the point of an autocrop script.

Anyway, thanks again, and I hope things are going well for you.

Edit: Forgot to add my specs.

I typically use the vulkan API and winvk context, along with the FSRCNNX and SSIMDownscaler shaders. I've tried turning all my shaders off, though, as well as changed to various APIs, but no luck.

Ashyni commented 3 years ago

Hello, one thing to try quickly, would be to set deviation = 0, keep the rest with the default values, but the log will help to be sure what going on.

Edit mpv.conf : log-file=C:\Users\<username>\AppData\Roaming\mpv\mpv.log -- Or any path you can find easily

Post me the log here or on pastebin, i'll take a look.

You can watch the log in realtime in powershell with Get-Content C:\Users\<username>\AppData\Roaming\mpv\mpv.log -Wait | Select-String -Pattern "\[dynamic_crop\]".

I also use FSRCNNX, KrigBilateral, SSSR, SSD with vulkan API, it's not an issue.

FitzWM commented 3 years ago

Thanks for the quick reply! I tried adding the script-opts-append=autocrop-deviation=0 option to mpv.conf, but it didn't seem to help, unfortunately. I've attached five files:

Just let me know if there's anything else I can do to help diagnose the issue.

kingdom-of-heaven.log kingdom-of-heaven-autocrop.log zombieland.log zombieland-autocrop.log mpv.conf.txt

Ashyni commented 3 years ago

I have updated the documentation,

script-opts-append=autocrop-deviation=0

should be script-opts-append=<script_name>-<option>=<value>, e.g. script-opts-append=dynamic_crop-deviation=0, but it's not the issue anyway.

From the logs, with option debug=true (apparently), the collected meta found for Kingdom of Heaven

w=1920:h=822:x=0:y=126 | offX=0 offY=-3 | detected_total=8.05 ratio=nil -- 2,3357 compare to 1920/2.35=817+-1 (816 or 818 to match)
w=1920:h=820:x=0:y=128 | offX=0 offY=-2 | detected_total=1.752 ratio=nil 
w=1920:h=822:x=0:y=128 | offX=0 offY=-1 | detected_total=5.258 ratio=nil -- 2,3357
w=1920:h=824:x=0:y=126 | offX=0 offY=-2 | detected_total=0.917 ratio=nil 

and for Zombieland,

w=3840:h=1606:x=0:y=276 | offX=0 offY=-1 | detected_total=0.248 ratio=true 
w=3840:h=1608:x=0:y=276 | offX=0 offY=0 | detected_total=0.417 ratio=true 
w=3840:h=1604:x=0:y=278 | offX=0 offY=0 | detected_total=15.727 ratio=nil -- 2.39401 compare to 3840/2.39=1606.69+-1 (1606 or 1608 to match)
w=3840:h=1606:x=0:y=278 | offX=0 offY=1 | detected_total=0.835 ratio=true 

This show me that the collected meta is not match as known ratio, that's why the script doesn't approve the crop in 5sec (+1sec allowed to deviate) but should eventually be able to be approved as a fallback after 20sec (+1) in a stable light scene (which can be harder to get, but pass eventually).

I will work on something to get more tolerance on this, in the meantime you can adjust the list of ratios or reduce new_fallback_timer and increase deviation to 2 or 3 sec, e.g. script-opts-append=dynamic_crop-new_fallback_timer=15, don't go to low, or you will end up with false positive crop script-opts-append=dynamic_crop-deviation=2 script-opts-append=dynamic_crop-ratios={2.4, 2.394, 2.39, 2.35, 2.335, 2.2, 2, 1.85, 16 / 9, 5 / 3, 1.5, 4 / 3, 1.25, 9 / 16} -- doesn't work, i'm going to alter the format

FitzWM commented 3 years ago

OK, so good news and bad news. The good news is that simply adding the additional ratios seems to have solved the problem for Kingdom of Heaven, Zombieland, and Pirates of the Caribbean, in addition to the freshly merged Return of the King I just made. The bad news is that Kingdom of Heaven and Paprika continue to cause issues, even when I also added 2.347 to the list (basing that off the 1920x818 dimensions arrived at by autocrop for Kingdom). Oddly, as you said, both Kingdom and Paprika will eventually crop correctly once they hit that fallback of 20 seconds, or 15 if you edit. Can I ask what is done differently at that point that makes it work properly?

Also, I found that adding the options via script-opts-append in mpv.conf caused dynamic-crop to crash upon starting any file, but simply editing the options in the script itself worked fine. No idea why, but I thought I'd report it.

Edit: Even modifying the other parameters doesn't get those two to work properly. Very strange.

Ashyni commented 3 years ago

Hello, multiple change that will help with your case have been made, give it a try.

Can I ask what is done differently at that point that makes it work properly?

Simple, new_known_ratio_timer is checked with the list of ratios and new_fallback_timer without it (all stable collected meta long enough)

I recommend avoiding added more ratio to the default list, to reduce the chance of a false positive cropping, and give time to the script to approve the first change of ratio.

You can speed up your test with ], reset with backspace.

Thanks for all the feedback.

Edit: bug fix in the meantime, be sure you have the latest version.

FitzWM commented 3 years ago

Hey, apologies for the late response. The fixes really seem to have helped! All but one of the movies I've tested now work as expected without further tweaking. Kingdom of Heaven, though, for whatever reason, simply refuses to crop normally, requiring the full new_fallback_timer period to expire before it will, finally, crop perfectly correctly. Maybe it's just something weird with that one file? In any case, everything else, across a few different aspect ratios and resolutions, seems to be working, so that's great! And I can always threaten the stubborn few with Handbrake...

Ashyni commented 3 years ago

The log that you gave me for Kingdom of Heaven, show a 2.3357 aspect ratio, but the fallback timer is here for that.

You should try Interstellar with this script, it's a case of use where it shines.

I consider this case closed, Happy Video !