moviepy.video.tools.interpolators.Trajectory#

class moviepy.video.tools.interpolators.Trajectory(tt, xx, yy)[source]#

Trajectory compound by time frames and (x, y) pixels.

It's designed as an interpolator, so you can get the position at a given time t. You can instantiate it from a file using the methods from_file and load_list.

Parameters:
  • tt (list or numpy.ndarray) -- Time frames.

  • xx (list or numpy.ndarray) -- X positions in the trajectory.

  • yy (list or numpy.ndarray) -- Y positions in the trajectory.

Examples

>>> trajectory = Trajectory([0, .166, .333], [554, 474, 384], [100, 90, 91])
addx(x)[source]#

Adds a value to the xx position of the trajectory.

Parameters:

x (int) -- Value added to xx in the trajectory.

Returns:

Trajectory

Return type:

new instance with the new X position included.

addy(y)[source]#

Adds a value to the yy position of the trajectory.

Parameters:

y (int) -- Value added to yy in the trajectory.

Returns:

Trajectory

Return type:

new instance with the new Y position included.

static from_file(filename)[source]#

Instantiates an object of Trajectory using a data text file.

Parameters:

filename (str) -- Path to the location of trajectory text file to load.

Returns:

Trajectory

Return type:

new instance loaded from text file.

static load_list(filename)[source]#

Loads a list of trajectories from a data text file.

Parameters:

filename (str) -- Path of the text file that stores the data of a set of trajectories.

Returns:

list

Return type:

List of trajectories loaded from the file.

static save_list(trajs, filename)[source]#

Saves a set of trajectories into a text file.

Parameters:
  • trajs (list) -- List of trajectories to be saved.

  • filename (str) -- Path of the text file that will store the trajectories data.

to_file(filename)[source]#

Saves the trajectory data in a text file.

Parameters:

filename (str) -- Path to the location of the new trajectory text file.

txy(tms=False)[source]#

Returns all times with the X and Y values of each position.

Parameters:

tms (bool, optional) -- If is True, the time will be returned in milliseconds.

update_interpolators()[source]#

Updates the internal X and Y position interpolators for the instance.