A square and a rectangle have equal perimeters. The length of a side of the square is 4x-1. The length of the rectangle is 2x+2 and the width is 2x. Write and solve an equation to find x.