Skip to content

feat: add video captions, either uploaded or generated automatically with AI - #10

Merged
its-gabo merged 1 commit into
mainfrom
gs_feat_add_captions_and_transciption
Nov 21, 2026
Merged

its-gabo merged 1 commit into
mainfrom
gs_feat_add_captions_and_transciption

Conversation

@its-gabo

@its-gabo its-gabo commented Nov 21, 2026 •

Copy link
Copy Markdown
Owner

Summary

Videos can now have caption tracks: subtitles, or captions that also describe other sounds such as [music]. Members can add a track in two ways. They can upload a WebVTT or SRT file, or they can have the video transcribed by one of the organization's transcription providers.

A provider is either OpenAI or a speech-to-text server the organization runs that speaks OpenAI's transcription API, for example Speaches, faster-whisper-server or LocalAI. The organization's owner connects providers and chooses one for each library. A library can also transcribe every new video once it's processed.

Transcription runs in the worker. It splits the video's sound into 10-minute chunks, sends each chunk to the provider, and turns the timed segments it gets back into readable cues.

The player shows the tracks in a captions menu, remembers the viewer's language, and turns the default track on by itself. Servers can manage tracks with the existing videos:read and videos:manage API key scopes. Three new webhook events report tracks that were added or deleted, and transcriptions that failed.

What owners and members see

  • Captions tab in the video sheet. It lists the video's tracks with their language, kind (Subtitles or Captions (CC)), number of cues, and whether they were uploaded or transcribed.
    • Upload takes a WebVTT or SRT file of up to 2 MB, with a language, a label and a kind. Uploading a track with the same language and kind as an existing one replaces that track.
    • Transcribe asks the library's provider for a track. A spoken language can be chosen; otherwise the library's language is used, or the provider detects it. While a transcription runs, the tab shows "Transcribing…" and refreshes by itself. If the last transcription failed, the tab says why, for example that the provider refused its API key or heard no speech.
    • Each track can be renamed, made the default, downloaded or deleted. A video can have up to 20 tracks.
    • No editor in this PR. To fix a track, download it, edit it in any subtitle editor, and upload it again in the same language.
  • Transcription page for the organization, for the owner only, since providers hold API keys.
    • Connect provider: choose OpenAI (API key required) or your own server (an address, plus an optional API key), then a name and a model.
    • Keys are stored encrypted. Only their last four characters are shown again.
    • Test checks that the provider answers and accepts the key, without transcribing anything.
    • Edit: changing a self-hosted provider's address removes its saved key, so the key never goes to another server. The dialog warns about this.
    • Delete: a provider that libraries still use can't be deleted.
  • Transcription tab in each library, for the owner only. It has the library's provider, the spoken language, and Transcribe new videos automatically (off by default). Automatic transcription skips videos that already have captions and videos without sound.
  • Player settings. A new Captions switch, on by default.
  • Webhooks. A new Captions group with the video.caption.ready, video.caption.deleted and video.transcription.failed events.
  • Activity log. New entries for connecting, changing and deleting a provider; changing a library's transcription settings; uploading, changing and deleting a track; and requesting a transcription.

What viewers see

  • Captions menu in the player, with Off and one entry per track. A captions track's entry ends in "(CC)". The C key turns captions on and off.
  • Default track. The player turns the video's default track on by itself, unless the viewer turned captions off.
  • Remembered language. The viewer's choice is kept in the browser and used for the next video, in video and playlist embeds alike.
  • Cues show above the controls. They keep bold, italic and underline, and nothing else.
  • The player also adds <track> elements, so the browser's own player can show captions where it is used instead.

Changes

API

New endpoints, for members and for library API keys:

Member route Library API route Scope
GET …/videos/:videoId/captions GET /libraries/:id/videos/:videoId/captions videos:read
POST …/videos/:videoId/captions (multipart) POST /libraries/:id/videos/:videoId/captions videos:manage
PUT …/videos/:videoId/captions/:captionId PUT /libraries/:id/videos/:videoId/captions/:captionId videos:manage
DELETE …/videos/:videoId/captions/:captionId DELETE /libraries/:id/videos/:videoId/captions/:captionId videos:manage
GET …/videos/:videoId/captions/:captionId/file
POST …/videos/:videoId/transcriptions (202) POST /libraries/:id/videos/:videoId/transcriptions videos:manage

