How to Get Video Resolution with ffprobe: From Basic Commands to Batch Processing

This guide is brought to you by filethings.net — whether you're adapting videos for different devices, organizing media libraries, or transcoding footage, obtaining accurate video resolution is a fundamental first step. ffprobe from the FFmpeg toolkit acts like a precision measuring instrument, quickly parsing media metadata to extract width and height information without decoding the entire video, streamlining your video processing workflow.

Unlike Getting Video Metadata with ffprobe, this article focuses specifically on advanced resolution extraction techniques, including basic commands, parameter breakdowns, batch processing, and special case resolution calculations.

Resolution Extraction Principles 🔍

ffprobe extracts stream information by parsing media container formats (MP4, MKV, AVI, etc.) without decoding the entire video, making it highly efficient. Video files typically contain multiple streams: video, audio, subtitles, and more.

To obtain resolution, ffprobe follows this workflow:

  1. Identify all stream types in the file
  2. Locate the video stream (usually the first video stream, marked as v:0)
  3. Extract width and height parameters from the video stream metadata
  4. Format output according to user specifications

This non-decoding approach not only delivers speed but also handles corrupted or partially downloaded video files.

Quick Start: Basic Commands ⚡

The simplest command to get resolution for a single video file:

ffprobe -v error -select_streams v:0 -show_entries stream=width,height -of csv=s=x:p=0 input.mp4

Parameter Explanation

Output Example

1920x1080

This command returns the video resolution directly in widthxheight format, ideal for scripting purposes.

Advanced Applications: Resolution Extraction Techniques 🚀

1. JSON Output (for Programmatic Processing)

For scenarios requiring programmatic result handling, JSON format provides structured output that's easier to parse:

ffprobe -v error -select_streams v:0 -show_entries stream=width,height -of json input.mp4

Output:

{
    "programs": [],
    "streams": [
        {
            "width": 1920,
            "height": 1080
        }
    ]
}

2. Getting Aspect Ratio Information

Beyond basic resolution, you may need to know the video's aspect ratio:

ffprobe -v error -select_streams v:0 -show_entries stream=width,height,sample_aspect_ratio -of json input.mp4

Output example:

{
    "programs": [],
    "streams": [
        {
            "width": 1920,
            "height": 1080,
            "sample_aspect_ratio": "1:1"
        }
    ]
}

3. Working with Files Containing Multiple Video Streams

Certain container formats (like MKV) may contain multiple video streams. You can specify the stream index to get resolution for a specific stream:

# Get resolution of the second video stream
ffprobe -v error -select_streams v:1 -show_entries stream=width,height -of csv=s=x:p=0 input.mkv

4. Batch Resolution Extraction for Multiple Files

When working with numerous video files, batch operations save significant time:

# Process all MP4 files in current directory
echo "File,Resolution" > video_resolutions.csv
for file in *.mp4; do
    resolution=$(ffprobe -v error -select_streams v:0 -show_entries stream=width,height -of csv=s=x:p=0 "$file")
    echo "$file,$resolution"
    echo "$file,$resolution" >> video_resolutions.csv
done

5. Batch Processing on Windows

Windows users can achieve similar functionality using PowerShell:

Get-ChildItem -Filter *.mp4 | ForEach-Object {
    $resolution = ffprobe -v error -select_streams v:0 -show_entries stream=width,height -of csv=s=x:p=0 $_.FullName
    Write-Output "$($_.Name): $resolution"
}

Frequently Asked Questions ❓

Q: No output or errors when executing commands?

A: Possible causes and solutions:

Q: How to get actual displayed resolution after rotation?

A: Videos shot on mobile devices or cameras may contain rotation metadata (typically 90°, 180°, or 270°). In these cases, combine the rotate parameter to determine actual displayed resolution:

ffprobe -v error -select_streams v:0 -show_entries stream=width,height,rotate -of csv=s=x:p=0 input.mp4

If output includes rotation angle (e.g., 1920x1080x90), the actual displayed resolution would be 1080x1920 (width and height swapped).

Q: How to distinguish between stored resolution and displayed resolution?

A: Stored resolution refers to the actual encoded pixel dimensions (width×height) in the video file, while displayed resolution may differ due to aspect ratio, rotation, or scaling. Use this command to get both:

ffprobe -v error -select_streams v:0 -show_entries stream=width,height,display_aspect_ratio,rotate -of json input.mp4

Q: How to batch process different video formats?

A: Extend the bash script to handle multiple video formats using wildcards:

# Process all video files in current directory
for file in *.{mp4,mkv,avi,mov}; do
    if [ -f "$file" ]; then
        resolution=$(ffprobe -v error -select_streams v:0 -show_entries stream=width,height -of csv=s=x:p=0 "$file")
        echo "$file: $resolution"
    fi
done

Q: How to get other video information (frame rate, codec format)?

A: Simply extend the -show_entries parameter:

# Get resolution, frame rate, and codec format
ffprobe -v error -select_streams v:0 -show_entries stream=width,height,r_frame_rate,codec_name -of csv=s=x:p=0 input.mp4

Quick Reference 📋

Here's a summary of the core commands introduced in this article for quick lookup:

FunctionCommand
Basic resolutionffprobe -v error -select_streams v:0 -show_entries stream=width,height -of csv=s=x:p=0 input.mp4
JSON outputffprobe -v error -select_streams v:0 -show_entries stream=width,height -of json input.mp4
Aspect ratio informationffprobe -v error -select_streams v:0 -show_entries stream=width,height,sample_aspect_ratio -of json input.mp4
Specific stream resolutionffprobe -v error -select_streams v:1 -show_entries stream=width,height -of csv=s=x:p=0 input.mkv
Check rotation angleffprobe -v error -select_streams v:0 -show_entries stream=width,height,rotate -of csv=s=x:p=0 input.mp4
Stored vs displayed resolutionffprobe -v error -select_streams v:0 -show_entries stream=width,height,display_aspect_ratio,rotate -of json input.mp4
Extended video informationffprobe -v error -select_streams v:0 -show_entries stream=width,height,r_frame_rate,codec_name -of csv=s=x:p=0 input.mp4