refactor encoding to be always ahead of playhead