WesselKroos / youtube-ambilight

This browser extension adds ambient light to YouTube videos
MIT License
78 stars 8 forks source link

Less aggressive remove black bar option #225

Closed Askejm closed 2 months ago

Askejm commented 3 months ago

Is your feature request related to a problem? Please describe. I own an ultrawide, and find great use in the remove black bars feature. However, I often find that this feature is very jittery and mistakes things for black bars. I was watching this video and at 5:51 the extension would mistake the star background for a black bar.

Describe the solution you'd like A solution would be a toggle for a less aggressive remove black bar solution. In this solution, the extension would detect a black bar and then instead of finding where the black bar ends i suggest cropping a predetermined amount if the black bar is big enough. This would be most noticable in 16:9 playing 21:9 content. I feel like this could eliminate some of the "seeking" it does back and forth like i noticed in the video i linked. Perhaps if this clears up performance, you could also add a more thorough method for detecting if the black bar has any other elements in it like the stars. Basically, when a black background is present the extension will cut think its a black bar. I propose a feature in which it only crops a specific amount. For example, if the black bar is 21:9 content in a 16:9 video +-50 pixels then crop, else not. I just want to scale the content up and use the full size of my 21:9 monitor when 21:9 content is displayed

Describe alternatives you've considered You could also add a feature to crop the entire video to a specific aspect ratio without any dynamic adjustments I hope this makes sense

WesselKroos commented 3 months ago

Reading pixel data from a video frame is an expensive operation, that's why the video frame gets reduced to 512x512 pixels and only 5 lines of pixels are being read. Your example contains a background with small stars and thus is a perfect example of an image with lots of small bright details that get lost and faded due to this reduction, resulting in a more black-ish image: image

Since a video can be in any aspect ratio on YouTube and the video frame gets cropped to a square, there is no way to determine which ratios are more important than others in the detection algorithm.

But I'm already working on a evolution of the black bar detection algorithm. The evolution will detect differences between the r,g,b color values of pixels instead of only comparing the combined r+g+b value. And it randomizes the position of the 5 lines of pixels that are being read. This seems to reduce the flickering a bit.

But I think a precision threshold setting could work even better in these kind of scenarios. Currently only the closest 7 out of 10 detected sizes are being used to determine the bar size (to ignore minor video compression errors and channel logos). So increasing this amount should take these minor details more into account.

WesselKroos commented 3 months ago

The next version seems to work better: image

But feel free to slide the new "Bar detection anomalies" setting to 10% to reduce the errors even more.

Or slide it to 90% to ignore more stars: image

Askejm commented 3 months ago

Since a video can be in any aspect ratio on YouTube and the video frame gets cropped to a square, there is no way to determine which ratios are more important than others in the detection algorithm.

Wouldn't you be able to get the videos aspect ratio on the page load and keep that information to calculate which crop amount would be more important? Sorry if I am misunderstanding, I don't really write code

WesselKroos commented 3 months ago

Wouldn't you be able to get the videos aspect ratio on the page load and keep that information to calculate which crop amount would be more important? Sorry if I am misunderstanding, I don't really write code

That should be possible, but:

So I would rather spend that development time on making the detection algorithm more correct to reduce the flickering. Than finetuning the algorithm for specific aspect ratios.

WesselKroos commented 2 months ago

@Askejm The improved algorithm and the new setting is now available on all browsers