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
    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...

  • By
    Send Text Messages with PHP

    Kids these days, I tell ya.  All they care about is the technology.  The video games.  The bottled water.  Oh, and the texting, always the texting.  Back in my day, all we had was...OK, I had all of these things too.  But I still don't get...

Incredible Demos

Discussion

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