This work deals with the inverse problem in epidemiology based on a SIR model with time-dependent infectivity and recovery rates, allowing for a better prediction of the long term evolution of a pandemic. The method is used for investigating the COVID-19 spread by first solving an inverse problem for estimating the infectivity and recovery rates from real data. Then, the estimated rates are used to compute the evolution of the disease. The time-depended parameters are estimated for the World and several countries (The United States of America, Canada, Italy, France, Germany, Sweden, Russia, Brazil, Bulgaria, Japan, South Korea, New Zealand) and used for investigating the COVID-19 spread in these countries.