added code to terminate the connection if problems encoding video