start to rewrite the encoding/streaming process