Thanks for your query.Based on the facts that you have posted it appears that you have what is called as Haemospermia.
In absence of any urinary symptoms and history of this occuring after masturbation
it looks to be most likely due to injury to your urethra during vigorous masturbation .
However this needs to be confirmed by clinical examination by a qualified Urologist
scanning of the penis and scrotum
In the mean while take broad spectrum antibiotics along with anti inflammatory drug like Diclofenac
Get the prescription of medicines from your family Physician.Ensure to avoid sexual activities till it gets cured completely.