FYI, I edited my previous comment. I simplified the function again
- only check frames once the buffer is at least 70,000 bytes, since my camera gives me frames that are 79,000
- removed unused variables, unneeded ‘repeat loop’, unneeded catch block
- use bool variables to as flags to identify a valid frame
- added comments to the code
- left commented code that lets you check your fps
- FYI my camera gives me about 30 frames per second, and each frame is 79k bytes