Hi Guyz,
In this tutorial, I will discuss the video properties and how to view the video properties of any video file using OpenCV.
A video file contains different types of properties like width, height, frames, etc. Sometimes it is required to take out these basic video details. In order to make this work, easy OpenCV comes with built-in properties to ease out the work for developers.
video = cv.VideoCapture("video.mp4")video.get(0)
OpenCV has a function named get(propId).
Which takes property Identifier as an argument.
There are total 22 property identifiers that OpenCV supports.
One can also modify the properties of video file using set function.
This function takes two arguments.
1. Index
2. Property Identifier
In case, You want to modify the width and height of the video file.
video.set(3,320) # Width
video.set(4,480) # Height
Program
#import cv2 moduleimport cv2 as cv#This function shows the properties of a video filedef showProperties(): print('Current position - '+str(video.get(0))) print('Frames POS - '+str(video.get(1))) print('Ratio - '+str(video.get(2))) print('Width - '+str(video.get(3))) print('Height - '+str(video.get(4))) print('FPS - '+str(video.get(5))) print('FOURCC - '+str(video.get(6))) print('Frame Count - '+str(video.get(7))) print('Format - '+str(video.get(8))) print('Mode - '+str(video.get(9))) print('Brightness - '+str(video.get(10))) print('Contrast - '+str(video.get(11))) print('Saturation - '+str(video.get(12))) print('Hue - '+str(video.get(13))) print('Gain - '+str(video.get(14))) print('Exposure - '+str(video.get(15))) print('Convert RGB - '+str(video.get(16))) print('White Balance U - '+str(video.get(17))) print('White Balance V - '+str(video.get(18))) print('Rectification - '+str(video.get(19))) print('ISO SPEED - '+str(video.get(20))) print('Buffer Size - '+str(video.get(21))) while True: ret,frame = video.read() cv.imshow('video',frame) if cv.waitKey(30) & 0xFF == ord('q'): #Click q key will trigger this function. showProperties() breakvideo.release()cv.destroyAllWindows()
Don’t forget to check my other OpenCV Tutorials
Thanks for reading 🙂 🙂
Comments
Post a Comment