Use ffprobe
For example:
ffprobe -v error -select_streams v:0 -show_entries stream=width,height -of csv=s=x:p=0 input.mp4
Output in the format:
1280x720
Examples of other output formatting choices
See -of option documentation for more choices and options. Also see FFprobe Tips for other examples including duration and frame rate.
Default With No [STREAM] Wrapper
ffprobe -v error -select_streams v:0 -show_entries stream=width,height -of default=nw=1 input.mp4
Output in the format:
width=1280
height=720
Default With No Key
ffprobe -v error -select_streams v:0 -show_entries stream=width,height -of default=nw=1:nk=1 input.mp4
Output in the format:
1280
720
CSV
ffprobe -v error -select_streams v:0 -show_entries stream=width,height -of csv=p=0 input.mp4
Output in the format:
1280,720
JSON
ffprobe -v error -select_streams v:0 -show_entries stream=width,height -of json input.mp4
Output in the format:
{
"programs": [
],
"streams": [
{
"width": 1280,
"height": 720
}
]
}
XML
ffprobe -v error -select_streams v:0 -show_entries stream=width,height -of xml input.mp4
Output in the format:
<?xml version="1.0" encoding="UTF-8"?>
<ffprobe>
<programs>
</programs>
<streams>
<stream width="1280" height="720"/>
</streams>
</ffprobe>
evalis risky and not really necessary for this. http://stackoverflow.com/questions/17529220/why-should-eval-be-avoided-in-bash-and-what-should-i-use-instead – Nathaniel M. Beaver Oct 12 '16 at 17:25evalin the answer has been eliminated for a super simple solution that I somehow missed despite staring at the documentation for years. – llogan Mar 28 '18 at 18:33{ "programs": [ { "streams": [ { "width": 640, "height": 360 } ] } ], "streams": [ { "width": 640, "height": 360 } ] }– Salem F May 30 '18 at 21:51| sort -nur | head -n 1. This returns the resolution with the largest width. That being said, in all cases I've ever seen, there is only one resolution, but that may be duplicated. – Cyker Jul 22 '18 at 03:38ffprobejust once. Possible? – Ωmega Δ Jan 28 '20 at 20:05ffprobe -v error -sexagesimal -show_entries stream=width,height:format=duration -of default=nw=1 input.mp4– llogan Jan 28 '20 at 20:15ffprobe -v error -select_streams v:0 -show_entries stream=width,height,duration -of csv=s=x:p=0 -sexagesimal input.mp4, but I would like to change separators=xto a standard space character. I cannot find documentation how to use space character incsvparameter. Please advise. Thanks – Ωmega Δ Jan 28 '20 at 20:27-of "csv=s=\ :p=0"– llogan Jan 28 '20 at 21:11