Add videowriter thread
Some optimizations