Home Linux Commandline Tips How to Find Video Resolution (Width and Height) in Linux

How to Find Video Resolution (Width and Height) in Linux

Being characterized as a Linux user does not necessarily imply that we are constrained to a technical lifestyle. The advantage of using Linux as the go-to operating system has contributed to the career growth of content creators, video producers, and even online video streamers. Whether it is project-related or work-related, dealing with videos will always redirect us to the issue of video resolution.

[ You might also like: How to Check Video Files Formats in Linux ]

The video resolution of the video file you have access to determines its display clarity in terms of pixels. The more the pixels the clearer the video. Therefore, knowing the video resolution of your video files via Linux helps us determine whether we are dealing with a low-quality or high-quality video file.

Additionally, the video quality may be too high to be played on less performant hardware like mobile devices. Knowing the resolution may help us downsize the video file to accommodate the less performant devices.

Problem Statement

To make this tutorial interesting, we will reference the following video file:

Python_Backend_Web_Development_Course.mp4

Find Video Resolution Using ffmpeg Video Converter

The ffmpeg is an effective terminal-based video converter for various Linux operating system distributions. Reference the following ffmpeg installation commands for various Linux OS distributions.

Install ffmpeg in Linux

On RHEL-based distributions like RHEL 8, Rocky Linux, and AlmaLinux:

$ sudo dnf install https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm
$ sudo dnf upgrade
$ sudo subscription-manager repos --enable "rhel-*-optional-rpms" --enable "rhel-*-extras-rpms"
$ sudo yum update
$ sudo yum install snapd
$ sudo systemctl enable --now snapd.socket
$ sudo ln -s /var/lib/snapd/snap /snap
$ sudo snap install ffmpeg 

On Fedora Linux distribution:

$ sudo dnf makecache 
$ sudo dnf install ffmpeg-free

On Debian distributions like Ubuntu and Linux Mint:

$ sudo apt update && sudo apt upgrade -y
$ sudo apt install ffmpeg

On Arch Linux and Manjaro:

$ sudo pacman -Syu
$ sudo pacman -S ffmpeg

On OpenSUSE Leap:

$ sudo zypper refresh
$ sudo zypper install ffmpeg

On OpenSUSE Tumbleweed:

$ sudo zypper refresh
$ sudo zypper install ffmpeg-4

Find Video Resolution in Linux

The ffmpeg video converter utility is associated with a tool called ffprobe which gathers information associated with a targeted media file.

Its usage syntax is as follows:

$ ffprobe [options] [input_url]

We can use it to determine our sample file’s video resolution in the following manner:

$ ffprobe -v error -select_streams v:0 -show_entries stream=width,height -of csv=s=x:p=0 Python_Backend_Web_Development_Course.mp4
Find Video Resolution in Linux Using ffprobe
Find Video Resolution in Linux Using ffprobe

The commands options are as follows:

  • -v error ensures the terminal output is less verbose.
  • -select_streams v:0 picks first video stream.
  • -show_entries stream=width,height outputs width, and height resolution of the targeted video file.
  • -of csv=s=x:p=0 produces simple text output format.

Alternatively, you can also use the ffmpeg command to find out the video resolution as shown.

$ ffmpeg -i Python_Backend_Web_Development_Course.mp4 2>&1 | grep -oP 'Stream .*, \K[0-9]+x[0-9]+'

1280X720

The ffmpeg command above pipes its output to a grep command which implements some regular expression to output the final width X height resolution of the input video file.

We can now comfortably determine the video resolution (width and height) of a targeted video file for our Linux-based projects/work.

Ravi Saive
I am an Experienced GNU/Linux expert and a full-stack software developer with over a decade in the field of Linux and Open Source technologies. Founder of TecMint.com, LinuxShellTips.com, and Fossmint.com. Over 150+ million people visited my websites.

Each tutorial at UbuntuMint is created by a team of experienced writers so that it meets our high-quality standards.

Was this article helpful? Please add a comment to show your appreciation and support.

Got something to say? Join the discussion.

Thanks for choosing to leave a comment. Please keep in mind that all comments are moderated according to our comment policy, and your email address will NOT be published or shared. Please Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.