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
    An Interview with Eric Meyer

    Your early CSS books were instrumental in pushing my love for front end technologies. What was it about CSS that you fell in love with and drove you to write about it? At first blush, it was the simplicity of it as compared to the table-and-spacer...

  • By
    Vibration API

    Many of the new APIs provided to us by browser vendors are more targeted toward the mobile user than the desktop user.  One of those simple APIs the Vibration API.  The Vibration API allows developers to direct the device, using JavaScript, to vibrate in...

Incredible Demos

Discussion

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