Detect Video Resolution

By  on  

Video resolution has always been something I've been interested in, starting with the purchase of my first HD television.  The HD video quality felt life-changing, especially when watching the World Cup, which I'd bought that TV for.  I carried that enthusiasm through to being an early adopter of 4K TVs, which are absolutely amazing.

These days you can get 4K videos on YouTube, Netflix, and other networks, and I see that Samsung and Sony are even offering 8K televisions.  With that in mind, I wanted to figure out how to detect video resolution from a downloaded video file.  Let's check it out!

Standard Video Resolutions

The following are standard video resolutions you may recognize:

Standard Resolution Aspect Ratio Pixels
DVD 720 × 480 (NTSC) 4:3 or 16:9 345,600
720 × 576 (PAL) 414,720
720p (HDTV) 1280 × 720 16:9 921,600
1366 × 768 (FWXGA) 1,049,088
1080i, 1080p (HDTV, Blu-ray) 1920 × 1080 16:9 2,073,600
4K (UHDTV) 3840 × 2160 16:9 8,294,400
8K (UHDTV) 7680 × 4320 16:9 33,177,600

This wikipedia page provides other popular resolutions used in different devices.

Detect Video Resolution with ffprobe

Installing ffmpeg provides another utility, ffprobe, which allows us to get the resolution of a video file, albeit with a cryptic command:

eval $(ffprobe -v error -of flat=s=_ -select_streams v:0 -show_entries stream=height,width MyVideo.mkv)
size=${streams_stream_0_width}x${streams_stream_0_height}
echo $size // "3840x1606"

We can create a shell alias function to make this type of video resolution query more dynamic:

getVideoResolution() {
    eval $(ffprobe -v error -of flat=s=_ -select_streams v:0 -show_entries stream=height,width $1)
    size=${streams_stream_0_width}x${streams_stream_0_height}
    echo $size
}

# getVideoResolution myVideo.mkv

Many media sites allow you to choose the video quality you prefer, so knowing the maximum video quality available (that of the original source, in theory) is useful.

Retrieving the resolution of a video isn't difficult using ffprobe!

Recent Features

  • By
    JavaScript Promise API

    While synchronous code is easier to follow and debug, async is generally better for performance and flexibility. Why "hold up the show" when you can trigger numerous requests at once and then handle them when each is ready?  Promises are becoming a big part of the JavaScript world...

  • By
    9 More Mind-Blowing WebGL Demos

    With Firefox OS, asm.js, and the push for browser performance improvements, canvas and WebGL technologies are opening a world of possibilities.  I featured 9 Mind-Blowing Canvas Demos and then took it up a level with 9 Mind-Blowing WebGL Demos, but I want to outdo...

Incredible Demos

  • By
    Image Manipulation with PHP and the GD Library

    Yeah, I'm a Photoshop wizard. I rock the selection tool. I crop like a farmer. I dominate the bucket tool. Hell, I even went as far as wielding the wizard wand selection tool once. ...OK I'm rubbish when it comes to Photoshop.

  • By
    jQuery topLink Plugin

    Last week I released a snippet of code for MooTools that allowed you to fade in and out a "to the top" link on any page. Here's how to implement that functionality using jQuery. The XHTML A simple link. The CSS A little CSS for position and style. The jQuery...

Discussion

    Wrap your code in <pre class="{language}"></pre> tags, link to a GitHub gist, JSFiddle fiddle, or CodePen pen to embed!