首页 > 解决方案 > 从 ffpmeg 获取视频分辨率

问题描述

我尝试获取视频文件的分辨率,并希望此代码对来自GitHub的arionik有所帮助

from subprocess import Popen, PIPE

def getWH(pathvideofile):
in_pipe = Popen(["ffmpeg", "-i", "\"%s\"" % (pathvideofile)], stderr=PIPE)
lines = in_pipe.stderr.readlines()
for line in lines:
    rx = re.compile('.+Video.+, (\d{2,4})x(\d{2,4}).+')
    m = rx.match(line)
    if m is not None:
        w = int(m.group(1))
        h = int(m.group(2))
return w, h

但是得到这个错误代码:

m = rx.match(line)
TypeError: cannot use a string pattern on a bytes-like object

它可能是什么?

谢谢,

标签: pythonregexffmpegsubprocess

解决方案


推荐阅读