encodes and writes segments and m3u8 index