Greatness, the movies tell us, is unknowable, perhaps even divinely bestowed. The recent “Jimi: All is by My Side” portrayed Jimi Hendrix as an enigma, too shy to let us in to his brilliance. In “Whiplash” you know how characters achieve greatness: they practice and nothing else, shutting out the rest of the world, doing nothing but following their mega-ambitions. It’s an intense, blood-curdling, debatably cynical portrait of geniuses as sociopaths, or at least the ones who have to work at it.

Andrew (Miles Teller) definitely has to work at it. When we meet him he’s at the top music school in the country, playing for its most feared professor, pianist Terrence Fletcher (J.K. Simmons). Andrew, only 19, has been at it for ages, and sounds it, but Fletcher isn’t moved. He belittles him and messes with his head before quietly walking out. He puts him in his competition band anyway. The sessions invariably involve lots of tantrums, insults personal and homophobic. Sometimes someone is driven to tears or told to get out. Once in awhile Fletcher hurls a giant object at someone’s head.

Even after the latter has happened to Andrew, he stays. Fletcher loves to tell the story of how Jo Jones threw a cymbal at the neophyte Charlie Parker’s head, thus, it’s believed, forcing him to practice till he became Charlie Parker. Andrew loves to hear this story. It’s not long before he’s built himself into an ambition monster, one who shirks friendships, relationships and anything that doesn’t involve practice, banging away till he bleeds on his set, till Fletcher is happy. But Fletcher is never happy.

“Whiplash” isn’t exactly saying antisocial behavior is the only way towards greatness. Indeed, its director Damien Chazelle is if not great then uncommonly rigorous. Like his antihero, Chazelle, as they say, directs his ass off. His picture moves: The cuts are fast, sometimes tied to the beat of the music being played; the camera darts around rooms or dollies in on players. It drifts into expressionistic montages made of sensual, moist images: spent mouthpieces soaking with saliva, sweat on cymbals. Many of its scenes take place in darkened, theatrical rooms, where all you can really see is the actors engaged in tense combat. (Not very surprisingly, Teller and Simmons make fine insane people.)

Like Fletcher — and eventually Andrew — it can go too far. One very serious accident strains credibility, to put it lightly. In fact, a fair amount of it strains strictly logical credibility. But no matter: It knows how to play over its mistakes, to regroup and charge through. There are numerous killer scenes, which play like great solos or duets. These showdowns — which invariably involve Fletcher pushing Andrew and others well past the brink and way further still — play at patiently. As Fletcher himself would put it, they neither drag nor rush. “Whiplash” is nearly as wound up as its twin adversaries, because it recognizes that, though they sound insane, perhaps they’re right. Or perhaps they’re both mediocrities with undaunted faith that they can find greatness, but only by shutting out all that’s great about humanity.

Superficially, “Whiplash” plays like “Black Swan,” only stripped of its insanity, its sex, its trashiness, its theatricality. What it adds is a real understanding of the extremes required (by some) to make towering art — the way it forces you to live it at all times, and what a Faustian bargain it can become. “Black Swan” thought it understood it, but “Whiplash” lives it in its bones. It reminds viewers that when every amazing — or even so-so, or even lousy — piece of work ends, it came as the result of at, the very least, considerable pain.