Conventional differential-threshold methods and machine-learning-based approaches often fail to guarantee both accuracy and real-time performance in heart rate variability (HRV) prediction. To address this issue, this paper proposes a heartbeat abnormality classification algorithm that integrates dynamic parameter feature extraction with a random forest classifier for fast and accurate electrocardiogram (ECG) analysis. First, raw ECG data are cleaned by digital filtering to obtain noise-suppressed signals, and dynamic thresholds are computed based on the heartbeats in the most recent 10 seconds. Second, a composite threshold score is calculated from the dynamic thresholds and current beat features to locate the QRS complex, followed by a local search for refinement. Finally, temporal feature vectors are constructed from the most recent heartbeats and fed into a pre-trained random forest model to obtain heartbeat abnormality classification results. Experimental results demonstrate that, compared with traditional differential-threshold algorithms and machine-learning-based methods, the proposed algorithm achieves both high accuracy and real-time performance in HRV prediction. On record 100 of the MIT-BIH Arrhythmia Database, the proposed method attains an accuracy of 99.65% and a sensitivity of 99.54%. Thus, relative to conventional differential-threshold and machine-learning-based approaches, the proposed algorithm maintains real-time capability while simultaneously achieving high classification accuracy.