The director was an insecure task­master whose most recent movie had bombed. The producer was a lifelong depressive whose last film had also flopped. The screenwriter was a self-destructive alcoholic, the two lead actors relatively untested newcomers.

Collectively, they were to make a movie based on a bleak novel that had sold poorly and was mostly ignored by critics.

That was the improbable genesis of “Midnight Cowboy,” the 1969 classic of two outcasts who find heartbreak and hope in the kaleidoscopic jungle of New York City. The film would win the Academy Award for Best Picture and the adoration of legions of fans while capturing the lonesome bravado and sordid materialism of America in its crass urban decline.

More than 50 years later, Glenn Frankel has examined the film in “Shooting Midnight Cowboy: Art, Sex, Loneliness, Liberation, and the Making of a Dark Classic”; it explores the movie’s controversial subject matter (gang rape, homosexuality), its mournful eye (a helpless poodle humiliated on a talk show) and its cynical humor.

Where’s the Statue of Liberty, asks the newcomer from Texas.

“It’s up in Central Park,” replies the derisive local, “taking a leak.”

Frankel, a Pulitzer Prize-winning former reporter for The Washington Post and the author of other books on Hollywood, is a smooth writer and sure-footed narrator who uses this volume to excavate the cultural landscape of postwar America — the entrenched homophobia, the shameless exploitation of women, the corrosion of our cities. But even good books about great movies have limits. In this case, squeezing more than 300 pages of prose from a 113-minute film does not always come easily.

Frankel tells his story through interweaving profiles, mostly of men who have to overcome financial woes, combustible egos and their own self-doubt. Frankel’s message seems to be: It takes desperate men to make a movie about other desperate men.

Fans most closely associate the film with Jon Voight and Dustin Hoffman, who found the humanity in two seemingly broken men: Joe Buck, the wide-eyed strapping Texan who seeks his fortune in New York as a hustler, and Ratso Rizzo, the sickly, street-smart grifter from the Bronx who craves deliverance to Florida.

Though Hoffman had just come off his breakout performance in “The Graduate,” neither Hoffman nor Voight was favored by “Midnight Cowboy” director John Schlesinger. But Schlesinger relented, agreeing to Hoffman only after taking a walk with him on 42nd Street, whereupon the actor started limping like Ratso.

To prepare for his role, Voight explored Times Square dressed as a cowboy and invited homeless people to his basement apartment for dinner. Hoffman studied photographs of the liberated concentration camps in World War II, as he wanted Ratso to replicate the pose, and the dignity, of a survivor. The chemistry of Voight and Hoffman on-screen reflected their deep respect for each other, but their friendship was not without rivalry. Hoffman was miffed with the final cut because his character didn’t appear until the 25th minute.

Critical to the enterprise was Schlesinger, the acclaimed but forever despairing British director who second-guessed most every shot, berated his crew and cast, and was certain no one would see a movie, in his words, “about a dumb Texan who takes a bus to New York to seek his fortune screwing rich old women.” He won the Academy Award for Best Director.

There was Jerome Hellman, the distraught producer whose last film had been a bust and, in the midst of a painful divorce, had to sell his house in Bel Air. There was also James Herlihy, the author of the book “Midnight Cowboy,” published and poorly received in 1965; his depiction of emotionally damaged characters reflected his own internal conflicts, including his homosexuality, which he kept concealed for much of his life. (The novel, unlike the movie, had explicit gay themes.)

“Shooting Midnight Cowboy’s” most endearing figure is screenwriter Waldo Salt, a recovering alcoholic who had been blacklisted in the 1950s for his Communist Party membership and whose screenplays in the 1960s had consisted of three flops. But in “Midnight Cowboy,” Salt not only recognized the heart of the story — Joe Buck’s “search for love in the only world he knows” — but also the corrupt, simmering violence of modern pop culture. Joe’s illusions, Salt concluded, “are in fact the absurd reality of our time.” Thanks in part to Salt, “Midnight Cowboy” is as much a meditation on urban rootlessness as it is on male friendship.

Frankel is a diligent researcher, and he uncovers the rich details that gave the movie its texture and authenticity. Costume designer Ann Roth found Ratso’s grungy clothes at sidewalk tables in midtown, and the Andy Warhol-inspired party scene included Warhol regulars. Some scenes were too authentic: Jennifer Salt, Waldo’s daughter, who played the role of a young woman who was gang raped, was traumatized by the experience.

While Frankel uses “Midnight Cowboy” to trace broader cultural trends, some digressions are extraneous. There are unnecessary details of the self-absorbed Warhol; of a bomb that detonates in a townhouse next to Hoffman’s Greenwich Village apartment; of Schlesinger’s next movie. Some careless writing also creeps in. The teenage boy who meets Joe Buck at a movie theater is described as “pimply” five times.

Nonetheless, Frankel’s book will satisfy anyone interested in how a long-shot movie about two underdogs became an American original. Or as Voight told his disbelieving director while still shooting “Midnight Cowboy,” “We will live the rest of our artistic lives in the shadow of this great masterpiece.”

Shooting Midnight Cowboy

Art, Sex, Loneliness, Liberation, and the Making of a Dark Classic

By Glenn Frankel

Farrar, Straus and Giroux.
415 pp. $30