This study investigated the effects of environmental changes on zebrafish larval behavior, using single-factor and orthogonal experiments to assess locomotion during temperature and pH changes. In single-factor experiments, zebrafish larvae were exposed to variations in temperature (22 to 30 °C) and pH levels (6.0, 7.0, 9.0). The simultaneous temperature and pH changes were investigated by orthogonal tests. In both experiments, each zebrafish larva was recorded in three 5 min videos at different stages (before exposure, during short-term exposure (10 min), and after long-term exposure (60 min)). You Look Only Once (YOLOv5) and Deep Simple Online Real Time Tracking (DeepSORT) models were adopted to develop a zebrafish larva tracking system, and YOLOv5 was improved in two aspects of anchor clustering and network structure. The tracking accuracy of the tracking system for small targets effectively improved, reaching more than 98% MOTA (Multiple Object Tracking Accuracy). Principal Component Analysis (PCA) was employed to extract three behavioral features from 13 motion parameters, namely motion activity, edge behavior, and motion direction preference. Our findings reveal that lower temperatures and acidic conditions both led to a decrease in motion behavioral activity, and the former also increased edge behavior. Conversely, elevated temperatures and alkaline conditions had a muted impact on these behaviors. Interestingly, concurrent changes in temperature and pH significantly altered directional preference. Additionally, we observed that lower temperatures elicited distinct temporal behavioral patterns at a constant pH level. In summary, we recommend the precise control and explicit reporting of ambient temperature and pH in both breeding devices and experimental wells to minimize the environmental impact on zebrafish behavior and enhance experiment repeatability and reliability.