Image source: Getty Images.

This year has been very good to both Ambarella (NASDAQ:AMBA) and NVIDIA (NASDAQ:NVDA). Ambarella's stock has popped 69% over the past six months and NVIDIA is up about 87%. 

Ambarella's gains have come mostly from the company's ongoing revenue diversification and big expectations from GoPro (NASDAQ:GPRO), of which Ambarella is the exclusive system-on-a-chip (SoC) supplier for many devices. Meanwhile, NVIDIA's stock has skyrocketed on strong earnings and graphics processing unit (GPU) sales, the increasing potential coming from virtual reality and driverless cars

With both stocks doing so well right now it, it's worth taking a closer look to determine which one is the better long-term buy.

The case for Ambarella

Investors were pleased with Ambarella's recent earnings beat in the fiscal first quarter 2017, which helped pop the company's stock price 22% in August.

Investor optimism has also been fueled in part by Amabarella's close ties to GoPro's devices, which are expected to see a sales bump this holiday season. GoPro's management said in a press release back in July that "HERO5 and Karma will contribute to the largest introduction of products in our history, all in time for what we believe will be GoPro's most exciting fourth quarter, ever -- a quarter where we expect to return to profitability."

Ambarella earns about 30% of its total revenue from sales of SoCs to GoPro, so a great sales quarter for GoPro could mean a great quarter for Ambarealla as well. GoPro just debuted its new Karma drone and Hero 5 camera earlier this week to much fanfare, but investors will have to wait to see if that translates into sales for both companies.

But there are some pitfalls investors should be worried about. First, it's not exactly a stellar strategy for any company to align its fate so closely with another company's. Ambarella has tried to diversify its revenue in areas like drones  -- it also makes SoCs for DJI's popular drones. It makes optical image stabilization, electronic image stabilization, and other tech for security and automotive cameras, and is betting big on virtual reality (VR).

That's all positive news, to be sure, but investors should also realize that some of Ambarella's good times could turn sour if GoPro fails to deliver strong sales of the Hero 5 or Karma drone.

Additionally, revenue prospects aren't all that good for the company right now. Ambarella's management projects revenue between $60 million and $66 million for the current quarter, which would be a 22% to 29% decline year over year. 

Now, add to all that the fact that the company's stock is currently trading at 50 times its earnings (twice the technology sector's average of 25) and it starts becoming clear that there are some areas Ambarella needs to improve in. That P/E ratio wouldn't be all that bad if the company were growing revenue at a healthy clip, but that's not happening right now. 

The case for NVIDIA 

A lot of NVIDIA's stock price gains this year have come from the company's earnings. Revenue in fiscal Q2 2017 hit a record high of $1.43 billion. 

NVIDIA makes the majority of its revenue from sales of its GPUs for gaming, and currently holds about 66% of the discrete GPU market. But over the past few years, the company has expanded quickly into powering artificial-intelligence systems and automotive technologies as well. 

The company just released a new single processor for its Drive PX 2 driverless car supercomputer. Drive PX, already used by 80 automakers and Tier 1 suppliers, allows cars with varying levels of autonomy to make sense of the visual information collected by their cameras. 

Investors are betting that NVIDIA can continue to use its strong GPU position for other markets as well. The company recently released three new VR-ready graphics cards for notebooks. These powerful cards help ensure the company stays head of competition, like AMD in the VR space. The cards have enough processing power to come within 10% of the performance of an equivalent desktop card. 

With its current GPU position, inroads into the burgeoning VR market, and continual steps toward driverless cars, NVIDIA is building out a strong portfolio of business as it continues to grow revenue. The company's stock trades at about 41 times its current earnings, making it slightly cheaper than Ambarella, but with the added benefit of having strong revenues to back up its above-average P/E ratio. 

The final verdict 

Though Ambarella has a lot of potential, I would feel far more comfortable investing in NVIDIA over the long term. The company's strong earnings, dominant GPU market share position, virtual reality prospects, and increasing driverless car technology initiatives show me the company knows how to manage its core business (GPUs) as it expands into new markets with ease. NVIDIA also isn't as tied to one company as Ambarella is, which -- when all is added up -- makes NVIDIA the better long-term play over Ambarella. 

This article represents the opinion of the writer, who may disagree with the “official” recommendation position of a Motley Fool premium advisory service. We’re motley! Questioning an investing thesis -- even one of our own -- helps us all think critically about investing and make decisions that help us become smarter, happier, and richer.