从ffmpeg -i获取视频维度 [英] Getting video dimension from ffmpeg -i
本文介绍了从ffmpeg -i获取视频维度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何从 ffmpeg
的信息输出中获取视频的高度和宽度。例如,使用以下输出 -
How would I get the height and width of a video from ffmpeg
's information output. For example, with the following output --
$ ffmpeg -i 1video.mp4
...
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '/Users/david/Desktop/1video.mp4':
Metadata:
major_brand : isom
minor_version : 1
compatible_brands: isomavc1
creation_time : 2010-01-24 00:55:16
Duration: 00:00:35.08, start: 0.000000, bitrate: 354 kb/s
Stream #0.0(und): Video: h264 (High), yuv420p, 640x360 [PAR 1:1 DAR 16:9], 597 kb/s, 25 fps, 25 tbr, 25k tbn, 50 tbc
Metadata:
creation_time : 2010-01-24 00:55:16
Stream #0.1(und): Audio: aac, 44100 Hz, stereo, s16, 109 kb/s
Metadata:
creation_time : 2010-01-24 00:55:17
At least one output file must be specified
如何获得 height = 640,width = 360
?谢谢。
推荐答案
看看 mediainfo 处理大多数格式。
如果您要寻找解析ffmpeg输出的方法,请使用regexp \d + x\d +
If you looking for a way to parse the output from ffmpeg, use the regexp \d+x\d+
使用perl的示例:
$ ./ffmpeg -i test020.3gp 2>&1 | perl -lane 'print $1 if /(\d+x\d+)/'
176x120
使用python(不完美)的示例:
Example using python (not perfect):
$ ./ffmpeg -i /nfshome/enilfre/pub/test020.3gp 2>&1 | python -c "import sys,re;[sys.stdout.write(str(re.findall(r'(\d+x\d+)', line))) for line in sys.stdin]"
[] [] [] [] [] [] [] [] [] [] [] [ ] [] [] [] [] [] [] [] [] ['176x120'] [] [] []
[][][][][][][][][][][][][][][][][][][]['176x120'][][][]
Python one-liners不那么引人入胜作为perl: - )
Python one-liners aren't as catchy as perl ones :-)
这篇关于从ffmpeg -i获取视频维度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文