Skip to main content

Video Ingest 🎬

Video has been encoded and played by Brightcove, and the contract ends on 23 January 2027. Its replacement is video-ingest: a set of Lambdas that encode the Hub's uploads to HLS with AWS MediaConvert, and caption them with Amazon Transcribe. The Hub plays the result with Video.js. Hubs move across one at a time, and every video already in Brightcove is re-encoded by a backfill.

This page covers the Hub's side and the round trip. video-ingest's README covers the service itself, and its docs/messages.md is the message contract between the two.

Choosing the pipeline​

Each Hub picks where its videos go with domains.config.videoPipeline. Super users set it in the Admin dashboard, under Settings → Brightcove → Video pipeline.

videoPipelineNew uploadsPlayback
brightcove, or unsetSent to Brightcove, as beforeBrightcove Player
awsSent to video-ingest, then copied to Brightcove as a fallbackVideo.js, from the HLS rendition when the video has one; Brightcove Player otherwise

The API reads it with getVideoPipeline() (api/modules/videoIngest/index.js), and the frontend with isAwsVideoPipeline() (frontend/src/common/utils/video/isAwsVideoPipeline.ts).

The upload round trip​

postProcessFiles() (api/modules/files/processors/assets.js) sends a video to video-ingest instead of Brightcove when the Hub is set to aws. Everything after that is asynchronous, and crosses two SQS queues per environment.

  • One request per upload. ingest() claims the file by moving state from draft to processing before it sends anything, so overlapping post-processing of the same upload sends one request, and a video already queued or encoded is left alone. If the request can't be sent, the file is marked invalid and the uploader is told.
  • Output goes next to the upload, in the same bucket: the HLS playlists and segments under <key without extension>/hls/, with the poster frames and audio beside them. The request doesn't say where output goes, so everything for a client stays under its domain's prefix.
  • The request is built by createRequest() (api/modules/videoIngest/requests.js), shared by uploads and the backfill. Both message types are versioned, and an unknown version or type is rejected.

Results​

api/modules/videoIngest/consumer.js reads the results queue when VIDEO_INGEST_RESULTS_QUEUE_URL is set, and handleResult() (api/modules/videoIngest/results.js) handles each message:

  • A video result adds the HLS rendition, sets the poster frame as the asset's thumbnail unless someone uploaded one, moves the file to ready, and tells the uploader. A failure moves it to invalid instead. Either way the content is then resynced to other regions, and a successful video is copied to Brightcove.
  • A captions result stores the transcript as the file's extracted_text and the content's body_text, adds the WebVTT file as subtitles in the detected language unless subtitles in that language were uploaded, and sets the content's language if it has none. A failed transcription only logs: the video plays regardless.

Every step is safe to repeat, so a redelivered result finishes whatever an earlier attempt didn't, and a repeated one changes nothing. The consumer handles one message at a time. When handling throws, SQS delivers it again after 60 seconds; after five attempts it moves to video-ingest-<env>-msg-hub-queue-dlq, and the last failure posts a Slack alert (Video ingest: A result failed for the last time).

What's stored​

RowWritten byNotes
files (the upload)The uploadstate goes draft → processing → ready or invalid, written by ingest() and the video result
files (the HLS rendition)video resultparent_id is the upload, mime_type is application/vnd.apple.mpegurl, file_path is the master playlist
files (the subtitles)captions resultoriginal_file_name is the output's s3:// URI, which tells generated subtitles apart from uploaded ones
assetFilescaptions resultLinks the subtitles to the content, with their locale

is_hls is a generated column, set from mime_type, and the unique key on parent_id and is_hls gives a file at most one HLS rendition. That's what makes a repeated result a no-op. It also sits beside the MP4 rendition from file conversion, which is unrelated: that one exists for the Mindset knowledge bank.

How state differs from Brightcove

For a Brightcove Hub, Brightcove owns a video's state, and file conversion keeps out of it. For an aws Hub, video-ingest's results own it instead. The Brightcove fallback copy never changes it.

Playback​

The asset viewer (frontend/src/common/screens/AssetViewerUI/Content/) plays a video with HlsVideoPlayer, which wraps Video.js and hls.js, when the asset has an HLS rendition (hasHlsRendition) and the Hub is set to aws. Otherwise it uses the Brightcove Player. HlsVideoPlayer is a lazy-loaded chunk, so Brightcove Hubs never download it.

