The following commands rely purely on ffmpeg
(and grep
and cut
) to get you the height or width as required:
Height:
$ ffmpeg -i video.mp4 2>&1 | grep Video: | grep -Po '\d{3,5}x\d{3,5}' | cut -d'x' -f1
1280
Width:
$ ffmpeg -i video.mp4 2>&1 | grep Video: | grep -Po '\d{3,5}x\d{3,5}' | cut -d'x' -f2
720
The difference between the two is just the -f
parameter to cut
.
If you prefer the full resolution string, you don't need cut
:
$ ffmpeg -i video.mp4 2>&1 | grep Video: | grep -Po '\d{3,5}x\d{3,5}'
1280x720
Here's what we're doing with these commands:
- Running
ffmpeg -i
to get the file info.
- Extracting the line which just contains
Video:
information.
- Extracting just a string that looks like
digitsxdigits
which are between 3 and 5 characters.
- For the first two, cutting out the text before or after the
x
.
Using
– Nathaniel M. Beaver – 2016-10-12T17:25:23.330eval
is risky and not really necessary for this. http://stackoverflow.com/questions/17529220/why-should-eval-be-avoided-in-bash-and-what-should-i-use-instead1@bariumbitmap Thanks.
eval
in the answer has been eliminated for a super simple solution that I somehow missed despite staring at the documentation for years. – llogan – 2018-03-28T18:33:25.997I got two result with that command
{ "programs": [ { "streams": [ { "width": 640, "height": 360 } ] } ], "streams": [ { "width": 640, "height": 360 } ] }
– Salem F – 2018-05-30T21:51:12.9871@SalemF Append
| 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 – 2018-07-22T03:38:13.697Could you please advise how to get simple output of the video length? Thanks – Ωmega Δ – 2020-01-28T12:37:30.777
@ΩmegaΔ See How to get video duration in seconds?
– llogan – 2020-01-28T18:07:17.853@llogan - I would like to print them together (resolution and sexagesimal length) with running
ffprobe
just once. Possible? – Ωmega Δ – 2020-01-28T20:05:34.560@ΩmegaΔ
ffprobe -v error -sexagesimal -show_entries stream=width,height:format=duration -of default=nw=1 input.mp4
– llogan – 2020-01-28T20:15:04.300@llogan - I used
ffprobe -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=x
to a standard space character. I cannot find documentation how to use space character incsv
parameter. Please advise. Thanks – Ωmega Δ – 2020-01-28T20:27:40.690@ΩmegaΔ
-of "csv=s=\ :p=0"
– llogan – 2020-01-28T21:11:34.053@llogan - Genius! Thank you!!! – Ωmega Δ – 2020-01-28T21:53:47.270