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
    How to Create a RetroPie on Raspberry Pi – Graphical Guide

    Today we get to play amazing games on our super powered game consoles, PCs, VR headsets, and even mobile devices.  While I enjoy playing new games these days, I do long for the retro gaming systems I had when I was a kid: the original Nintendo...

  • By
    fetch API

    One of the worst kept secrets about AJAX on the web is that the underlying API for it, XMLHttpRequest, wasn't really made for what we've been using it for.  We've done well to create elegant APIs around XHR but we know we can do better.  Our effort to...

Incredible Demos

  • By
    Create a Download Package Using MooTools Moousture

    Zohaib Sibt-e-Hassan recently released a great mouse gestures library for MooTools called Moousture. Moousture allows you to trigger functionality by moving your mouse in specified custom patterns. Too illustrate Moousture's value, I've created an image download builder using Mooustures and PHP. The XHTML We provide...

  • By
    Introducing MooTools Templated

    One major problem with creating UI components with the MooTools JavaScript framework is that there isn't a great way of allowing customization of template and ease of node creation. As of today, there are two ways of creating: new Element Madness The first way to create UI-driven...

Discussion

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