Martyn Smith spent 25 minutes hiding in a toilet cubicle at an ASDA store in the Garthdee area of Aberdeen.
The 25-year-old was caught when one of his victims saw a camera hovering above the cubicle door.
The man had been using the urinal when the offence happened on September 4 last year.
Smith admitted an offence under the Sexual Offences (Scotland) Act 2009 when he appeared at Aberdeen Sheriff Court earlier this year.
Fiscal depute Sally McAuley said the victim was “concerned” when he saw the camera in the gents toilets.
She said: “Initially he thought someone had left it, but saw the object moving.
“He was concerned that someone was filming his genitals.”
When he saw someone leaving the toilets, he ran after the man, and confronted him.
Ms McAuley said: “The complainer followed and spoke to him. At that point the accused admitted that he had been taking pictures.”
Smith admitted taking pictures and videos of men using the toilets for “sexual gratification” when interviewed by the police.
He said he had recorded footage for 20 minutes and had later deleted the images.
The IT worker, who lives in Montrose, said he was disgusted with himself and embarrassed.
Smith’s defence lawyer told the court that her client was gay, but that none of his family or friends knew.
She said he was at the supermarket to shop and there had been no suggestion that he was going to share the images.
The court heard today that Smith was simply a confused man who had now spoken to family and friends about his sexuality.
But she said some of his friends had abandoned him because of the case and the nature of the offence.
She said her client was a man who did not take his conviction lightly and was “genuinely remorseful” for his actions.
The court heard that Smith had recently experienced difficulties in the small Angus town where he lives after his conviction came to light.
He previously admitted recording images of the genitals, buttocks, or underwear of men whilst they urinated.
Sheriff Graeme Napier placed Smith on a supervision and community payback order and for three years.
He was also told to sign up on the Tay Project operated by Angus Council.
Smith was put on the sex offenders register for three years.