I’m creating an application to display multiple videos concurrently (lets say 2-10 videos). I’m basically looking for an algorithm which can aid in the placement of the videos on the screen. The problem I face is that each video may have a different aspect ratio, and I will obviously need to resize the videos to make them all fit on the screen. But I want to resize and fit them in a way that I maximise the use of the screen (and minimise aspect ratio distortion). In addition I want the user to be able to increase the size of one or more videos so it takes more space on the screen. Thus the algorithm should be stable, in the sense that enlarging one video doesn’t make all the placements jump around.
I’m asking this question in a language agnostic way, and the fact I’m using video is irrelevant, this problem applies equally to still images.
So does anyone know of a placement algorithm?
To help clarify here is an example. I have three videos, with the following sizes. I want the first video to take up roughly 50% of the screen, and the last two videos to take up roughly 25% of the screen.
(464, 336) 50%
(624, 480) 25%
(608, 336) 25%
How would I place them on the screen (1024×800) to achieve this? I figured I would first divide the screen in half and best fit the first video in the top half. Then I would divide the bottom half into two and fit both remaining videos as best I can.
thanks in advance
This is a version of the bin packing problem
http://en.wikipedia.org/wiki/Bin_packing_problem
which is NP-hard, so you’ll want to choose some reasonable heuristic. If you don’t want videos to jump around as you resize one, you’ll need to leave a bunch of extra dead space or automatically shrink the others.
Unless you have a good reason for allowing it, I’d suggest requiring the aspect ratios to stay fixed.
A suggestion: start by fixing the height of all videos, then use a greedy first fit algorithm to pack them in. The initial height would be an integer fraction of the total screen height. If someone resizes a video, everything else shrinks by the same fraction value and shifts away to accomodate.