Graeme Docherty's face was not shown on the video but a dragon tattoo on an arm was identified by police as similar to one inked on his limb.
Docherty, 32, was confronted by the woman who found the film and claimed he could not remember doing anything like that.
He later sent her a text message saying he had no excuse for his actions. She contacted police to report what she had found on the phone.
A judge told Docherty at the High Court in Edinburgh: "You pled guilty to an act of sexual abuse of a boy when he was under four years of age."
Lord Burns said: "It was plainly done for your own sexual gratification and deliberately filmed on your mobile phone."
The judge said that the discovery of the images must have been "highly traumatic".
Lord Burns said that while Docherty appeared to have forgotten about the incident perhaps because he was under the influence of drink or drugs, that did not reduce his culpability.
The judge told him: "I have concluded no other sentence but a custodial one is appropriate here."
He said Docherty would have faced a five year prison term, but for his guilty plea.
The judge also ordered that he be kept under supervision for a further two years.
Docherty, formerly of Moorfield Place, Kimarnock, earlier admitted sexually assaulting the boy at a house in the Ayrshire town and taking an indecent photo of the child.
The woman who got his old mobile phone found the video as she checked it for messages or anything of a personal nature which should be deleted.
The video was date stamped in January 2012 when the boy would have been three years and nine months, but the accuracy of the date could not be confirmed.
Defence counsel Derick Nelson said: "He did have no recollection of committing the offence."
He said it was clear from a background report prepared on Docherty that he was "appalled" that he became involved in it.
Mr Nelson said there was a desire by Docherty to "do something about it".
Lord Burns told Docherty that he would be on the sex offenders' register indefinitely.