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
    CSS Animations Between Media Queries

    CSS animations are right up there with sliced bread. CSS animations are efficient because they can be hardware accelerated, they require no JavaScript overhead, and they are composed of very little CSS code. Quite often we add CSS transforms to elements via CSS during...

  • By
    I’m an Impostor

    This is the hardest thing I've ever had to write, much less admit to myself.  I've written resignation letters from jobs I've loved, I've ended relationships, I've failed at a host of tasks, and let myself down in my life.  All of those feelings were very...

Incredible Demos

  • By
    Downloadify:  Client-Side File Generation Using JavaScript and Flash

    The following tools is in its very beta stages and works intermittently. Its so damn useful that I had to show it off now though! I recently stumbled upon Downloadify, a client-side file generation tool based on JavaScript and Flash ActionScript code. A...

  • By
    JavaScript Copy to Clipboard

    "Copy to clipboard" functionality is something we all use dozens of times daily but the client side API around it has always been lacking; some older APIs and browser implementations required a scary "are you sure?"-style dialog before the content would be copied to clipboard -- not great for...

Discussion

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