For the organization's owner only:

Route Does
GET /organizations/:slug/transcription-providers Lists providers, each with how many libraries use it
POST /organizations/:slug/transcription-providers Connects a provider
PUT /organizations/:slug/transcription-providers/:providerId Changes a provider
DELETE /organizations/:slug/transcription-providers/:providerId Deletes a provider that no library uses
POST /organizations/:slug/transcription-providers/:providerId/connection-tests Checks a saved provider's address and key
GET/PUT …/libraries/:libraryId/transcription The library's provider, language and automatic transcription

Public, under the library's playback rules:

Route Does
GET /libraries/:id/videos/:videoId/embed/captions Lists the tracks the player offers, each with a WebVTT URL
GET /libraries/:id/videos/:videoId/captions/:captionId.vtt Serves a track's WebVTT
  • Uploads.

    • Format: files must be UTF-8 WebVTT or SRT. SRT files are turned into WebVTT.
    • Cleaning: cue text keeps only <b>, <i>, <u> and voice tags; everything else is escaped or removed.
    • Timing: cues are clipped to the video's duration, and a file with no cue inside the video is refused.
    • Limits: at most 20 000 cues, 500 characters per cue, 2 MB per file.
    • Language: written as BCP 47, normalized to its usual case (pt-br becomes pt-BR).
  • Bodies.

    • Update takes { label?, isDefault? }. A video has at most one default track, and saving the same values again changes and records nothing.
    • Transcription requests take { language?, kind? }.
    • Provider bodies are a union on kind:
      • openai needs apiKey;
      • openai_compatible needs baseUrl, with an optional apiKey.
    • Provider updates treat apiKey three ways:
      • left out keeps the saved key;
      • null removes it, except for OpenAI;
      • a string replaces it.
  • Provider safety.

    • Addresses must be public HTTPS, unless TRANSCRIPTION_ALLOW_PRIVATE_ENDPOINTS is set. The check runs again before each transcription.
    • Requests connect to the address that DNS lookup checked, don't follow redirects, and stop reading answers larger than 20 MB.
    • Keys are encrypted the same way as storage secrets.
    • A new address without a new key removes the saved key.
  • Transcription.

    • Audio: the worker extracts the sound as mono 16 kHz MP3 in 10-minute chunks, well under OpenAI's 25 MB limit per file. It asks for verbose_json with segment timestamps.
    • Cues: chunk times are shifted into place, then the segments are laid out as cues of at most 2 lines of 42 characters, each shown for at least 0.5 seconds.
    • Runs:
      • Claims: a run claims its transcription and renews the claim every 30 seconds; transcriptions whose claim stops being renewed for 15 minutes are failed.
      • One at a time: a video has at most one active transcription.
      • Retries: failures the provider might recover from, such as being down, are retried up to 3 times. Refused keys and refused requests fail at once.
    • The track is saved in the same transaction that completes the transcription, and replaces a track of the same language and kind.
  • Caption files. Tracks are stored as WebVTT under the video's folder, in captions/. Each save writes a new file. The old file is removed only after the database commits, and the new one is removed if the transaction rolls back, so players never get a file the database doesn't describe. Files go with their track, and with their video.

  • Embed and playback. Video and playlist embeds, and the library API's playback URLs, include a captionsUrl that carries the embed's signature.

  • Automatic transcription. Video processing now publishes an outbox video.processed message. For libraries that ask for it, its handler queues a transcription.

  • Webhooks.

    • video.caption.ready sends the track.
    • video.caption.deleted sends the track as it was.
    • video.transcription.failed sends the transcription and its failureReason.
  • Activity log. New actions:

    • providers: transcription_provider.created, transcription_provider.updated (with apiKeyChanged), transcription_provider.deleted;
    • libraries: library.transcription_updated;
    • videos: video.caption_uploaded, video.caption_updated, video.caption_deleted, video.transcription_requested.

    There is also a new transcription_provider resource type, and no entry ever holds a key.

  • Errors.

    Status Code When
    404 video.caption.not_found The track doesn't exist on this video
    404 transcription_provider.not_found The provider doesn't exist in this organization
    409 video.caption.limit_reached The video already has 20 tracks
    409 video.transcription.not_configured The library has no provider
    409 video.transcription.in_progress The video is already being transcribed
    409 video.transcription.no_audio The video has no sound
    409 transcription_provider.limit_reached The organization already has 20 providers
    409 transcription_provider.in_use Libraries still use the provider
    413 video.caption.file_too_large The file is larger than 2 MB
    422 video.caption.invalid_file Not WebVTT or SRT, or no cue falls within the video
    422 video.caption.too_many_cues More than 20 000 cues
    422 transcription_provider.endpoint_not_allowed The address isn't public HTTPS
    422 transcription_provider.api_key_required An OpenAI provider without a key
  • Config. New TRANSCRIPTION_* settings for:

    • concurrency (2);
    • attempts (3) and the delay between them;
    • the request timeout (10 minutes);
    • the heartbeat (30 seconds) and stall timeout (15 minutes);
    • allowing private endpoints (off).

    .env.example and the README describe them.

