简体   繁体   English

检测视频中的媒体分辨率变化

[英]Detect media resolution change in video

I tried to search in SO but could not find.I want to iterate video file frame by frame and want to detect if there is any point when resolution of two consecutive frame changes. 我试图在SO中搜索,但找不到。我想逐帧迭代视频文件,并想检测两个连续帧的分辨率变化时是否有任何意义。 The desired functionality in pseudocode: 所需的伪代码功能:

resolution1 = videoFile[0]->resolution
resolution2 = 0;
for frame in videoFile[1:]:
    resolution2 = frame->resolution
    if (resolution1 != resolution2):
        print 'Changes occured'
    else:
        resolution1 = resolution2

Please give me the name of a library to implement them, I have tried and read documentation of OpenCV and PiCamera. 请给我一个实现它们的库的名称,我已经尝试过阅读OpenCV和PiCamera的文档。 Thanks in advance 提前致谢

You should use OpenCV to iterate through each frame. 您应该使用OpenCV遍历每个帧。 This should print "Changes occured" whenever the video changes resolution: 每当视频更改分辨率时,都应打印“ Changes when created”:

import cv2

capture1 = cv2.VideoCapture('videoname') #Open the video

ret, frame = capture1.read() #Read the first frame

resolution1 = frame.shape #Get resolution

while capture1.isOpened():
    ret, frame = capture1.read() #Read the next frame
    if ret == False or frame == None:
        break #Quit if video ends

    resolution2 = frame.shape #Get the new resolution

    if resolution1 != resolution2:
        print 'Changes occured'
        #Change resolution1 to resolution2 so that the new resolutions are
        #compared with resolution2, not resolution1.
        resolution1 = resolution2

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM