user: Show practical ways to work with Retiming Keys in a Blender add-on or script – include code.

assistant: [image reference removed]

Strips can be sped up or, slowed down by adding and moving retiming keys. Retiming controls can be activated for
individual strips, after which keys can be selected and moved.

Selecting Retiming Keys

Retiming keys are always shown on strip as inactive by default.
In order to select retiming keys, [Show Retiming Keys](../../../editors/video_sequencer/sequencer/sidebar/strip.xhtml#bpy-types-strip-show-retiming-keys) must be enabled.
This property can also be enabled using [Toggle Retiming Keys](#bpy-ops-sequencer-retiming-show).

Multiple keys can be selected at once with box selection. Box select will select keys, only if a key is already
selected. Otherwise it will select strips only.

Use `Ctrl`-`LMB` to select all keys to the right of the selected key.

Moving Retiming Keys

Retiming key can be moved by dragging it with mouse, or by pressing `G`. The key is mapped to particular frame
of strip content, so moving it effectively means moving a frame to a new position and therefore stretching, or
contracting time flow.

When a key is moved, this does not affect position of other keys inside of the strip. If strip has more keys inside,
multiple keys have to be selected, if only 1 segment has to be retimed. However if there are retiming keys outside
of strip boundary, these will be moved along with first or last key in strip in order to preserve
existing retiming, that is not visible.

### Add Retiming Keys

Retiming key can be added to selected strips from retiming menu
or by pressing `I` and choosing Add Retiming Key option. This adds a key to current frame.
This operation will also create keys at strip start and end point, since these keys must be always present.

When keys are selected, strips are deselected, but it is still possible to add new keys.
In this case keys will be added to strips where any key is selected.

### Add Freeze Frame and Slide

Freeze frame is used to stop strip playback at particular frame for any duration.
Freeze frame can be added from strip retiming menu or context menu.

### Add Speed Transition and Slide

It is possible to create smooth transition from one speed to another speed.
This can be done by selecting retiming key between 2 segments of different speeds,
and choosing Add Speed Transition either from strip retiming menu or context menu.
This will create 2 keys, that are linked and always move in opposite direction.
If both keys are moved at once, this changes where transition starts and ends.

### Delete Retiming Keys

Retiming key can be deleted by selecting and pressing `Delete` or `X`.
When handle is deleted, strip size will not change,
therefore speed will change to average between 2 retimed segments.

### Reset Retiming

Reverts all timing to the original strip.

### Set Speed

Sets the speed of a retimed segment.

Speed
:   The rate compared to the original time.

Preserve Current retiming
:   Keeps the speed of the other retiming segments unchanged by adjusting the
    [Duration](../../../editors/video_sequencer/sequencer/sidebar/strip.xhtml#bpy-types-strip-frame-final-duration) of the strip instead.

### Toggle Retiming Keys

Enables the [Show Retiming Keys](../../../editors/video_sequencer/sequencer/sidebar/strip.xhtml#bpy-types-strip-show-retiming-keys) strip property.
This allows retiming keys to be shown for the first time and enables interacting with them.