title: Python OpenCV writing a video without losing frames during device crash
body: <p>I have the following basic algorithm for writing a video file -</p>
  <ol>
  <li>Create a cv2.VideoWriter() instance</li>
  <li>Camera is running in a loop</li>
  <li>Check if instruction was received to start writing video, if yes - For every new image, perform write() command on the VideoWriter instance to add new image to the video</li>
  <li>Check if instruction was received to stop writing video, if yes - run release() command on the VideoWriter instance to close the video file and perform some steps to be ready in case instruction for writing video is received again</li>
  </ol>
  <p>This works perfectly fine when the instructions for starting and stopping the video writing are received.</p>
  <p>However, there is a test condition in which the device which is running this code physically crashes into the wall and essentially would stop working unexpectedly. Obviously, in this case the instruction to stop writing video (from step 4) is not received and the last video on the device is always corrupt.</p>
  <p>Is there any way to prevent this? The video on the device (especially just before the crash) is quite important for analysis of the crash.</p>