从ffmpeg获取视频尺寸/分辨率/宽度x高度 [英] Getting video dimension / resolution / width x height from ffmpeg

查看:1408
本文介绍了从ffmpeg获取视频尺寸/分辨率/宽度x高度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何从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 video.mp4
...
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'video.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 处理大多数格式在那里.

Have a look at mediainfo Handles most of the formats out there.

如果您正在寻找一种解析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单行代码不如perl易记:-)

Python one-liners aren't as catchy as perl ones :-)

这篇关于从ffmpeg获取视频尺寸/分辨率/宽度x高度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