Delay closing output file until after the encoder is flushed

Applies only when in file only mode or with stream paused while file
output is enabled

Still need to evaluate not closing the file prematurely while stream is
active with a large number of buffered frames in the encoder