Removing black bars off video thumbnail

假如想象 提交于 2019-12-22 10:26:27

问题


I have gallery where user can submit Youtube links to videos and server fetches the thumbnail from Youtube automatically. However, lots of videos contain black bars on top and bottom of the image. I know the origin of the black bars, but as i resize thumbnail to square, the black bars interfere with the design.

I have tried to analyze pixel color from top to bottom until no black color is found (imagecolorat()), but it still leaves some near-black color so the small bars still reside in the image.

What can be more effective algorythm to check for?


回答1:


If you want to go by the color, the wideimage library (GD based) has this implemented already. The method is called autoCrop, an online demonstration exists.

This might already fulfil your needs.




回答2:


One of the solutions is to do same thing which youtube did. If you visit their site, and look at the image and element that wraps image, you will see that wrap element have css similar to this one:

display:inline-block;
height: /*here goes fixed height in px*/
overflow: hidden;

They are using image which contain black areas on top and bottom (within that container), but they used css to hide it. This means that element (on youtube span with att display:inline-block) will be smaller then acctual picture, and picture will be centered/positioned like that so top and bottom black areas will overflow smaller wrap and will be hidden.




回答3:


You should check the video's ratio (4:3 or 16:9) and crop the thumbnail to keep that ratio. Not trying to detect the color.



来源:https://stackoverflow.com/questions/7938789/removing-black-bars-off-video-thumbnail

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!