When setting cv2.VideoWriter, you need to set the fifth parameter to 0, indicating the grayscale image video_writer = cv2.VideoWriter('road_gray.mp4', cv2.VideoWriter_fourcc(*'mp4v'), fps, size, 0)
The size of cv2.VideoWriter needs to be the same as the size of the original image, and the format is width*height