osumoclement / script.black.bars.never

An addon to automatically remove black bars in KODI
GNU General Public License v3.0
12 stars 2 forks source link

Adapt over time #2

Closed stenyak closed 1 year ago

stenyak commented 1 year ago

Sometimes, the plugin will mis-detect the black bar size if a video happens to start with some black background imagery with some content scattered inside of it.

This could be solved by re-checking frames every e.g. 2.5 seconds: if the "detected blackbar size" gets smaller, it means the initial detection was wrong and needs to be adjusted, by taking the smaller size we just saw.

A second more complex case, is when a single video has various aspect ratios throughout its length. Such as some movies filmed with several different cameras, each with a different ratio, and the released cut intentionally featuring varying ratios. Those might be possible to handle by checking for the stability of blackbar size: so not only taking the minimum size as explained above, but also allowing to enlarge the detected blackbar size if it has been a consistent-ish size over a period of, say, 10 seconds.

(side note, I was doing the modifications myself, in order to submit a merge request here, but I can't even re-package the zip file without Kodi claiming it has an invalid structure (even though it looks identical to your release zip structure)

The first case should™ be quite simple to implement from what I see, while the second one seems a bit more complicated to get right.

Thoughts?

osumoclement commented 1 year ago

What video has this mis-detection so I can have a look? What OS are you using? The first case I think could be occurring on specific machines/OS based on what I've encountered in the past. The addon already discards frames that are too dark, but I will check and confirm.

The second case I did think about when I was creating the first release of the addon, and it sure is complicated. For instance, let's say the aspect ratio changes from 16:9 to 1.85:1 in the middle of the video and this lasts for 5 minutes then it switches back to 16:9. Since the stability check takes several seconds to be sure of the new change, during this time the user is seeing an image that's missing content from all sides (left, right, up, down). There's also a worst case scenario where the frames being analyzed every 2.5 seconds are coincidentally misleading (the frame is dark past the real content boundary) and this would lock the picture at a wrong aspect ratio for too long.

I also think of another possible problem, one in which we have a video which has constant aspect ratio all through, but as the addon analyzes every 2.5 seconds, it coincidentally grabs enough frames which are dark in just the wrong places to mislead the addon.

I encountered the problem you have with Kodi rejecting zip file, in my case when it does this I kill and restart the Kodi process and try again this time it works. If you're able to get a merge request working I'll be happy to evaluate

stenyak commented 1 year ago

Restarting Kodi has indeed fixed the inability to update the addon. Not sure why that happens, but it certainly slows down dev iterations which is a shame.

In any case, I've implemented a quick and dirty solution to re-compute each time you resume video playback. So at any point, if the ratio seems wrong, you can just double-tap spacebar and it'll fix it (first case). For now I'm assuming the video is not a dynamic-ratio kind of video (second case).

A merge request is not cleanly viable, since I ended up doing some cleanups prior to the actual feature, but feel free to take a look at my changes and grab whatever you like from them :) https://github.com/stenyak/script.black.bars.never

osumoclement commented 1 year ago

Sounds good. I will add this recompute-on-resume behavior in next release