1. An image processing apparatus comprising: an obtainment unit that obtains a plurality of images obtained by shooting a subject at different positions, at each of a plurality of timings; a first detection unit that detects a phase difference between the images obtained at the same timing; a second detection unit that detects a phase difference between the images obtained at the same position but at different timings; and a generating unit that generates an output image by synthesizing at least some of the images obtained by the obtainment unit so that at least one of the phase differences between the some of the images, which are detected by the first detection unit and the second detection unit, is reduced, wherein in the case of a setting for generating an image corresponding to a long-exposure shooting, the generating unit adjusts an exposure amount and a depth of field of the output image by controlling shot positions and obtained timings of images used for the synthesis.