How to implement 2 f-curves: 1 for camera position and 1 for speed?

I’m trying to have 2 curves:
- 1 for the spline that the camera will follow
- 1 for the speed of the camera

How it currently works:

  • At each frame n, I evaluate the 1st curve for n, and the camera’s position is set to (n,f(n)). So currently the velocity is not implemented.
  • I have created a python script that creates the spline mesh from the f-curve.

My problem:

  • Implementing the velocity curve. I think I need to do some math with the curves but I’m not sure what or how. With default velocity, we set the position to (n,f_1(n)). But with a different velocity, we need to find out what input to give to $f_1$

How I think it could work:

  • The velocity curve has one controlpoint for every controlpoint in the 1st curve.

  • The curve between any two controlpoints n-1 and n, indicates how fast the camera will travel from the first controlpoint to the 2nd one (in the 1st curve, which is the path)

  • For example, at frame 130, we don’t want (130,f_1(130)), but we instead want (130,f_1(160))