Thanks for your reply @ptrblck. That’s a very good suggestion. I created a DummyVideoCapture class to trick the script and that worked without problems, which means that the issue is indeed in the interaction between the OpenCV VideoCapture object and PyTorch.
Also, I found this article 1 which in one of the update points suggests that OpenCV VideoCapture may cause multithreaded reading to become stuck:

Use Thread in multithreading module instead of Process in muliprocessing module. When using Process and importing cv2.VideoCapture() as input argument, you may suffer reading stuck during retrieving frames from video stream. It seems to be related to the multi-processing mechanism in Python.

I’ll resign to using a custom class to create my batches and not using multithreaded reading yet.