Added cleanup code at the beginning to protect against a bug.

bug fixed: A non-clean prior exit can cause the mixing of frames
from different videos.