Releasing video inside while loop

Hi, im trying to do something quiet simple… i need to start recording video on specifique threshold mean value calculated from a still picture taken of the desired event to trigger the recording.

Everything work as it should but when i come to the point of releasing the Video its an empty shell… The file get created but nothing get saved to it.

I noticed that if i BREAK and get out of the Main While Loop the video is properly saved.

i added the XXXX.release() in a def inside my main class but even there it create an empty shell only BREAK seem to finalise the recording…

anyone had that issue or have any idea ?

Please share your code. Be sure your image size is correctly defined by VideoWriter