Hey all, I have looked but don’t see any solid answers for this. I’m using opencv to do a specific job of cutting thumbs from video streams, then processing those thru several different AI systems.
The way I currently use it, I take the total frames, divide by number of CPUs in the system and then process the video as 12 (current CPU count) threads. I set a cv2.CAP_PROP_POS_FRAMES, start_frame for each of the threads.
Threads 2-12 work as expected, regardless of the frame I specify as the start frame it starts at exactly that frame.
Thread 1 however doesn’t, sometimes it properly starts at frame 0, but often it starts 1 second in to the video but thinks that it is at frame 0.
If I set start_frame to any value between 0-30 it always takes frame 30 and marks it as 0. If however I specify 31, 37, 42, etc it starts at exactly that frame. Which is also why all 11 other threads are picking up on exactly the correct thread.
In further testing, if I just negate the cv2.CAP_PROP_POS_FRAMES option, it starts at 0 and processes properly. So the bug/glitch/thing I don’t want, seems to only happen IF I set CAP_PROP_POS_FRAMES and set start_frame=0
In theory it makes sense (sorta) that it would go to the first key frame that is at 1 second, but why doesn’t it so that when PROP_POS_FRAMES is not set? Why doesn’t it search for a keyframe when I give it a start frame of 3001 (or any number after that first key frame).
I think most importantly, how do I get to a place where I can count on it starting at 0?
Thanks in advance!
def process_video(start_frame, frame_partition, cudaProc, ar): print("START FRAME: ", start_frame) cap = cv2.VideoCapture(args.s3url) frameRate = cap.get(5) # Get the frame rate from the video frameCutRate = frameRate / 12 # we set to X frames per second cap.set(cv2.CAP_PROP_POS_FRAMES, start_frame) while(cap.isOpened()): frameId = int(cap.get(1)) # get current frame ID print("FRAME ID:", frameId) if (frameId > start_frame + frame_partition - 1): #print("reached end of looop for start_frame: ", start_frame) break ret, frame = cap.read() if (ret != True): print("ret does not equal True:", ret) break ----- Write frame to s3/etc....