Getting video dimension / resolution / width x height from ffmpeg

前端 未结 8 1575
粉色の甜心
粉色の甜心 2020-11-27 05:33

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         


        
8条回答
  •  盖世英雄少女心
    2020-11-27 06:03

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

    If you looking for a way to parse the output from ffmpeg, use the regexp \d+x\d+

    Example using perl:

    $ ./ffmpeg -i test020.3gp 2>&1 | perl -lane 'print $1 if /(\d+x\d+)/'
    176x120
    

    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'][][][]

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

提交回复
热议问题