Arranging to meet the filmmaker Parvez Sharma is a little like setting up an appointment with an extremely polite spy. He asks to rendezvous in a public place — a Starbucks in SoHo where the noise level is high, the tables distant and the volume of customers great. His boundaries are clearly drawn: no discussion of his husband, his friends, his Manhattan neighborhood or his family. He arrives a half-hour early.

Mr. Sharma’s discretion is no doubt borne of his experience growing up gay in a conservative city in India, but it has deepened since the release of his 2007 documentary, “A Jihad for Love,” which depicted the struggle of gay Muslims around the world to reconcile their faith with their sexual orientation. (Homosexuality is generally condemned in modern Islamic societies, said Everett Rowson, an associate professor of Middle Eastern and Islamic Studies at New York University.) After “Jihad,” Mr. Sharma was labeled an infidel, and in the intervening years, he has gotten more death threats than he cares to recall.

His new documentary, “A Sinner in Mecca,” about his 2011 hajj, or journey to Islam’s most sacred sites in Saudi Arabia, put him at even greater risk. Saudi religious police allow selfies or short videos, Mr. Sharma said, but they forbid pilgrims from taking extensive footage of the hajj, which attracts up to three million faithful a year. While Mr. Sharma said there were government-sanctioned videos of the ritual, his documentary shows images of the annual pilgrimage that Saudi officials do not want others to see.

At one moment, “A Sinner in Mecca” seems to eerily anticipate the events of Thursday, when, government officials said, more than 700 people were killed and almost 900 were injured as pilgrims surged through a tunnel en route to one of the rituals. “This is the place of stampedes,” the film’s voice-over says.