Do the encoding with a temporary file. This prevents clients watching the final output directory from seeing the file until it is done.