-1

By display format, I mean names like 360p, 720p, 1080, 2K, 4K, 8K.

If I have a bunch of videos, how do I determine which format is each? Their resolutions vary, some are 1280x720, which is 720p, but others are 1270x528, which should still be 720p? Same with 960x720.

Anna K.
  • 1,887
  • 6
  • 26
  • 38
  • Possible duplicate of [Get video resolution in nodejs](http://stackoverflow.com/questions/31924846/get-video-resolution-in-nodejs) – Gökay Gürcan Nov 01 '15 at 21:30
  • @GökayGürcan I'd disagree, the OP is asking for a solution in JavaScript, not Node.JS. – Script47 Nov 01 '15 at 21:33
  • Actually I'm using nodejs but that link doesn't really answer my question. I know how to get the width and height, but I don't know how to convert that to a human readable format name – Anna K. Nov 01 '15 at 21:39
  • @AnnaK. please use the appropriate tags for your questions. – Script47 Nov 01 '15 at 21:39

3 Answers3

1

The resolution is a characteristic of the video file. In Windows, you can check the resolution of the video by clicking with the right mouse button in the video file, select "Properties", then "Details". There you have two properties, width and height. If the width is 1280 and the height 720, then the resolution is 1280X720.

Basically, these numbers represent the amount of pixels, or colored points you see in the screen. In 1280X720, there are 1280 pixels in the width and 720 in the height. The more pixels, the better the resolution.

The ability to support these resolutions is specific of your monitor/TV.

1

I made a small array with some common resolutions. The algorithm looks first for the lines and then for the dots.

var resolution = [
        { name: '480p', dots: 852, lines: 480 },
        { name: '576p', dots: 768, lines: 576 },
        { name: '720p', dots: 1280, lines: 720 },
        { name: '1080p', dots: 1920, lines: 1080 },
        { name: '2160p', dots: 3840, lines: 2160 },
        { name: '4320p', dots: 7680, lines: 4320 },
    ];

function findResolution(dots, lines) {
    var i = 0;
    while (lines > resolution[i].lines) {
        i++;
    }
    while (dots > resolution[i].dots) {
        i++;
    }
    return resolution[i].name;
}
document.write(findResolution(600, 600) + '<br>');
document.write(findResolution(1920, 600) + '<br>');        
document.write(findResolution(1270, 528) + '<br>');
document.write(findResolution(960, 720) + '<br>');
Nina Scholz
  • 376,160
  • 25
  • 347
  • 392
0

Use mediainfo. However, when looking at resolutions for video files, it depends on whether they specify the entire rendered screen or based on the aspect ratio.

For example a 720p video may be specified as 1280 x 720 or 1280 x 528 (the missing pixels are usually the black bars at the top and bottom). The black bars might still be encoded giving the full 720p image, but if they're missing then the TV may auto scale the picture to 'full screen'. Same goes for 1920 x 1080 and 1920 x 798 or similar.

People may specify something as 720 if the video is also running at 720 x 340 (I think is a usual one). Best bet is to use mediainfo, it's a good little utility.

Amble
  • 187
  • 2
  • 14