Adding animation tracks to timeline dynamically

A gameobject in my scene changes its position and rotation within various length of time.
I am trying to write a script where it takes the properties of these changes and adds them as clips to timeline.

For example, in my script the gameobject could be in position (1, 1, 0), rotation (90, 0, 0) for 3 seconds.
Then the object would be in position (0, 1, 0), rotation (0, 90, 0) for 1 seconds.

I want to set these changes to the gameobject as 2 separate animation tracks or clips.

How do I do this? Thanks.

The limitation here is AnimationClips cannot be created at runtime (i.e. in the player). If you have pre-baked animation clips, you can dynamically add AnimationTracks at runtime using TimelineAsset.CreateTrack(parentTrack, name) and add clips using AnimationTrack.CreateClip(animationClip);

However, if you need to dynamically generate the animation content, a good start would be a custom track that uses 6 AnimationCurves to store position and rotation values. See the DefaultPlayables asset store package for examples of how to write custom tracks.