The formation of petroleum takes millions of years.
It is formed when the dead remains of animals are below the surface of the earth.
As these dead remains are subjected to heat and pressure, they get decomposed and liquefied. This liquid form of organic matter is petroleum or crude oil.
It can be obtained by digging oil wells and refining the oil to yield several products or fractions.
The dying aquatic animals get submerged and get decomposed on the sea bed. They also form petroleum under similar conditions.