Comcast Corp. CMCSA -2.63% is sitting on a potential treasure trove of data on how Americans watch TV. Now, the cable giant is working to unlock that information in ways that it hopes could save the $70 billion U.S. television advertising market.

Comcast is seeking to harness viewing data from the set-top boxes and streaming apps used by its millions of cable-TV subscribers to create products it can license to other companies, according to people familiar with its plans. That will require organizing a vast pool of details into “dashboards” that TV networks and marketers can use to tap specific slices of data.

Comcast is in talks with audience-measurement firms and television networks, including Walt Disney Co.’s ESPN, Time Warner Inc.’s Turner Broadcasting and Discovery Communications Inc., about licensing its data to them. It already has a deal with its own NBCUniversal unit and at least one other media company, said people familiar with the deals.

In recent months, Comcast rebuffed an offer from TV-ratings specialist Nielsen, which was willing to pay roughly $100 million for an exclusive license to the data, these people said, though the two companies are deep in talks about other potential partnerships.

Comcast, the largest seller of TV advertising in the U.S., says it believes licensing its data could help the industry bolster the TV-ad market, which has been soft amid a prolonged ratings slide. TV networks say viewing data from the nation’s largest cable operator could plug a gap in traditional TV ratings, which don’t reflect the growing number of viewers who might be watching shows on mobile devices or on-demand several days after the show aired.

Comcast is betting the industry, armed with the company’s data, could better compete with Web-based rivals, such as Google parent Alphabet Inc. and Facebook Inc., whose ad-targeting capabilities are a big draw for marketers.

A TV network could use Comcast’s viewing data, in conjunction with third-party data on buying behavior, to answer such questions as which shows have the highest proportion of viewers who are shopping for a car. Such a service could command a premium ad rate, the thinking goes. Some TV networks have already started targeting specific audiences using data from companies like FourthWall Media and Cablevision Systems Corp., but executives say the scale and detail of Comcast’s data would fill a major blind spot.

TV networks also are interested in using data to evaluate their programming—to assess, for instance, whether a show with a small audience is worth keeping on the air because it has an avid group of return viewers.

“We do believe it’s an unprecedented set of information,” said Sam Schwartz, Comcast’s chief business development officer.

For decades, Nielsen, using data gleaned from a panel of U.S. households, has been the dominant source of TV ratings. ComScore Inc. and Rentrak Corp., two smaller firms that recently announced plans to merge, are emerging as a potential rival.

Comcast could bring a new dimension to the measurement wars. The company collects viewing data from about 18 million of 22 million subscribers, say people briefed on the matter. Roughly 12 million to 13 million of those homes have advanced set-top boxes that collect more-detailed information than older ones.

What makes Comcast’s data potentially so powerful is that its subscribers are spread across much of the U.S., including many major markets. While Nielsen extrapolates TV ratings from a sample of 25,000 households, Comcast’s data reflects actual viewing, and will include its streaming apps.

“Having more precise set-top data is what will power better monetization of premium TV inventory,” said Tracey Scheppach, executive vice president of ad-buying firm Starcom MediaVest. “Money has moved online because they have better analytics and targeting. TV is way behind in both of those places.”

Steve Hasker, Nielsen’s global president, plays down the competitive threat set-top box data poses to Nielsen. “We think it has a role in stabilizing the ratings, but only…when used in combination with panel information” like Nielsen’s, which provides key demographic insights, such as viewers’ age and gender, he said.

People close to Comcast say the company is still formulating its data strategy, including price and technology. Some at the company think Comcast should use its data largely to its own advantage, while others think it needs to be licensed widely to outsiders so it gains credence with advertisers. Comcast has made clear to interested parties that it isn’t interested in doing an exclusive deal. It has indicated to at least one TV programmer that it wants an eight-figure sum in exchange, one of the people said.

Comcast will license only subsets of its data to any one company, and won’t give programmers information about rivals, said people close to Comcast. The information will be aggregated and anonymized to protect individuals’ privacy.

In the short run, Comcast executives expect the company can make the biggest impact on the TV ad market by bolstering Nielsen’s panel with its data.

In the longer run, however, Comcast sees many options. The company has held early talks with cable operators including Cablevision and Time Warner Cable Inc. about pooling data to license a bigger swath of the country to parties. People familiar with the discussions say that could allow the companies to create an alternative TV-measurement currency based on a vast collection of real viewing data rather than just a panel.

Marketers “can get actual measurement,” said Kristin Dolan, chief operating officer of Cablevision, which has data-analytics deals with ESPN and Tribune Media covering more than 7 million set-top boxes in nearly 2.6 million homes. “We’re not guessing or modeling off a small number.”

Write to Shalini Ramachandran at shalini.ramachandran@wsj.com and Suzanne Vranica at suzanne.vranica@wsj.com