added capture stream to file function