More cleanup; there's no good reason to estimate bitrate before starting file writing.  A good guess will suffice here, and having proper timestamps in the output file is more important.