komotion
0.4.1indexedFrame-driven video composition system using composable functions where animations are pure functions of frame index; includes preview player, interpolation/spring easing, MP4 export with FFmpeg, audio mixing.
Frame-driven video composition system using composable functions where animations are pure functions of frame index; includes preview player, interpolation/spring easing, MP4 export with FFmpeg, audio mixing.
Frame-driven video animation for Compose Multiplatform.
Komotion lets you build video compositions as @Composable functions where every animation is a pure function of the current frame number. This makes animations deterministic, scrubbable, and trivially exportable to MP4.
Think Remotion — but for Kotlin and Compose.
Terminology follows GLOSSARY.md; architectural decisions are recorded in docs/adr/.
A Composition describes the video: width, height, frame rate and duration in frames. Every composable inside a composition reads the current frame with currentFrame() — the only way composition code should obtain the frame:
val frame = currentFrame() // 0-based frame index
val comp = LocalComposition.current // width, height, fps, durationInFrames
LocalFrame is the underlying composition local that currentFrame() reads. Prefer currentFrame(); read LocalFrame.current directly only when you need the raw local (for example, to provide a different frame via CompositionLocalProvider).
Sequence adds no layout wrapper by default — children lay out directly in the parent. Use AbsoluteFill for overlay content that should fill the parent's space:
AbsoluteFill {
Text("Overlay")
}
New primitives (Series, TransitionSeries, Freeze, Loop, FontAsset/KomotionFont, and the random/ family) are marked . Opt in at the call site:
@OptIn(ExperimentalKomotionApi::class)
@Composable
fun MyComposition() { ... }
Time-window a section of your composition. Children see LocalFrame re-based to 0 at from:
Sequence(from = 0, durationInFrames = 30) {
// currentFrame() here is 0..29
val frame = currentFrame()
val opacity = interpolate(frame, 0..30, 0f..1f)
Text("Intro", modifier = Modifier.graphicsLayer(alpha = opacity))
}
Sequence(from = 30, durationInFrames = 30) {
// currentFrame() here is 0..29
Text("Main content")
}
durationInFrames is optional — when omitted, the sequence runs until the parent ends. The other timing options:
Sequence(
from = 0,
durationInFrames = 30,
trimBefore = 5, // children start 5 child frames "early" (negative frames, clamped by interpolation)
playbackRate = 2.0, // children play at 2x speed; the window is 15 parent frames long
freeze = null, // pin the child to one frame, e.g. freeze = 15
loop = false, // repeat the trimmed range until the parent ends (needs finite durationInFrames)
name = "intro", // carried via LocalSequenceName for timeline display
) {
}
Outside the window the sequence emits a zero-size layout, so it reserves no space in the parent.
A scoped DSL for sequential scenes: each scene starts when the previous one ends, and each scene's children see a frame clock re-based to 0 at the scene's start. A positive offset leaves a gap after the previous scene; a negative offset overlaps it. The last scene may be infinite — pass a negative durationInFrames to run it until the end of the composition:
@OptIn(ExperimentalKomotionApi::class)
@Composable
fun MyVideo() {
Series {
Sequence(durationInFrames = 40) { Intro() }
Sequence(durationInFrames = 20, offset = -10) { Main() } // overlaps Intro's last 10 frames
Sequence(durationInFrames = -1) { Outro() } // runs to the end
}
}
Pins the frame to an absolute value for its content, regardless of the parent's frame — a snapshot of an animation at a specific moment while the surrounding timeline continues:
@OptIn(ExperimentalKomotionApi::class)
@Composable
fun FreezeDemo() {
Freeze(frame = 15) {
// Always sees frame 15
val opacity = interpolate(currentFrame(), 0..30, 0f..1f)
Text("Frozen", modifier = Modifier.graphicsLayer(alpha = opacity))
}
}
Cycles the frame modulo durationInFrames, so the subtree animates on a repeating cycle. To bound how many times it repeats, wrap it in a Sequence that limits the window:
@OptIn(ExperimentalKomotionApi::class)
@Composable
fun Pulse() {
Sequence(from = 30, durationInFrames = 90) { // 3 iterations of a 30-frame loop
Loop(durationInFrames = 30) {
val frame = currentFrame()
val scale = interpolate(frame, 0..15, .)
Box(Modifier.size(dp * scale))
}
}
}
Alternates scenes and transitions. Each transition consumes durationInFrames of overlap from the scene before it and the scene after it, so the total timeline is the sum of the scene durations minus the overlaps. During the overlap the two adjacent scenes are rendered together, blended by the transition:
@OptIn(ExperimentalKomotionApi::class)
@Composable
fun MyVideo() {
TransitionSeries {
Scene(40) { TitleCard() }
Fade(durationInFrames = 10)
Scene(30) { BarChart() }
Slide(durationInFrames = 20)
Scene(30) { Outro() }
}
}
Available transitions: Fade, , , and , each with an optional (and a for /). The scope is a plain value object, so you can compute outside a composable context (for example for a ) and render it with .
Pure functions — deterministic, no Compose context needed. Every animated value is currentFrame() piped through one of these:
interpolate(frame, 0..30, 0f..1f) // Float
interpolateInt(frame, 0..60, 0..100) // Int
interpolateColor(frame, 0..30, Color.Black, Color.White) // Color
interpolateDp(frame, 0..30, dp, dp)
The keyframe form accepts lists of equal length (at least one element, strictly increasing), so a single call can drive a multi-segment animation:
interpolate(frame, listOf(0, 30, 60), listOf(0f, 1f, 0f))
Behavior is controlled with InterpolateOptions:
InterpolateOptions(
extrapolateLeft = ExtrapolateMode.clamp, // clamp | extend | wrap | identity
extrapolateRight = ExtrapolateMode.clamp, // clamp is the default
posterize = 3, // quantize the input to a step (e.g. 3 = 10 fps at 30 fps)
easing = listOf(LinearEasing), // one easing, or one per segment
)
interpolateFloats interpolates every component of a FloatArray independently:
interpolateFloats(frame, listOf(0, 20), listOf(floatArrayOf(0f, 0f), floatArrayOf(100f, 50f)))
Physics-based spring compatible with all interpolation functions:
spring() // Default: slightly bouncy (damping=0.7)
spring(damping = 0.3f) // Very bouncy, overshoots
spring(damping = 1.0f) // Critically damped, no overshoot
spring(damping = 2.0f, stiffness = 50f) // Overdamped, sluggish
// Use with any interpolation
val frame = currentFrame()
val scale = interpolate(frame, , ., options = InterpolateOptions(easing = listOf(spring(damping = ))))
springValue returns the spring's value at a frame directly, without keyframes:
val config = SpringConfig(damping = 0.3f) // bouncy
val position = springValue(
frame = currentFrame(),
fps = 30,
config = config,
from = 0f,
to = 300f,
durationInFrames = 40,
delay = ,
reverse = ,
overshootClamping =
)
settleFrames = measureSpring(config, fps = , threshold = )
springValue and spring share one solver, so the value function and the easing curve never disagree.
Procedural variation must also be a pure function of the frame: use the seeded random family (experimental) instead of unseeded Random calls:
@OptIn(ExperimentalKomotionApi::class)
@Composable
fun Particles() {
val phase = random("particle-1") // same value on every frame
val jitter = randomPerFrame("particle-1") // different value on every frame
val color = pick("palette-1", listOf(Color.Red, Color.Green, Color.Blue))
val frameColor = pickPerFrame(, listOf(Color.Red, Color.Green, Color.Blue))
}
random(seed) returns a deterministic Double in [0.0, 1.0) derived from ; returns a deterministic element of . and fold the current frame into the seed, so the same pair always returns the same value while different frames return different values. Seeds may be a or a .
Declare audio files to be mixed into the exported MP4:
val audioTracks = listOf(
AudioTrack(file = "/path/to/intro.wav", startFrame = 0),
AudioTrack(file = "/path/to/main.wav", startFrame = 90),
)
renderer.render(composition, "output.mp4", audioTracks = audioTracks, content = {
MyComposition()
})
Audio is mixed via FFmpeg adelay + amix during export. Preview playback is silent.
Embed pre-rendered MP4 clips in your composition (desktop export only):
@Composable
fun DemoSegment(videoPath: String) {
val frame = currentFrame()
val videoFrame = rememberVideoFrame(videoFile = videoPath, frameIndex = frame)
Box(Modifier.fillMaxSize()) {
if (videoFrame != null) {
Image(bitmap = videoFrame, contentDescription = null, modifier = Modifier.fillMaxSize())
} else {
Box(Modifier.fillMaxSize().background(Color.Gray)) // Preview placeholder
}
}
}
In preview the composable returns null so you can show a placeholder; during export the renderer decodes the real frame for each output frame.
Captions are timed text overlays built from the core timing primitives — one Sequence per caption, re-based so each caption's text fades in over its own window:
komotion-theme provides shared design tokens: KomotionColors, KomotionTypography and KomotionShapes, exposed through KomotionTheme. KomotionTypography carries the fontFamily and a set of TextStyle tokens (display, title, body, label, code):
@Composable
fun StyledTitle() {
Text(
text = "Komotion",
style = KomotionTheme.typography.display,
color = KomotionTheme.colors.accent,
)
}
Override any token by passing a customized KomotionTheme(...) wrapper around your composition.
Load a TTF/OTF font file and provide it to a subtree with KomotionFont (experimental):
@OptIn(ExperimentalKomotionApi::class)
@Composable
fun StyledTitle() {
val font = remember { FontAsset("fonts/Display.ttf") }
KomotionFont(font) {
Text(
text = "Komotion",
fontFamily = LocalFontFamily.current,
)
}
}
FontAsset loads the file when it is constructed: on Android, iOS and Desktop, path is a path on the local file system; on wasmJs, it is a URL served alongside the app. A missing or unreadable file, or data that is not a font, throws IllegalArgumentException rather than silently falling back to a system font.
KomotionPlayer embeds a composition with transport controls: play/pause, skip to start/end, scrub, loop toggle and a frame counter:
@Composable
fun Preview() {
val composition = Composition(width = 1920, height = 1080, durationInFrames = 60, fps = 30)
KomotionPlayer(
composition = composition,
initialFrame = 0,
loop = true,
autoPlay = false,
) {
HelloVideo()
}
}
Playback is wall-clock driven and corrected for scrubbing; the frame it reports is always a pure function of the player's current state, so preview and export agree frame for frame.
FfmpegFrameRenderer (desktop only) renders a composition frame-by-frame offscreen and encodes it to MP4 with FFmpeg:
val renderer = FfmpegFrameRenderer(
crf = 18, // quality (lower = better)
preset = FfmpegPreset.Medium, // UltraFast | Fast | Medium | Slow | VerySlow
renderMode = RenderMode.Pipe, // Pipe (raw pixels to FFmpeg) or PngSequence (PNG files, for debugging)
)
// Blocking:
renderer.render(composition, "output.mp4", content = {
MyComposition()
})
// Non-blocking: returns a RenderJob reporting progress, completion, failure and cancellation
val job: RenderJob = renderer.renderAsync(
composition = composition,
outputPath = "output.mp4",
content = { MyComposition() },
scope = scope,
)
RenderJob.progress is a StateFlow<Int> of frames rendered so far; RenderJob.isComplete and RenderJob.error report completion and failure; RenderJob.cancel() aborts the render. FfmpegFrameRenderer throws if FFmpeg is not on (or at ).
The changes below are the complete set of breaking changes since 0.4.0. The published 0.4.1 still has the 0.4.x API; the new API described here is not yet published and will ship as 0.5.0.
interpolate family: range-based to keyframe-basedThe interpolate family was rewritten from a two-point range API to a multi-keyframe API. The easing parameter became InterpolateOptions, which adds extrapolation modes and posterization:
A single easing now applies to every segment; one easing per segment is passed as a list. Extrapolation behavior is controlled per side with ExtrapolateMode (clamp, extend, wrap, identity); clamp is the default, matching the old behavior.
// 0.4.x
val opacity = interpolate(frame, 0..30, 0f..1f, easing = spring())
// Now
val opacity = interpolate(frame, listOf(0, 30), listOf(0f, 1f), options = InterpolateOptions(easing = listOf(spring())))
Convenience overloads keep the two-point range form compiling unchanged:
interpolate(frame, 0..30, 0f..1f) // still valid — delegates to the keyframe form
New: interpolateFloats for multi-component FloatArray output.
animate*AsFrame composables removedThe composable wrappers animateFloatAsFrame, animateIntAsFrame, animateColorAsFrame and animateDpAsFrame are gone. Read the frame once with currentFrame() and call the pure interpolate family:
Sequence timing modelSequence gained full timing control. durationInFrames is now optional (Int?) — null runs the sequence until the parent ends — and new parameters were added:
Existing Sequence(from, durationInFrames) call sites compile unchanged; the new parameters all have defaults.
SpringEasing is now constructed from a SpringConfig data class instead of taking damping/stiffness/mass directly, so SpringEasing(0.3f) no longer compiles. Use the spring() factory, which accepts either individual parameters or a :
// 0.4.x
val easing = SpringEasing(damping = 0.3f)
val easing = spring(damping = 0.3f) // also valid in 0.4.x
// Now
val config = SpringConfig(damping = 0.3f)
val easing = spring(config)
val easing = spring(damping = 0.3f) // still valid
New: springValue and measureSpring, sharing the same solver as spring so the easing curve and the value function never disagree.
, (with , , , , ), , , font loading (, , ) and the deterministic randomness family (, , , ) are new since 0.4.0 and are marked — use them with .
No published module was renamed or removed since 0.4.0; the Maven coordinates in Installation are unchanged. now also hosts the timing primitives (, , , , ), the spring utilities, font loading (, ) and the deterministic randomness family, and is a new opt-in annotation in .
The current published version is 0.4.1.
// build.gradle.kts
commonMain.dependencies {
implementation("dev.boling.komotion:komotion-core:0.4.1")
implementation("dev.boling.komotion:komotion-player:0.4.1")
implementation("dev.boling.komotion:komotion-theme:0.4.1")
implementation("dev.boling.komotion:komotion-algo-viz:0.4.1")
}
// Desktop only
val desktopMain by getting {
dependencies {
implementation("dev.boling.komotion:komotion-export-desktop:0.4.1")
}
}
In your settings.gradle.kts:
includeBuild("/path/to/komotion") {
dependencySubstitution {
substitute(module("dev.boling.komotion:komotion-core")).using(project(":komotion-core"))
substitute(module("dev.boling.komotion:komotion-player")).using(project(":komotion-player"))
substitute(module("dev.boling.komotion:komotion-theme")).using(project(":komotion-theme"))
substitute(module("dev.boling.komotion:komotion-algo-viz")).using(project(":komotion-algo-viz"))
substitute(module("dev.boling.komotion:komotion-export-desktop")).using(project(":komotion-export-desktop"))
}
}
The sample-app module is a player sandbox with demo compositions (FadeIn, TitleCard, BarChart, Loop, Freeze, Transition) and an MP4 export button. Run the desktop build:
./gradlew :sample-app:run
Releases are published to Maven Central by the Publish to Maven Central GitHub workflow when a v* tag is pushed. See RELEASING.md for prerequisites, the release checklist and the human approval gates.
Copyright 2026 Stewart Boling
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance the License.
You may obtain a copy of the License at
http:
Unless applicable law agreed to writing, software
distributed under the License distributed an BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express implied.
See the License the specific language governing permissions
limitations under the License.
| Module | Targets | Description |
|---|
komotion-core | Android, iOS, Desktop, wasmJs | Composition model, frame-driven timing (Sequence, Series, Freeze, Loop, TransitionSeries), interpolation, springs, font assets, deterministic randomness |
komotion-player | Android, iOS, Desktop, wasmJs | Embedded player with play/pause, scrub, loop, and frame counter |
komotion-export-desktop | Desktop (JVM) | MP4 export via FFmpeg with audio mixing and video frame extraction |
komotion-theme | Android, iOS, Desktop, wasmJs | Shared design tokens: KomotionTheme with colors, typography and shapes |
komotion-algo-viz | Android, iOS, Desktop, wasmJs | Algorithm visualizations for arrays, graphs, trees, stacks and queues |
sample-app | Android, iOS, Desktop, wasmJs | Demo compositions and the player sandbox |
// Define your animation as a composable
fun HelloVideo() {
val frame = currentFrame()
val opacity = interpolate(frame, 0..30, 0f..1f, options = InterpolateOptions(easing = listOf(spring())))
Box(Modifier.fillMaxSize().background(Color.Black), contentAlignment = Alignment.Center) {
Text(
"Hello, Komotion!",
color = Color.White,
fontSize = 48.sp,
modifier = Modifier.graphicsLayer(alpha = opacity)
)
}
}
// Preview it with the built-in player
fun Preview() {
val composition = Composition(width = 1920, height = 1080, durationInFrames = 60, fps = 30)
KomotionPlayer(composition) {
HelloVideo()
}
}
// Export to MP4 (desktop only)
suspend fun export() {
val composition = Composition(width = 1920, height = 1080, durationInFrames = 60, fps = 30)
val renderer = FfmpegFrameRenderer()
renderer.render(composition, "output.mp4", content = {
HelloVideo()
})
}
pick@ExperimentalKomotionApiSlideWipeIrisClockWipeeasingdirectionSlideWipescope.totalDurationInFramesCompositionTransitionSeries(scope)seedpick(seed, list)listrandomPerFrame(seed)pickPerFrame(seed, list)(seed, frame)StringLongdata class Caption(val text: String, val startFrame: Int, val endFrame: Int)
fun Captions(captions: List<Caption>) {
captions.forEach { caption ->
Sequence(from = caption.startFrame, durationInFrames = caption.endFrame - caption.startFrame) {
val frame = currentFrame()
val opacity = interpolate(frame, 0..10, 0f..1f)
AbsoluteFill {
Box(
modifier = Modifier.fillMaxSize(),
contentAlignment = Alignment.BottomCenter,
) {
Text(
text = caption.text,
color = Color.White.copy(alpha = opacity),
fontSize = 24.sp,
modifier = Modifier.padding(16.dp),
)
}
}
}
}
}
FfmpegNotFoundExceptionPATHffmpegPath| 0.4.x | Now |
|---|
interpolate(frame, IntRange, ClosedFloatingPointRange<Float>, easing: Easing) | interpolate(input, List<Int>, List<Float>, options: InterpolateOptions) |
interpolateInt(frame, IntRange, IntRange, easing: Easing) | interpolateInt(input, List<Int>, List<Int>, options: InterpolateOptions) |
interpolateColor(frame, IntRange, Color, Color, easing: Easing) | interpolateColor(input, List<Int>, List<Color>, options: InterpolateOptions) |
interpolateDp(frame, IntRange, Dp, Dp, easing: Easing) | interpolateDp(input, List<Int>, List<Dp>, options: InterpolateOptions) |
// 0.4.x
val opacity = animateFloatAsFrame(0..30, 0f..1f)
val count = animateIntAsFrame(0..60, 0..100)
val bg = animateColorAsFrame(0..30, Color.Black, Color.White)
val padding = animateDpAsFrame(0..30, 0.dp, 16.dp)
// Now
val frame = currentFrame()
val opacity = interpolate(frame, 0..30, 0f..1f)
val count = interpolateInt(frame, 0..60, 0..100)
val bg = interpolateColor(frame, 0..30, Color.Black, Color.White)
val padding = interpolateDp(frame, 0..30, 0.dp, 16.dp)
| Parameter | Default | Effect |
|---|
durationInFrames | null | Window length in child frames; null = until the parent ends |
trimBefore | 0 | Children start that many child frames early (negative frames, clamped by interpolation) |
playbackRate | 1.0 | Scales child frames; the window becomes durationInFrames / playbackRate parent frames long |
freeze | null | Pins the child to one frame while the sequence is mounted |
loop | false | Repeats the trimmed range until the parent ends (requires finite durationInFrames) |
name | null | Carried via LocalSequenceName for timeline display |
SpringConfigSeriesTransitionSeriesFadeSlideWipeIrisClockWipeFreezeLoopFontAssetKomotionFontLocalFontFamilyrandomrandomPerFramepickpickPerFrame@ExperimentalKomotionApi@OptIn(ExperimentalKomotionApi::class)komotion-coreSequenceSeriesFreezeLoopTransitionSeriesFontAssetKomotionFont@ExperimentalKomotionApikomotion-coreSurfaced from shared tags and platforms — no rankings paid for.