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>