Hi, After I had to reinstall my Anaconda version I have now an issue with jumping within a video file.
I am using vs.set(cv2.CAP_PROP_POS_FRAMES, framei)
and it take really long time to perform. And it is relevant from where to where I jump.
Below you can find a test code show the problem.
First I just read in 600 frames ==> 11.78 s
Then I make trials with the jumps: from frame 0 to 600 ==> 6.6s
then from 600 to 1200 ==> 12.8s
Then I make the same but just with the retrieve command which is roughly half the time of reading.
Any idea why the vs.set(cv2.CAP_PROP_POS_FRAMES, framei)
command is such slow?
Also just see the warning in the output with the GStreamer. even I don’t asked to do anything with it, I have this warning.
Setup is following:
- Windows 11
- Anaconda 2.3.1,
- with an environment using Python 3.9.15
- OpenCV 4.6.0, just installed in anaconda
Here the code:
import cv2
import time
filename = "E:/DaVinciResolveProjects/20221208_OffsetSystem/20230115_2157/20230115_2157.mkv"
vs = cv2.VideoCapture(filename)
############################################################
print('Task: read 600 frames')
framei = 0
tic = time.time()
while framei< 600:
framei = framei + 1
ret, frame = vs.read()
toc = time.time()
print(str(round(toc-tic,3))+'s - '+str(round(600/(toc-tic),3))+'fps')
############################################################
print(' ')
print('Task: Jump from frame 0 to 600')
# rewind back to 0
framei = 0
vs.set(cv2.CAP_PROP_POS_FRAMES, framei)
tic = time.time()
# jump to 600
framei = 600
vs.set(cv2.CAP_PROP_POS_FRAMES, framei)
toc = time.time()
print(str(round(toc-tic,3))+'s - '+str(round(600/(toc-tic),3))+'fps')
############################################################
print(' ')
print('Task: Jump from frame 600 to 1200')
tic = time.time()
# now jump to 1200
framei = 1200
vs.set(cv2.CAP_PROP_POS_FRAMES, framei)
toc = time.time()
print(str(round(toc-tic,3))+'s - '+str(round(600/(toc-tic),3))+'fps')
############################################################
print(' ')
print('Task: Jump from frame 1200 to 1800')
tic = time.time()
# now jump to 1800
framei = 1800
vs.set(cv2.CAP_PROP_POS_FRAMES, framei)
toc = time.time()
print(str(round(toc-tic,3))+'s - '+str(round(600/(toc-tic),3))+'fps')
############################################################
print(' ')
print('Task: Jump back from frame 1200 to 0')
tic = time.time()
# now jump to 0
framei = 0
vs.set(cv2.CAP_PROP_POS_FRAMES, framei)
toc = time.time()
print(str(round(toc-tic,3))+'s - '+str(round(1200/(toc-tic),3))+'fps')
############################################################
print(' ')
print('Task: grab 600 frames')
framei = 0
tic = time.time()
while framei< 600:
framei = framei + 1
ret = vs.grab()
toc = time.time()
print(str(round(toc-tic,3))+'s - '+str(round(600/(toc-tic),3))+'fps')
############################################################
print(' ')
print('Task: continue grab from frame 600-1200')
tic = time.time()
while framei< 1200:
framei = framei + 1
ret = vs.grab()
frame = vs.retrieve()
toc = time.time()
print(str(round(toc-tic,3))+'s - '+str(round(600/(toc-tic),3))+'fps')
This is the output:
[ WARN:0@7115.629] global C:\b\abs_74oeeuevib\croots\recipe\opencv-suite_1664548340488\work\modules\videoio\src\cap_gstreamer.cpp (2386) cv::handleMessage OpenCV | GStreamer warning: your GStreamer installation is missing a required plugin
[ WARN:0@7115.629] global C:\b\abs_74oeeuevib\croots\recipe\opencv-suite_1664548340488\work\modules\videoio\src\cap_gstreamer.cpp (2402) cv::handleMessage OpenCV | GStreamer warning: Embedded video playback halted; module uridecodebin22 reported: Your GStreamer installation is missing a plug-in.
[ WARN:0@7115.629] global C:\b\abs_74oeeuevib\croots\recipe\opencv-suite_1664548340488\work\modules\videoio\src\cap_gstreamer.cpp (1356) cv::GStreamerCapture::open OpenCV | GStreamer warning: unable to start pipeline
[ WARN:0@7115.629] global C:\b\abs_74oeeuevib\croots\recipe\opencv-suite_1664548340488\work\modules\videoio\src\cap_gstreamer.cpp (862) cv::GStreamerCapture::isPipelinePlaying OpenCV | GStreamer warning: GStreamer: pipeline have not been created
Task: read 600 frames
11.954s - 50.192fps
Task: Jump from frame 0 to 600
6.765s - 88.698fps
Task: Jump from frame 600 to 1200
13.195s - 45.473fps
Task: Jump from frame 1200 to 1800
19.359s - 30.993fps
Task: Jump back from frame 1200 to 0
0.056s - 21424.104fps
Task: grab 600 frames
6.892s - 87.063fps
Task: continue grab from frame 600-1200
11.251s - 53.331fps