fix multithread and encoding