How to convert 3D pose sequences to the bvh format?
OK, found the solution myself. Posting here in case anyone else finds this useful. In the BVH format, the following relationship holds between the joints:

$$pos_j = R_{P(j)}offset_j + pos_{P(j)}$$

where $pos_j$ indicates the 3D position of joint $j$, $P(j)$ returns the parent of joint $j$ in whatever DAG the positions are modeled in (generally the DAG starts at the root and points towards the end-effectors) $offset_j$ indicates the offset of joint $j$ relative to its parent $P(j)$ (aka the connecting limb), and $R_{P(j)}$ is the 3D rotation that determines how much should $offset_j$ be rotated from an initial pose (generally a T-pose). In the BVH format, for each parent $P(j)$, we need to store $R_{P(j)}^{-1}R_j$.

The main trouble I had then was working with joints that had multiple children, for example, the root joint, which has connections to both legs as well as the spine. I eventually came across this repo and digging through their function forward_kinematics inside skeleton.py, realized what to do. Basically, for joints with multiple children, I had to make copies with $offset=0$, and assign those as parents of the corresponding chains. Thus I made 3 copies of the root: one became the parent for the left leg chain, one for the right leg chain, and one for the spine. And similarly for the other parents with multiple children. And yes, the visualization works great!