Ensure proper termination of the video thread