There are two geometric features of $\mathsf{R}M$ that are important: First, there is the foliation by the fibers ${\mathsf R}_x M$ for $x\in M$, each of which is diffeomorphic to the $n$-sphere, and the corresponding 'vertical' $n$-plane field $V\subset T(\mathsf{R}M)$, i.e., the kernel of the differential of the projection $\pi:\mathsf{R}M\to M$. Second, there is the $(n{+}1)$-plane field $C\subset T(\mathsf{R}M)$ that contains the vertical plane field $V$ and has the property that $\pi'(r)(C_r)= \mathbb{R}\cdot r \subset T_{\pi(r)}M$. The plane fields $V$ and $C$ are canonical in the sense that $V$ and $C$ are preserved under the natural action on $\mathsf{R}M$ of the diffeomorphisms of $M$ (and they are the only plane fields that are preserved). There is also an involution $\iota:\mathsf{R}M\to\mathsf{R}M$ that sends each ray to its opposite ray, but this won't be important in what follows.
Now, an oriented path geometry on $M$ is, by one definition, a choice of a line bundle $E\subset C$ over $\mathsf{R}M$ such that $C = E\oplus V$. The $2n$-parameter family of curves in $\mathsf{R}M$ that are tangent to $E$ (and hence foliate $\mathsf{R}M$) can be canonically oriented so that they then $\pi$-project to $M$ to be a $2n$-parameter family of oriented curves, one through each point oriented tangent to each ray based at that point. The so-called inverse problem in the calculus of variations is to determine whether there exists a (first-order) nondegenerate Lagrangian for oriented curves in $M$ such that the extremals of that Lagrangian are exactly the oriented curves generated by $E$. In [A (classical) path geometry is simply an oriented path geometry that is invariant under $\iota$.]
In this context, a first-order Lagrangian is a section $\lambda$ of the line bundle $(C/V)^*\to \mathsf{R}M$. The reason is that, for any immersed curve $\gamma:[0,1]\to M$, its tangential lifting to $\mathsf{R}M$ defined by $\mathsf{R}\gamma = [\gamma']_+$$\mathsf{R}\gamma(t)= \mathbb{R}^+\cdot\gamma'(t)$ then can be used to 'pullback'pull back $\lambda$ to $[0,1]$, so that it can be integrated over that interval, thus defining a first-order functional on oriented, immersed curves in $M$. (The point is that $(C_r/V_r)^\ast$ is naturally isomorphic to the dual of the tangent line $\mathbb{R}\cdot r$.)
How does one determine $E$ from a given $\lambda$? The process is as follows: First, one notes the classical Lemmalemma that, in this form, says that, for any given Lagrangian $\lambda$ on $\mathsf{R}M$, there exists a unique $1$-form $\delta\lambda$ on $\mathsf{R}M$ with the following properties: First, $V$ is in the kernel of $\delta\lambda$, so that it makes sense to evaluate $\delta\lambda$, which is a section of $(T/V)^\ast$, as an element of $(C/V)^\ast$; second, this evaluation agrees with $\lambda$; and, third, $\bigl(d(\delta\lambda)\bigr)(v,w)=0$ whenever $v,w\in C$. The $1$-form $\delta\lambda$ is known as the HilbertPoincaré-Cartan form of the Lagrangian $\lambda$. The mapping $\lambda\mapsto\delta\lambda$$\delta:C^\infty((C/V)^\ast)\to C^\infty((T/V)^\ast)$ is a linear, first-order operator.
We say that $\lambda$ is nondegenerate if $(d(\delta\lambda))^n$, which is a closed $2n$-form on $\mathsf{R}M$, is nonvanishing. In this case, since $\mathsf{R}M$ has dimension $2n$$2n{+}1$, there is a line bundle $E_\lambda\subset T(\mathsf{R}M)$ that is the kernel of $d(\delta\lambda)$, and it is not difficult to show that $E_\lambda\oplus V = C$ and that, moreover, the oriented curves defined by the oriented path geometry $E_\lambda$ are the extremal curves (with respect to compactly supported variations) of the functional defined by the Lagrangian $\lambda$.
Now, one can imagine a gradual attack on this problem that tries to swim back 'upstream' from $E$ to $\lambda$. First, note that if a nondegenerate $lambda$$\lambda$ exists such that $E=E_\lambda$, then there will be a closed nonvanishing $2n$-form $\Omega = \bigl(d(\delta\lambda)\bigr)^n$ on $\mathsf{R}M$ whose kernel is $E$. It shouldn't be too hard to find such an $\Omega$ since one can always do it locally, and one might be able to 'patch'. Then one must write $\Omega$ in the form $\Omega = \omega^n$ for some closed $2$-form $\omega$. Of course, doing this in general is exactly the problem of the OP. Supposing this could be done, though, that's far from enough because there's no guarantee that $\omega$ would vanish when restricted to each $(n{+}1)$-plane $C_r$, and this would be necessary if $\omega = d(\delta\lambda)$. You'd have to go back and try a different $\omega$, or worse, consider all possible $\omega$s and try to select one that does do what you want. This seems hopelesshopelessly difficult.
However, it turns out that you don't really need to do any of this. There is a better way to proceed: First, select awrite the identity map of $E$ in the form $ X\otimes \xi$ where the vector field $X$ on $\mathsf{R}M$ that is a nonvanishing section of $E$ (this can always be done and $X$ will be unique up to a scalar multiple) and $\xi$ is the dual section of $E^\ast$. Define a linear, second-order differential operator $$ D:C^\infty\bigl((C/V)^\ast\bigr)\to C^\infty\bigl((T/C)^\ast\bigr) $$$$ D_E:C^\infty\bigl((C/V)^\ast\bigr)\to C^\infty\bigl((T/C)^\ast\otimes E^\ast\bigr) $$ (the vector bundle $T/C$ has rank $n$ over $\mathsf{R}M$) by the rule $$ D\lambda = i(X)\ \bigl(d(\delta\lambda)\bigr). $$$$ D_E\lambda = i_X\bigl(d(\delta\lambda)\bigr) \otimes \xi\ . $$ (It is not hard to verify that $D\lambda$$D_E\lambda$ is well-defined and really is a section of $(T/C)^\ast$$(T/C)^\ast\otimes E^\ast$, i.e., aan $E^\ast$-valued $1$-form on $\mathsf{R}M$ that vanishes on elements of $C$.) Then, by construction, $E=E_\lambda$ if $\lambda$ is a nondegenerate Lagrangian that satisfies $D\lambda=0$. (Of course, $D$ is not quite canonical; we could make it canonical, if we wanted, by replacing the target bundle $(T/C)^\ast$ by $(T/C)^\ast\otimes E^\ast$, i.e., by twisting by the line bundle $E^\ast$, but I won't insist on this$D_E\lambda=0$.)
The point is that the inverse problem is cast as a linear, second-order PDE for the unknown Lagrangian $\lambda$, with the extra condition that one is only interested in nondegenerate Lagrangians. Locally, it is $n$ equations for $1$ unknown.
This PDE system is determined when $n=1$ and is always locally solvable. However, when $n>1$, this is an overdetermined problem, and, for the generic $E$, there are no nondegenerate solutions to $D\lambda=0$$D_E\lambda=0$. (I believe that it was Jesse Douglas in the 1930s who first did a serious, detailed study of this overdetermined problem, and he exhibited path geometries in the case $n=2$ for which there were no nondegenerate solutions to this equation.)