Skip to content

Instantly share code, notes, and snippets.

@hmahadik
Created September 11, 2020 14:58
Show Gist options
  • Save hmahadik/52cbd4f0a50ec6912f228077969cb4b4 to your computer and use it in GitHub Desktop.
Save hmahadik/52cbd4f0a50ec6912f228077969cb4b4 to your computer and use it in GitHub Desktop.
Easy way to measure how long it takes to decode frames using OpenCV's VideoCapture class
import cv2
import time
def measureDecodeTimeMs(src):
cap = cv2.VideoCapture(src)
for i in range(10):
a = time.time()
ok, frame = cap.read()
if not ok:
print("Error: Unable to read frame")
return
b = time.time()
print("Time: {}ms".format(1000*(b-a)))
measureDecodeTimeMs("videotestsrc ! appsink")
measureDecodeTimeMs("videotestsrc ! videoscale ! video/x-raw,width=1920,height=1080 ! appsink")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment