1

I try to get resolution of a video file, and hope this code would help thanks to arionik from GitHub

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

But get this error code:

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

What it could be?

Thank you,

MertTheGreat
  • 500
  • 1
  • 7
  • 20
  • 2
    Don't use `ffmpeg` - use `ffprobe`, it's intended precisely for that and you can define its output format so you don't need to do much parsing on the Python side. For example, `ffprobe -loglevel quiet -select_streams v:0 -show_entries stream=width,height -of csv=p=0 filename.mp4` will just print out the resolution of `filename.mp4` in `width,height` format to STDOUT. – zwer May 21 '18 at 22:44
  • 1
    Yes, use `ffprobe` instead. See [this `ffprobe` example](https://stackoverflow.com/a/27831698/1109017) if you want output formatted as `widthxheight`, such as `1280x720`. – llogan May 22 '18 at 00:08

0 Answers0