Shedding light on the pion production in heavy-ion collisions and application into the neutron star matter properties