Thermal barrier coatings (TBCs) play a crucial role in safeguarding aero-engine blades from high-temperature environments and enhancing their performance and durability. Accurate evaluation of TBCs’ porosity is of paramount importance for aerospace material research. However, existing evaluation methods often involve destructive testing or lack precision. In this study, we proposed a novel nondestructive evaluation method for TBCs’ porosity, utilizing terahertz time-domain spectroscopy (THz-TDS) and a machine learning approach. The primary objective was to achieve reliable and precise porosity evaluation without causing damage to the coatings. Multiple feature parameters were extracted from THz-TDS data to characterize porosity variations. Additionally, correlation analysis and p-value testing were employed to assess the significance and correlations among the feature parameters. Subsequently, the dung-beetle-optimizer-algorithm-optimized random forest (DBO-RF) regression model was applied to accurately predict the porosity. Model performance was evaluated using K-fold cross-validation. Experimental results demonstrated the effectiveness of our proposed method, with the DBO-RF model achieving high precision and robustness in porosity prediction. The model evaluation revealed a root-mean-square error of 1.802, mean absolute error of 1.549, mean absolute percentage error of 8.362, and average regression coefficient of 0.912. This study introduces a novel technique that presents a dependable nondestructive testing solution for the evaluation and prediction of TBCs’ porosity, effectively monitoring the service life of TBCs and determining their effectiveness. With its practical applicability in the aerospace industry, this method plays a vital role in the assessment and analysis of TBCs’ performance, driving progress in aerospace material research.