Yes you can legally film police officers just like the police officer can legally film you.
If a police officer informs you that it's illegal to film them and orders you to shut the camera off then they're violating your rights to film in public and film a public servant.
That also means that the officer is up to no good if they don't want to be filmed.
I always film a police encounter just in case something goes wrong which I hope never does but having that video evidence is crucial.
If the police officer demands you to turn your camera off then ask for a supervisor who will then inform that police officer that it's your right to film them.
Anything in public can be filmed legally including police officers.