Pedro Almodóvar’s brilliant “Pain and Glory” plays almost like an explanation/apology for why his last couple of movies sucked.

A ridiculously handsome Antonio Banderas does not look much like Almodóvar, other than his uncombed dandelion of graying hair, but his character, Salvador, has a lot in common with him. Both are celebrated filmmakers who are grieving the deaths of their beloved mothers, have weathered dips in their careers and live in Madrid.

Sideswiped by chronic ailments, Salvador tries a number of things — drugs, an appearance at a film festival showing a previous hit, meetings with old lovers — to help regain his hunger to make movies. (It’s never translated for us but we see posters of his biggest film, significantly titled “Sabor,” or “Taste.”)

Much of “Pain and Glory” takes place in Salvador’s head as he reflects on what has brought him to this troubled place. He remembers growing up with his strong-willed mother (Penélope Cruz), wonders why work that once struck him as average now seems excellent, visits doctors and attempts to pinpoint why he’s so creatively stuck since, as Salvador says, “Without filming, my life is meaningless. But that’s how things are.”

I know that sounds like a slog and, indeed, at the halfway point of the movie, I wrote in my notebook, “I don’t exactly know why but I am loving this.” Part of that is that, after the dopey “I’m So Excited” and “Julieta,” Almodóvar has his mojo back. There’s plenty to connect “Pain and Glory” to Almodóvar’s earlier work, including a fondness for crazy coincidences and the vivid color palette that American audiences first fell in love with back in 1988’s “Women on the Verge of a Nervous Breakdown,” which also featured Banderas and was shot by José Luis Alcaine. But its themes mark “Pain and Glory” as a mature work by an artist who knows he has more past days than future ones and who is beginning to realize the only way to keep on living is to make peace with the mistakes he has made.

Salvador makes plenty of new mistakes in “Pain and Glory” (insert your favorite anti-heroin PSA here) but Banderas, in a performance that won the best actor prize at the Cannes Film Festival, creates a sense of a character on a journey, albeit a messy one. It’s almost a surprise Banderas won at Cannes because his is the kind of subdued excellence that doesn’t get much awards attention. But, from the beginning of “Pain and Glory,” when there’s a sense that Salvador is about to give up on life, to the end, when there are signs he’s ready to process events by putting them in a movie (maybe “Pain and Glory?”), Banderas delineates a gradual transition from zombified to fully engaged.

Despite its sometimes-grim subject matter, “Pain and Glory” has plenty of Almodóvar’s playful humor and love of the absurd. If you’re a fan of his previous work, also including the Oscar-winning “Talk to Her” and “All About My Mother,” it’s even more fun to watch “Pain and Glory” so you can spot echoes of his previous movies as well as the unmissable autobiographical elements.

Because of a connection to his childhood, Salvador says that movies always make him think of water. It’s an image that recurs throughout the film, and if water is like the movies, “Pain and Glory” is a Buckingham Fountain of beauty and grace.