Thanks you for this empathic and balanced response. I'm quite tired of the narrative that the police are all assholes, as the ones that do act like assholes I've met has mostly been because they've been screwed by someone treating them like shit. Or as you've said, from the insanity that has been the training we've been giving them.
I don't think there's any substitute for (a) being polite ("Yes, sir. No, sir.") and (b) being aware of the context. Obviously you should never consent to a search or even give the impression that you're consenting. But literally not talking to the police is not really possible, so there's no avoiding keeping your wits about you so you can act in the most appropriate way possible.
Pulling out your camera is a pretty ballsy move that could escalate things, but I wasn't there so can't judge. But if there were witnesses watching such as other passengers or, especially, a conductor, I wouldn't risk it. I'd just ask for the witnesses' contact information afterward. An irate cop could always snatch your phone away; it's much harder to intimidate a witness, and anyone inclined to do that probably wouldn't think twice about taking your phone or doing something worse later, anyhow. Ultimately you're pretty much helpless, so you have to optimize for the [more likely case] of the cops being mostly honest. They're unfortunately trained to intimidate (we've militarized our civilian police forces), so just because they're acting like assholes doesn't mean they're actually assholes.