William McNamara, 26, was also put on the sex offenders' register for 10 years.
He admitted possessing indecent images at his home in Caledonian Avenue between January and October 2019. McNamara also admitted distributing indecent material to five other online users and breaching bail conditions on his internet use after his arrest.
Abby Seal, prosecuting, said the child porn was found on a phone and an iPad. There were 4,149 indecent photos of children, including 326 in the most depraved category.
Specialist police officers also counted 672 sickening videos, 447 of which were in the most serious category. Ms Seal told the court: "Officers went to the home address of McNamara's former partner, the mother of his two children. She said she saw an indecent image of a child on the accused's phone while they were at Pizza Hut.
Due to this she stopped having any contact with him. Later, on Facebook, the accused admitted to her that he was sexually attracted to young boys."
McNamara appeared in court and was given bail, but within a matter of weeks he was arrested again. He had breached his bail conditions by deleting his internet history, using a virtual private network to disguise his internet use and accessing file-sharing software.
This came to light when McNamara made online contact with a person who turned out to be an undercover police officer. He told the officer about his fixation with young boys and how he'd got into trouble.
He said he'd since obtained a new phone and email address, and was using a system that deleted emails from the server as soon as they were removed from his inbox.
Defence agent Jackson Bateman said McNamara "has difficulty accepting responsibility". It was suggested that a traumatic break-up in 2019 had "triggered" his offending behaviour. Mr Bateman said: "He is a first offender and a robust community payback order could be an alternative to custody.”
However, after adjourning to consider the sentence, Sheriff Andrew McIntyre told McNamara prison was the only appropriate outcome.