Added video writing functionality