How can I get the resolution (width and height) fo

2019-01-13 20:19发布

I've been digging through the mplayer/mencoder and ffmpeg documentation and I can't seem to come up with anything. I'm not especially picky as to the output format as I can use a regular expression to pull it out, I just can't seem to get the data in the first place.

9条回答
甜甜的少女心
2楼-- · 2019-01-13 20:53

To return only the Width and Height mediainfo is an excellent tool.

mediainfo --Inform="Video;%Width%" Videofile && mediainfo --Inform="Video;%Height%" Videofile will do exactly that, no more, no less, for a vast array of supported video files.

There is a long list of useful Inform= parameters which you can obtain with the command mediainfo --Info-Parameters

If you want the output in standard WidthXHeight format use Width=$(mediainfo --Inform="Video;%Width%" Video.File)&& Height=$(mediainfo --Inform="Video;%Height%" Video.File)&&echo $Width"X"$Height

There's a bash script here that you could easily modify to meet your needs.

Sources:

Adding an Overlay Using FFMPEG With Minimal Re-Encoding

http://manpages.ubuntu.com/manpages/xenial/man1/mediainfo.1.html

whiptail: How to redirect output to environment variable?

How to concatenate string variables in Bash

查看更多
在下西门庆
3楼-- · 2019-01-13 20:56

Use ffprobe:

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

Example output:

1280x720

See FFprobe Documentation and FFmpeg Wiki: FFprobe Tips for more info.

查看更多
疯言疯语
4楼-- · 2019-01-13 20:56

If you are just interested in the resolution:

ffprobe -v error -of flat=s=_ -select_streams v:0 -show_entries stream=height,width video.mkv

It works also on Windows. This is running right now on my PC to build an index of all files:

find //Q1207/Film -size +10000k -print -a -exec ./ffprobe.exe -v error -of flat=s=_ -select_streams v:0 -show_entries stream=height,width \{\} \; > //Q1207/Film/index.txt
查看更多
登录 后发表回答