The performance closes with a rousing reference to Mr. de Blasio. “No matter what will be, we’ve got Billy D. B.!” Ms. Ushkowitz belts out.

The mayor starts out nodding happily to all the praise but then whispers to an aide, “This is kind of over the top.” In the end, he delivers his review of the performance: “Maybe the song’s a little too elaborate,” he says. “Maybe we should just do a couple of tweets and a Facebook post instead.”

Dick Dadey, the executive director of Citizens Union, a government watchdog organization, questioned whether creating the video was a justifiable use of public resources and said it raised questions because it came right before next year’s re-election campaign.

“This is a virtual campaign ad that is meant to be a public-service announcement but goes beyond that in serving to promote the mayor,” Mr. Dadey said.

The video is part of a broader effort by City Hall to increase its use of the internet and social media to reach out to New Yorkers directly, bypassing traditional news media. It also comes as Mr. de Blasio controls his interactions with the press, frequently avoiding questions and limiting the news conferences at which he will take questions on any topic to once a week.

Eric Phillips, Mr. de Blasio’s press secretary, said that the video was produced by City Hall staff and that the actors volunteered their time. Mr. Phillips said that City Hall spent a total of $700 to pay the piano player and a composer. He said it cost an additional $170 to have the piano tuned and $30 to rent a rehearsal room.

Although the mayor is running for re-election next year, Mr. Phillips said in a written statement that the video “doesn’t have anything to do with his campaign.” He added, “We think New Yorkers have a right to know what their government does, and it’s our job to communicate that work in a modern way.”

The immediate effect of the video was not exactly the stuff of Broadway hit material. In the first seven hours after the video was posted on Twitter, it had received 218 likes on the mayor’s account and 88 retweets.