Skip to content

v1.14.0 β€” Compositor export β†’ H.264 MP4 🎬

Choose a tag to compare

@ozgesolidkey ozgesolidkey released this 01 Oct 08:51
· 1 commit to main since this release

Compositor export β†’ H.264 MP4 🎬

The on-device compositor could already export a shareable animated GIF (1.13.0). 1.14.0 adds a second export target: the same OGComposition renders to a real H.264 MP4 with OGComposition.exportMp4() β€” driving the device's own video encoder, with no third-party dependency.

Added

  • OGComposition.exportMp4(bitRate = defaultMp4BitRate(width, height, fps), background = Color.Black) β€” renders every frame offscreen at the composition's fps, flattens it onto an opaque background (H.264 has no alpha), and encodes a real H.264 MP4 with the OS video encoder: Android MediaCodec + MediaMuxer, iOS AVAssetWriter. Returns the encoded ByteArray; saving/sharing stays the app's call.
  • defaultMp4BitRate(width, height, fps) β€” a resolution/fps-scaled default average bit rate, clamped to a 0.75–16 Mbps band.

The byte stream isn't identical across platforms (each OS has its own encoder), but the input is: compositing and the RGB→YUV / RGB→BGRA colour maths live in shared, tested commonMain, so both encoders compress the same rendered frames. H.264 needs even dimensions. Purely additive — one new extension, nothing existing changed. Completes Bet 3 — on-device compositor + export beyond GIF.

Verified: 10 new tests green on JVM + iOS; Android live (MediaCodec β†’ a valid 288Β² @20fps 40-frame H.264, played back through OGAVPlayer); iOS live (AVAssetWriter on the simulator β†’ a valid standard High-profile H.264, ffprobe-confirmed). See docs/COMPOSITOR.md.

implementation("se.solidkey:kmpmedia-lib:1.14.0")