Migrations

0014_add_captions_and_transcription.sql

  • transcription_providers.
    • It belongs to an organization and holds the kind, name, model, address (null for OpenAI), encrypted key and the key's last four characters.
    • (id, organization_id) is unique, so libraries can point at a provider of their own organization only.
  • video_transcriptions.
    • It holds each transcription, with its history: provider (null once deleted), model, requested and detected language, kind, status, failure reason, the run's claim and heartbeat, and who asked.
    • A partial unique index allows one pending or processing transcription per video.
  • video_captions.
    • It holds only tracks whose file is stored: language, label, kind, default, file key, size, number of cues, and the transcription that made the track (null for uploads).
    • (video_id, language, kind) is unique, and a partial unique index allows one default track per video.
  • libraries. New columns: transcription_provider_id, auto_transcribe and transcription_language. A check makes automatic transcription need a provider.
  • Checks. The new kinds, statuses, failure reasons, outbox messages, webhook events, activity actions and resource type are allowed.

Shared

  • Constants. VIDEO_CAPTION_KINDS, VIDEO_CAPTION_SOURCES, VIDEO_CAPTION_LIMITS, CAPTION_LANGUAGE_PATTERN, TRANSCRIPTION_PROVIDER_KINDS, VIDEO_TRANSCRIPTION_STATUSES, VIDEO_TRANSCRIPTION_FAILURE_REASONS, TRANSCRIPTION_PROVIDER_LIMITS and OPENAI_TRANSCRIPTION_DEFAULTS.
  • Schemas. The upload, update, transcription request, provider and library settings schemas, used by the API and the web app.
  • Player settings. showCaptions, on by default.

Media

  • extractAudioChunks. A new ffmpeg toolkit step that writes the sound as numbered MP3 chunks, and reports a video without sound.

Web

  • Player.
    • VideoPlayer takes captions.
    • New pieces:
      • usePlayerCaptions, which fetches tracks, chooses one and remembers the language;
      • PlayerCaptionsMenu;
      • PlayerCaptionText, which renders cues as React elements, never as HTML.
  • Embed. useEmbedCaptions reads the embed's captionsUrl, in video and playlist embeds.
  • Dashboard.
    • Video sheet: the Captions tab, with its upload, transcription and edit dialogs.
    • Organization: the Transcription route and its provider dialog.
    • Library: the Transcription tab.
  • Translations. English and Polish for everything new.

@its-gabo its-gabo self-assigned this Nov 21, 2026
@its-gabo
its-gabo merged commit 67b064f into main Nov 21, 2026
1 check passed
@its-gabo
its-gabo deleted the gs_feat_add_captions_and_transciption branch November 21, 2026 15:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant