Did Ravana have knowledge about Rama being an avatar of Vishnu before the battle? If he knows that Ram is Vishnu's Avatar and will be killed by him then why didn't he change himself to save his life?
No, he was not aware of this fact. Some of his well wishers tried to say this but he abused them and rejected their advices saying Sri Rama was a human being. Many advised him that Sri Rama was not an ordinary human being. He ignored them too.
As I discuss in this answer, Vibhishana and Malyavan, maternal grandfather of Ravana advised Ravana to make peace with Sri Rama and restore Seetha to him. Especially, Malyavan urges him not to wage a war for the welfare of the demons. He perceived the destruction of demons. He says that he considers Sri Rama as Vishnu dwelling in a human form.
विष्णुम् मन्यामहे रामम् मानुषम् देहम् आस्थितम् |
न हि मानुष मात्रो असौ राघवो दृढ विक्रमः || ६-३५-३६
I deem Rama of firm fortitude as Vishnu dwelling in human form. This Rama is not a mere human being. [6-35-36].
So, it is clear that someone has advised Ravana that Sri Rama was an incarnation of Vishnu and not a mere Human being. Ravana put a deaf ear to those advices.
To this advice of Malyavan, Ravana arrogantly replies not to exaggerate his foe and a human being in front of him.
हित बुद्ध्या यद् अहितम् वचह् परुषम् उच्यते |
पर पक्षम् प्रविज़्य एव न एतत् ज़्रोत्र गतम् मम || ६-३६-३
I have closed my ears to the speech you have made, albeit with good intentions and even by taking sides with the enemy. [6-36-3]
मानुषम् कृपणम् रामम् एकम् ज़ाखा मृग आज़्रयम् |
समर्थम् मन्यसे केन त्यक्तम् पित्रा वन आलयम् || ६-३६-४
How can you hold Rama, who is a mere human being, a small feeble man, taking help from monkeys and dwelling in a forest having been abandoned by his father, to be a competent person? [6-36-4]
It is clear from above verses that he considered Rama as a human being rather than Vishnu.
He did it due to his arrogance and pride that he is the lord of demons and superior to the race of humans. He did it because of his pride that he has defeated celestials, other powerful demons etc.,
रक्षसाम् ईज़्वरम् माम् च देवतानाम् भयम् करम् |
हीनम् माम् मन्यसे केन;अहीनम् सर्व विक्रमैः || ६-३६-५
How can you hold me, the Lord of demons, terrifying celestials and possessing all powers in full, to be a weaker person? [6-36-6]
This shows his excessive pride and his attitude towards humans. For this reason he fought the war despite of numerous advises and warnings from his well wishers.