Magnetic flux trapped during the cooldown of superconducting radio-frequency cavities through the transition temperature due to incomplete Meissner state is known to be a significant source of radio-frequency losses. The sensitivity of flux trapping depends on the distribution and the type of defects and impurities which pin vortices, as well as the cooldown dynamics when the cavity transitions from a normal to superconducting state. Here we present the results of measurements of the flux trapping sensitivity on 1.3 GHz elliptical cavities made from large-grain niobium with different purity for different cooldown dynamics and surface treatments. The results show that lower purity material results in a higher fraction of trapped flux. We present an overview of published data on the mean free path and frequency dependence of the trapped flux sensitivity which shows a significant scatter which highlights the complexity of the pinning phenomenon on a bulk superconductor with a large curved surface. We discuss contributions of different physical mechanisms to rf losses resulting from oscillations of flexible vortex segments driven by weak rf fields. In particular, we address the dependence of the rf losses on the mean free path in the cases of sparse strong pinning defects and collective pinning by many weak defects for different orientations of the vortex with respect to the inner cavity surface. This analysis shows that the effect of the line tension of vortices is instrumental in the physics of flux trapping and rf losses, and theoretical models taking into account different pinning strength and geometry of flexible pinned vortex segments can provide a good qualitative description of the experimental data.