Driving from Ljubljana to Venice in July 2017 and will have two nights to stay in route. Rovinj or Piran or somewhere else?
Unfortunately, I missed Piran during my 2015 trip to Slovenia because of an untimely illness and a ticking Schengen clock, so I can't compare those two options. But I still have some thoughts (duh):
Rovinj is across the border in Croatia. Croatia is not Schengen, and border back-ups are possible. We'd need dejan to tell us how bad they might be. You're traveling during peak season, and it might matter what day of the week you'd be making the crossing. And of course you'd have to cross back the other way, though perhaps a different crossing, farther from the coast, would be less traffic-clogged.
I suspect that Rovinj (where I spent four nights, and which I liked) is more touristy than Piran. After Venice, that might matter to you. Here we really need someone who has seen both towns.
Rovinj is better positioned to see some of the key coastal towns in Istria, like Porec and Pula. Piran is closer to the interior towns of Motovun and Groznjan, but you have that pesky border in the way. I really liked Porec, Motovun and Groznjan; didn't have time for Pula and its Roman ruins. I am a big fan of getting away from the coast and the tourist hordes to see the Istrian interior, but your time is very limited, and that may not be practical in any case.
You might consider one night in Piran and then stopping at Postojna or Skocjan (somewhat less touristy) to see the caves. Or just get to Ljubljana earlier to have more time in that very interesting city.
I once read an article that made the Italian/Slovenian border towns of Gorizia/Nova Gorica sound interesting, but I've never made it there. There's also the much larger Trieste. If your time in Ljubljana is very short, I'd probably opt for more time there in lieu of Gorizia or Trieste, just because I really like Ljubljana.
You may run into really hot weather at the time you're traveling, so you might set out with a back-up plan in the event the heat gets to you. Perhaps some air-conditioned museums in Ljubljana.