One liner ffmpeg (or other) to get only resolution?

Using ffprobe from the ffmpeg package:

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

Example result:

1280x720

What these options do:

  • -v error makes the output less verbose.
  • -select_streams v:0 selects only the first video stream.
  • -show_entries stream=width,height chooses only width and height from the big list of parameters that ffprobe can provide.
  • -of csv=s=x:p=0 formats the text output. The csv formatting type is used because it makes a simple output. s=x makes it use an x to separate the width and height values. p=0 makes it omit the stream prefix in the output.

See the ffprobe documentation and FFmpeg Wiki: ffprobe tips for more info.


Get video resolution with ffmpeg:

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

Output (e.g.):

640x480

exiftool -b metavideo.mp4 -ImageWidth
exiftool -b metavideo.mp4 -ImageHeight

do the job without any greps

One-liner looks like:

exiftool -b metavideo.mp4 -ImageSize

That returns WxH string that you was looking for.