Multiple Image Algorithm - Collage Algorithm

I am creating an application to display multiple videos at the same time (say, 2-10 videos). I am mainly looking for an algorithm that can help put the video on the screen. The problem I am facing is that each video may have a different aspect ratio, and I obviously need to resize the videos so that they all fit on the screen. But I want to resize and position them so that I make the most of the screen (and minimize aspect ratio distortion). In addition, I want the user to be able to increase the size of one or more videos so that he takes up more space on the screen. Thus, the algorithm must be stable, in the sense that increasing one video does not cause all placements to move.

I ask this question in an agnostic language, and the fact that I use video does not matter, this problem applies equally to still images.

Does anyone know about the placement algorithm?

An example is provided to help clarify here. I have three videos with the following sizes. I want the first video to occupy about 50% of the screen, and the last two videos to occupy about 25% of the screen.

(464, 336) 50%
(624, 480) 25%
(608, 336) 25%

How would I put them on the screen (1024x800) to achieve this? I decided that I would first split the screen in half and best place the first video in the upper half. Then I would split the bottom half into two and put both of the remaining videos as far as I could.

early

+3
source share
3 answers

 http://en.wikipedia.org/wiki/Bin_packing_problem NP-, . , , .

, , .

: , , . . - , .

+2

, Treemap - , .

alt text

treemaps algs, ,

!

+4

+ , . sqrt < 0.5, , rows/cols 1 ; sqrt > 0.5, /.

10 videos = 4x3 (3.16; rounded down, so add 1 row or col)
9 videos = 3x3 (3; abs)
8 videos = 3x3 (2.82; round up)
7 videos = 3x3 (2.64; round up)
6 videos = 3x2 (2.44; round down, so add 1 row or col)
5 videos = 3x2 (2.23; round down, so add 1 row or col)
4 videos = 2x2 (2; abs)
3 videos = 2x2 (1.73; round up)
2 videos = split screen in half vertically or horizontally (however you'd like)
1 video = full screen

"" , , , /, ( ).

, , , . , , ( ) .

/ , , , .

- , . , , .

If you want to "maximize" the video, then determine in advance how much space "maximizes" means. Then subtract the pixel size from the screen resolution before calculating the size of other videos. If maximization means 50% of the screen, then you subtract this video from the number of videos in the grid and subtract 50% of the pixel space from the display resolution.

0
source

Source: https://habr.com/ru/post/1762057/


All Articles