The player asks GET /api/asset/:assetId/video for the stream. The API signs a CDN token for the folder holding the master playlist, valid for a day, so the variant playlists and segments it links to by relative path carry the token too. When the CDN refuses a URL the player fetched more than an hour earlier, it fetches a new one and carries on from the same point.

Brightcove fallback copy​

Until the contract ends, every video video-ingest encodes is also copied to Brightcove, so a Hub can switch back to brightcove and keep its videos. After a successful video result, copyToBrightcove() (api/modules/brightcove/index.js) sends the encoded video to brightcove-ingest, and addSubtitlesToFallbackCopy() pushes the content's subtitles once the copy exists. AWS owns the file: the copy's result only records where the copy is.

Regions​

Each region has its own video-ingest stack and queues, and the region that owns a file encodes it. Content shared to a Hub in the other region reaches it through region sync (api/modules/regionSync/README.md), which copies the HLS rendition row with the content, pointing at the same objects in the owning region's bucket. The resync after each result is what carries it across.

Environments​

Hub environmentvideo-ingest stackvideo-ingest branch
LocalLocal mode, belowAny
dev, dev-ustestingdev
Stagingstagingstaging
Productionproductionmain

The API needs two settings, VIDEO_INGEST_REQUEST_QUEUE_URL and VIDEO_INGEST_RESULTS_QUEUE_URL (api/config/videoIngest.js). With the results queue unset, nothing consumes results. With the request queue unset, an upload to an aws Hub fails visibly rather than waiting in draft.

Locally, docker compose up runs video-ingest's local mode beside the Hub, with the two queues in a localstack container. Encoding and transcription still run in AWS, on the testing stack's MediaConvert role and job template, so you need AWS credentials. Local mode, and running your own video-ingest checkout instead of the published image, are covered in video-ingest's README.

Alerts​

Failures someone needs to look at are logged with logger.slackAlert, and Datadog's slackAlert monitor posts them to Slack, as Helix's are. video-ingest alerts when MediaConvert refuses or fails a job for an upload, and the Hub alerts when it gives up on a result. Everything else, including any failure for the backfill, is only logged.

Backfill​

Every video in Brightcove needs an HLS rendition before the contract ends. api/scripts/backfillVideos.js asks video-ingest to encode them, with backfill: true in each request. For a backfill, video-ingest gives the job MediaConvert's lowest priority, so real uploads go first, and skips the poster and transcription. The Hub only adds the HLS rendition: the video already plays, so its state, thumbnail and subtitles stay as they are, and nobody is notified.

It picks source files with a brightcove_video_id that are videos, are in this region's private bucket, have no HLS rendition, are on an active or maintenance Hub, and are used by content that isn't soft-deleted and that this region owns. Oldest first. A re-run only picks what's still missing, so the backfill is done when the count reaches zero.

Run it once per region, against that region's database, with your own AWS credentials:

cd api
AWS_PROFILE=... MYSQL_HOST=... MYSQL_PORT=3306 MYSQL_USER=... MYSQL_PASSWORD=... MYSQL_DB=apps \
node scripts/backfillVideos.js --env production --region eu-west-2 --out /tmp/backfill.csv
OptionDoes
(none)A dry run: writes the videos and minutes left per Hub to the CSV, and logs the totals
--sendSends the requests
--limitSends at most this many
--rateSends at most this many a minute (default 10)
--outWhere the CSV goes. It defaults to the current directory, which git doesn't ignore
  • It won't encode a video twice. Before reading the database, --send refuses while an earlier run is still in flight: anything on the request queue, or a submitted or in-progress MediaConvert job tagged with this stack and backfill. Real uploads don't count.
  • After each batch, check the count fell. Once the in-flight check passes, run the dry run again: the count should have fallen by about the number sent. If it hasn't, the Hub isn't saving the results, and sending again would encode the same videos twice.
  • A video that can't be encoded is only logged, by video-ingest (video-ingest: MediaConvert job failed) and by the Hub (Video ingest: A video failed to backfill). The next run sends it again, so the videos still left after the last run are the ones to look into. Missing originals can often be restored from Brightcove with api/scripts/findMissingVideoSources.js.
  • The dry run warns about videos on archived or deleted Hubs that an active Hub can still watch through a shared playlist. The backfill leaves those out.
  • Sending needs sqs:GetQueueUrl, sqs:GetQueueAttributes and sqs:SendMessage on video-ingest-<env>-queue, and mediaconvert:ListJobs. The dry run only needs the database.

The order is staging, then production in eu-west-2, then us-east-1: 50 videos first, then the rest. Run it once more just before 23 January, to catch videos that only reached Brightcove since.