Fixed audio and video writing, and audio codec flushing.