S
S
Sacred702018-10-10 18:00:29
Python
Sacred70, 2018-10-10 18:00:29

How to determine the resolution of a movie using Python?

It is required to determine the resolution of the video clip before sending it for processing. How to do it via Python?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Sacred70, 2018-10-15
@Sacred70

import cv2
file_path = "./video.avi"
vid = cv2.VideoCapture( file_path )
height = vid.get(cv2.CAP_PROP_FRAME_HEIGHT)
width = vid.get(cv2.CAP_PROP_FRAME_WIDTH)

W
Web Dentist, 2018-10-10
@kgb_zor

from subprocess import Popen, PIPE
import re

def getvideodetails(filepath):
    cmd = 'ffmpeg -i %s" % filepath'
    p = Popen(cmd, shell=True, stdout=PIPE, stderr=PIPE)
    di = p.communicate()
    for line in di:
        if line.rfind("Video") > 0:
            resolution = re.findall("(\d+x\d+)", line)[0]
    return resolution


getvideodetails("путь к видео")

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question