2026-11-18 · 6 min read
How to Add Captions to Videos in Kotlin (Android)
Android apps that record, edit, or share video get the captions request sooner or later. Users expect text on screen, Play Store accessibility checks keep getting stricter, and every social feed has trained viewers to watch muted. In Kotlin you have two realistic paths: render text yourself on the device, or hand the video to an API that returns a finished, captioned file.
Option 1: On-device rendering with Media3
Media3's Transformer can composite text over video using an overlay effect, and older pipelines do it with a Canvas drawn onto a GL texture. It works fully offline, but you own everything: subtitle parsing, line breaking, timing drift, text scaling across the absurd range of Android screen densities, and encoder quirks across chipsets. The harder problem is upstream: you still need a transcript with usable timestamps, and on-device speech recognition gives you segments, not caption-ready two-line chunks.
Option 2: Burned-in captions with the caption.sh API
caption.sh takes a source video URL, transcribes it, and returns the same video with styled captions burned in. From an Android app the flow is: upload the video to your storage as you already do, your backend (never the phone, which should not hold the API key) submits the job, and the app downloads the rendered MP4 when it is ready.
// Backend submits the job; options are nested
val body = """{
"source_url": "https://cdn.example.com/clips/take-7.mp4",
"options": {
"font": "Inter",
"font_size": 48,
"font_color": "#FFFFFF",
"position": "bottom"
}
}""".toRequestBody("application/json".toMediaType())
val request = Request.Builder()
.url("https://api.caption.sh/v1/videos")
.header("Authorization", "Bearer YOUR_API_KEY")
.post(body)
.build()
val response = client.newCall(request).execute()Jobs move through queued, awaiting_upload, running, and done. Poll the status endpoint until done, then call /result, which answers with a 302 redirect; read the Location header for the finished file. Rendered files are kept for 24 hours, so pull them into your own storage promptly.
Choosing between them
- On-device rendering fits when captions must work offline, a transcript already exists, and you can maintain overlay code across screen densities and chipsets.
- The API fits when you need accurate transcription, one consistent style, and batch processing without shipping a renderer in the APK.
- A hybrid is common: caption share-clips through the API and revisit on-device rendering only if profiling proves you need it.
Cost and limits
Processing costs $0.10 per minute of video, prepaid, with a 10-minute per-video cap. A 429 response means you hit the throughput ceiling; back off and retry instead of hammering the endpoint.
For most Android teams the API path ships in a day. The on-device path ships eventually and becomes a permanent maintenance line item.