How to flip an animation in Quaternion?
Make a copy of your rig and remove the animation (unlink the action on the duplicate).
Flip your original rig by going into Object mode and setting scale in X-axis to -1.0 on the object.
Add a Copy Rotation constraint for each bone of the duplicate rig that will target the opposite bone in the original rig - ie. Arm.L will copy rotation from Arm.R:

Set the constraints in Local space, check inverse for Y and Z axis:



Automate it with python:

import bpy
orig = bpy.data.objects["NAME_OF_ORIG_RIG"]
copy = bpy.data.objects["NAME_OF_COPY_RIG"]

for pb in copy.pose.bones:
    const = pb.constraints.new("COPY_ROTATION")
    const.target = orig
    const.subtarget = pb.name.replace(".L","§").replace('.R','.L').replace('§','.R')
    const.invert_y = True
    const.invert_z = True
    const.target_space = const.owner_space = 'LOCAL'

Bake the animation on the copy rig into an action:

Pose > Animation > Bake Action > set settings:


Flip your original rig back by setting X-scale to 1.0
Switch the original mocap action with the baked action.
Delete the rig copy.
Optionally automate it all in python.




This approach shows how and why it works and is understandable for someone not familiar with quaternion math or python. You can also achieve the same by transforming F-curve channels directly with python by using that quaternion rotation math.