phoboslab / jsmpeg

MPEG1 Video Decoder in JavaScript
MIT License
6.3k stars 1.43k forks source link

Video wall, full screen, do not preserve aspect ratio. Possible? #394

Closed thehijacker closed 2 years ago

thehijacker commented 2 years ago

Hello,

I am building a video wall with multiple websockets. Not sure if issue I am trying to solve is related to jsmpeg or I just can't not figure out the html/css code.

The canvas are inside grid (4x4). Without canvas inside grid it will correctly show grid edge to edge depending on browser window size. But as soon as I add canvas inside it will strech to the width, but not limit the height. I get a slider to scroll down. What I want is that canvas would shrink proportionaly, depending on the window size without any vertical or horizontal sliders. I hope you understand me. Basically I wish to see all 16 screens in full screen page, without preserving aspect ratio. Currently it looks like that canvas is fixed to whatever is the size of the video.

image

Is there a CSS that I need to override or am I missing something else?

Thank you very much for the help.

thehijacker commented 2 years ago

Made some progress. I no longer get slider if I dinamically change width and height of canvas. But the video will not resize inside the canvas. Only canvas.

image

Code I used:

$(window).on('resize', function()
{
    var win = $(this);
    for (var i = 0; i < 16; i++)
    {
        var canvas = document.getElementById('player-wrp-'+(i + 1));
        canvas.height = win.height() / 4 - 10;
        canvas.width = win.width() / 4 - 10;
    }
});

Any possible way to make the video also resize?

Thank you.

phoboslab commented 2 years ago

The internal resolution of the canvas element (canvas.width and canvas.height) must be the same as the video resolution, otherwise the decoded video will just be drawn "outside" the element as you already figured out.

However, you can change the display size of the canvas element using the css style property. So for your example:

canvas.style.height = (win.height() / 4 - 10) + 'px';
canvas.style.width = (win.width() / 4 - 10) + 'px';

Edit: I believe you should be able to achieve the same directly in the CSS, too. Maybe using css grid or flexbox, but you're probably better of asking for a CSS solution on Stackoverflow, as this is not directly related to JSMpeg.

thehijacker commented 2 years ago

Hello @phoboslab.

Thank you very much. That did it.

image

I can resize as much as I want but it will keep it always inside the window.

Best regards!