Repository navigation
feat: add video captions, either uploaded or generated automatically with AI - #10
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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:readandvideos:manageAPI key scopes. Three new webhook events report tracks that were added or deleted, and transcriptions that failed.What owners and members see
video.caption.ready,video.caption.deletedandvideo.transcription.failedevents.What viewers see
Ckey turns captions on and off.<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:
GET …/videos/:videoId/captionsGET /libraries/:id/videos/:videoId/captionsvideos:readPOST …/videos/:videoId/captions(multipart)POST /libraries/:id/videos/:videoId/captionsvideos:managePUT …/videos/:videoId/captions/:captionIdPUT /libraries/:id/videos/:videoId/captions/:captionIdvideos:manageDELETE …/videos/:videoId/captions/:captionIdDELETE /libraries/:id/videos/:videoId/captions/:captionIdvideos:manageGET …/videos/:videoId/captions/:captionId/filePOST …/videos/:videoId/transcriptions(202)POST /libraries/:id/videos/:videoId/transcriptionsvideos:manageFor the organization's owner only:
GET /organizations/:slug/transcription-providersPOST /organizations/:slug/transcription-providersPUT /organizations/:slug/transcription-providers/:providerIdDELETE /organizations/:slug/transcription-providers/:providerIdPOST /organizations/:slug/transcription-providers/:providerId/connection-testsGET/PUT …/libraries/:libraryId/transcriptionPublic, under the library's playback rules:
GET /libraries/:id/videos/:videoId/embed/captionsGET /libraries/:id/videos/:videoId/captions/:captionId.vttUploads.
<b>,<i>,<u>and voice tags; everything else is escaped or removed.pt-brbecomespt-BR).Bodies.
{ label?, isDefault? }. A video has at most one default track, and saving the same values again changes and records nothing.{ language?, kind? }.kind:openaineedsapiKey;openai_compatibleneedsbaseUrl, with an optionalapiKey.apiKeythree ways:nullremoves it, except for OpenAI;Provider safety.
TRANSCRIPTION_ALLOW_PRIVATE_ENDPOINTSis set. The check runs again before each transcription.Transcription.
verbose_jsonwith segment timestamps.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
captionsUrlthat carries the embed's signature.Automatic transcription. Video processing now publishes an outbox
video.processedmessage. For libraries that ask for it, its handler queues a transcription.Webhooks.
video.caption.readysends the track.video.caption.deletedsends the track as it was.video.transcription.failedsends the transcription and itsfailureReason.Activity log. New actions:
transcription_provider.created,transcription_provider.updated(withapiKeyChanged),transcription_provider.deleted;library.transcription_updated;video.caption_uploaded,video.caption_updated,video.caption_deleted,video.transcription_requested.There is also a new
transcription_providerresource type, and no entry ever holds a key.Errors.
video.caption.not_foundtranscription_provider.not_foundvideo.caption.limit_reachedvideo.transcription.not_configuredvideo.transcription.in_progressvideo.transcription.no_audiotranscription_provider.limit_reachedtranscription_provider.in_usevideo.caption.file_too_largevideo.caption.invalid_filevideo.caption.too_many_cuestranscription_provider.endpoint_not_allowedtranscription_provider.api_key_requiredConfig. New
TRANSCRIPTION_*settings for:.env.exampleand the README describe them.Migrations
0014_add_captions_and_transcription.sqltranscription_providers.nullfor 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.nullonce deleted), model, requested and detected language, kind, status, failure reason, the run's claim and heartbeat, and who asked.video_captions.nullfor 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_transcribeandtranscription_language. A check makes automatic transcription need a provider.Shared
VIDEO_CAPTION_KINDS,VIDEO_CAPTION_SOURCES,VIDEO_CAPTION_LIMITS,CAPTION_LANGUAGE_PATTERN,TRANSCRIPTION_PROVIDER_KINDS,VIDEO_TRANSCRIPTION_STATUSES,VIDEO_TRANSCRIPTION_FAILURE_REASONS,TRANSCRIPTION_PROVIDER_LIMITSandOPENAI_TRANSCRIPTION_DEFAULTS.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
VideoPlayertakescaptions.usePlayerCaptions, which fetches tracks, chooses one and remembers the language;PlayerCaptionsMenu;PlayerCaptionText, which renders cues as React elements, never as HTML.useEmbedCaptionsreads the embed'scaptionsUrl, in video and playlist embeds.