When you check statistics, video consumption among users is increasing, which means video consumption is becoming part of daily life for people of all ages. So I thought, why not add a video of the performed steps, which will be very helpful for the reader to understand the steps?
For that reason, I started recording the output of the terminal using the inbuilt GNOME 42 screen recording features, but the problem for me was that I was unaware of the screencast or video width and height, so I was intrigued to know the height and width of the video through a terminal.
CLI users like me always charge up to perform all work through the terminal itself, and if you too are like me and want to find the width and height of video through the terminal, then this article will be more than enough to know.
Table of Contents
Find Video Width and Height from Terminal
It’s quite simple to find the width and height of the video from the terminal, you just need to have a prerecorded video and the FFmpeg package installed on your system.
Install FFmpeg utility
Most likely, you will find the FFmpeg libraries installed on your system because many applications like Chrome, OBS Studio, VLC, and others use the FFmpeg libraries like (libavcodec, libavutil, libavformat, libavfilter, libavdevice, libswscale, and libswresample) as dependencies to handle video and audio.
On the other hand, you can use the command line utilities ffmpeg, ffplay, and ffprobe from this list. We will use the ffprobe command to find the resolution of the video, which you need to install by running the following command.
Users of Ubuntu or Debian-based systems like Pop!_OS, Linux Mint, etc., need to run the below command to install FFmpeg.
$ sudo apt update && sudo apt upgrade $ sudo apt install ffmpeg
If you do have the latest version of a Red Hat-based OS like RockyLinux or AlmaLinux, then execute the following lines of command on your screen.
For any reason, if you are not able to find FFmpeg, then read the official documentation.
$ sudo dnf install --nogpgcheck https://dl.fedoraproject.org/pub/epel/epel-release-latest-$(rpm -E %rhel).noarch.rpm $ sudo dnf install --nogpgcheck https://mirrors.rpmfusion.org/free/el/rpmfusion-free-release-$(rpm -E %rhel).noarch.rpm https://mirrors.rpmfusion.org/nonfree/el/rpmfusion-nonfree-release-$(rpm -E %rhel).noarch.rpm $ sudo dnf install ffmpeg
Fedora-based users need to run the below command to install FFmpeg on your system.
$ sudo dnf makecache $ sudo dnf install ffmpeg-free
Users of Arch-based distributions like Garuda Linux and Manjaro Linux need to run the below command to install the FFmpeg package.
$ sudo pacman -Syu $ sudo pacman -Sy ffmpeg
Find Video Resolution using the ffprobe command
Once the installation is finished, you will use the ffprobe utility to discover the video resolution of the corresponding media, and you will also have multiple choices of format for how you want to print video resolution information on your screen.
So first, get familiar with command syntax.
$ ffprobe -v error -show_entries stream=width,height -of default=noprint_wrappers=1 /path/of/video
- -v error suppresses unwanted information except for any error.
- -show_entries stream=width, height from the video metadata to extract width and height information.
- -of as I said earlier, you can have output in various formats like default, XML, JSON, etc.
- /path/of/video specify the path of the video where it is located.
Print video resolution with variable names
To show you how to use the ffprobe command to find video resolution on your end, let me run the below command on my terminal screen, which will just print the size of the picture with a variable name for your easy understanding.
$ ffprobe -v error -show_entries stream=width,height -of default=noprint_wrappers=1 Videos/Screencasts/nala.webm
The behaviour of the above command.
Print video resolution without variable names
If you don’t want to print variable names, then you can run the below command.
$ ffprobe -v error -select_streams v -show_entries stream=width,height -of csv=p=0:s=x /path/of/video
Print video resolution in JSON format
As I said earlier, we can display the video resolution of a video in a couple of different ways, and one of them is to print video resolution information in JSON format, which can be helpful for programmers.
To display the output in JSON format, execute the below code.
$ ffprobe -v error -select_streams v -show_entries stream=width,height -of json Videos/Screencasts/nala.webm
The behaviour of the above command.
That’s all for now!
A man with a tech effusive who has explored some of the amazing technology stuff and is exploring more. While moving towards, I had a chance to work on Android development, Linux, AWS, and DevOps with several open-source tools.