def save()

in fairmotion/data/bvh.py [0:0]


def save(motion, filename, scale=1.0, rot_order="XYZ", verbose=False):
    if verbose:
        print(" >  >  Save BVH file: %s" % filename)
    with open(filename, "w") as f:
        """ Write hierarchy """
        if verbose:
            print(" >  >  >  >  Write BVH hierarchy")
        f.write("HIERARCHY\n")
        joint_order = _write_hierarchy(
            motion, f, motion.skel.root_joint, scale, rot_order
        )
        """ Write data """
        if verbose:
            print(" >  >  >  >  Write BVH data")
        t_start = 0
        dt = 1.0 / motion.fps
        num_frames = motion.num_frames()
        f.write("MOTION\n")
        f.write("Frames: %d\n" % num_frames)
        f.write("Frame Time: %f\n" % dt)
        t = t_start

        for i in range(num_frames):
            if verbose and i % motion.fps == 0:
                print(
                    "\r >  >  >  >  %d/%d processed (%d FPS)"
                    % (i + 1, num_frames, motion.fps),
                    end=" ",
                )
            pose = motion.get_pose_by_frame(i)

            for joint_name in joint_order:
                joint = motion.skel.get_joint(joint_name)
                R, p = conversions.T2Rp(pose.get_transform(joint, local=True))
                p *= scale
                R1, R2, R3 = conversions.R2E(R, order=rot_order, degrees=True)
                if joint == motion.skel.root_joint:
                    f.write(
                        "%f %f %f %f %f %f " % (p[0], p[1], p[2], R1, R2, R3)
                    )
                else:
                    f.write("%f %f %f " % (R1, R2, R3))
            f.write("\n")
            t += dt
            if verbose and i == num_frames - 1:
                print(
                    "\r >  >  >  >  %d/%d processed (%d FPS)"
                    % (i + 1, num_frames, motion.fps)
                )
        f.close()