Skip to content

Media catalog

Every video and photo the app can show is registered in one place: apps/mobile/src/features/media/catalog.ts. Adding a family memory is one entry there plus one reference from the feature that uses it.

Every asset belongs to a senior

Files live in a numbered folder per person, and each catalog entry carries the matching ownerId:

apps/mobile/assets/
  1/photos/  1/videos/     Tom
  2/photos/  2/videos/     Nyna

The number is the senior's id in src/features/seniors/roster.ts. Screens read through videosFor(seniorId) and photosFor(seniorId) rather than the whole catalog, so one senior never sees another's memories. See Multiple seniors on one device.

Adding a video

  1. Drop the file in apps/mobile/assets/<seniorId>/videos/, or get a public URL for it. Bundled files ship in the binary (fine for short clips); URLs stream (better for anything large). A streaming URL must serve raw video bytes with HTTP range support. Google Drive share and uc?export=download links do neither (every media request gets redirected to a one-time URL), so the native players show a black stage; a catalog test rejects them. Bundle the file or serve it from the backend instead.
  2. Add an entry to videoAssets:
{
  id: 'summer-picnic',
  kind: 'video',
  ownerId: '1',
  source: require('@/assets/1/videos/summer-picnic.mp4'),
  title: 'The picnic at the lake',
  description: 'A family spreads a checked blanket under a tree...',
  size: { width: 1280, height: 720 },
  credit: 'Summer 1994, camcorder',
}

size is the video as displayed. Read it with ffprobe -v error -select_streams v:0 -show_entries stream=width,height,sample_aspect_ratio -of csv=p=0 file.mp4, and widen the width by the sample aspect ratio when it is not 1:1. tests/video-shape.test.ts reads the file's own header and fails when the two disagree.

The description is read aloud as the audio description before playback, so write it for someone who cannot see the video. Write the require path out in full: Metro resolves it at build time, so a path assembled from a senior id at runtime does not bundle.

  1. Add a quiz in src/features/video-quiz/questions.ts, pulling the clip and its audio description from the catalog. Its seniorId must match the clip's ownerId, which tests/media-catalog.test.ts checks:
{
  id: 'vid-summer-picnic',
  seniorId: '1',
  videoUri: requireVideo('summer-picnic').source,
  audioDescription: { text: requireVideo('summer-picnic').description },
  captions: [ /* ... */ ],
  question: '...',
  // ...
}

Captions stay with the quiz because they are timed to that clip. A quiz without both an audio description and captions is not publishable and the screen refuses to play it (canPublish, src/features/video-quiz/validation.ts).

A video memory

A Stories memory can name a video by videoId. Tom's skydiving memory was the first: it names skydiving (assets/1/videos/skydiving.mp4, re-encoded at 720p with the audio track dropped). A memory's video plays muted, so the memory's song stays the one sound. It plays once: when it ends, the song stops and the overlay comes up with the memory detail and Restart and Next.

A memory may name a video before the file exists. Until that id is in videoAssets, the memory shows without a video in a senior's build, and development builds show a note in its place asking for the file in the repo's inputs/ folder. Register the file as above to finish it.

A landscape video (wider than 4:3, like 16:9) is small on an upright phone. While one shows, the app unlocks rotation and shows "Turn your phone sideways to see it bigger." Turned sideways, the video fills the screen; a tap, or the end of the video, brings up the memory detail with Restart and Next, and only the song line is left out so the panel stays short. Everywhere else the app stays locked upright. A portrait (9:16) or near-square video fits upright and asks for nothing. The shape comes from the catalog's size (videoShape).

A video a Loved One uploads on the web app gets its orientation the same way, by comparing width and height. The browser measures the file before upload (it applies a phone's rotation flag, so a portrait phone clip reads as portrait), the Worker keeps the size, and every video the API returns carries orientation: portrait when it is taller than it is wide, otherwise landscape. Most family videos are landscape, so a square clip, or one whose size the browser could not read, is landscape too. The web app says it in each video's Edit dialog ("Portrait video, 1080 by 1920") and plays a portrait video in a portrait frame. Videos uploaded before this have no size and read as landscape.

An uploaded video can be at most one minute long (VIDEO_MAX_SECONDS in packages/shared/src/video-length.ts) and 80 MB (VIDEO_CONFIG in the Worker's routes/media.ts). The senior waits for a video to end before its memory detail and the Restart and Next buttons appear, and a session holds up to five memories, so a long clip would hold up the whole session. The browser reads the length along with the size when the file is chosen (measureVideo), says so at once in the Add a photo or video dialog ("This video is 1:49 long. A video can be at most one minute (1:00). Trim it and choose it again."), and stops the upload before anything is sent; the hint under the File field states both limits. A file whose length the browser cannot read is not stopped, as one whose size it cannot read is not. The Worker checks the size, not the length, since it cannot open a video. The batch upload script below measures with ffprobe and holds to the same number.

On the web app's Photos and videos page, each video's card is a poster and the title, nothing else, so a memory is quick to find; the card's Edit button opens everything else (a photo's card works the same way, with the photo as the picture). The poster is one still from the middle of the clip. The browser draws it when the video is added (capturePoster in apps/web/src/video-size.ts, a JPEG at most 1280 pixels wide) and sends it with the upload; the Worker keeps it in R2 beside the video (poster_key, migration 0014) and serves it at GET /banks/:bankId/videos/:id/poster. A video added before posters, or from a browser that could not play the file, has none: its card says so, and the first time a manager loads the video in its Edit dialog, the web app draws the poster from it and saves it (PUT …/poster). The phone does not use posters.

On the phone, each uploaded video is a memory of its own in the senior's sessions (fetchBankVideoMoments, videoStoryMoment in src/features/bank/), muted and played once like a bundled video, with its auth header on the video request. A landscape one asks the senior to turn the phone, as above; a portrait one does not. The Worker serves the file in byte ranges, which the iPhone's video player needs to stream it. Videos stream from the Worker each time; only the list is cached for offline use.

Uploading a batch of home movies

A family's clips often arrive as a folder at once (a box of 8 mm reels digitized, say). Adding each through the web app means one form per clip, and the form never asks for the description a screen reader reads. Two scripts do the batch from the command line, with the same checks the web app and the Worker make. Both run from the repo root.

Look the clips over. pnpm videos:sheets inputs/ writes one contact sheet per clip to inputs/sheets/: eight frames spread over its length in a four by two grid, with the clip's length, size, and megabytes printed. Look at each sheet, then write the clip's words.

The manifest. A JSON file beside the clips, inputs/<name>.manifest.json, names the bank, where the clips came from, and each clip's words:

{
  "bank": "bank-example",
  "credit": "Family home movies",
  "videos": [
    {
      "file": "BeachDay.mp4",
      "title": "A day at the beach",
      "description": "Two small children in swimsuits run along the surf while their mother follows with a towel.",
      "takenOn": "1981",
      "location": "Lake George, New York",
      "memoryDetails": ["What beach did you take the children to?"],
      "tags": ["Kids", "Beach"],
      "song": { "title": "Beyond the Sea", "artist": "Bobby Darin" },
      "trim": { "start": 12 }
    }
  ]
}

file, title, and description are required, and neither word may be "TODO": the description is the audio description, read aloud on the phone before the video plays, and it fits the phone's budget (235 characters). The rest is optional and held to the web app's limits: takenOn is a year or a date ("1981", "07/04/1981"), location 120 characters, up to 10 memoryDetails of 140 characters, up to 20 tags of 40, credit on a clip overrides the manifest's, and a song is found with the same music search the web app uses (the first result by that artist, printed so a wrong pick is seen). A clip over the one-minute limit needs a trim, the second the minute starts at: the script cuts it with ffmpeg into inputs/trimmed/ and uploads the cut; the original stays as it is. Any other field (notes to confirm, say) is ignored. The script writes uploadedId into each entry it uploads.

The upload. pnpm videos:upload inputs/<name>.manifest.json signs in with the backup account (backup.env, Backups), lists the bank's videos and songs, and prints a plan. A clip already in the bank is found by its exact size, the only mark of a file the Worker keeps, or by the uploadedId from an earlier run; two rows of the same size are reported and left alone. Then, clip by clip: a clip the bank lacks is uploaded with a poster drawn from its middle, as the browser draws one, and its song; with --update, a clip the bank has gets the words it still lacks or holds as "TODO", a poster if it has none, and a song if it has none (without the flag only a missing song goes in, and the rest is reported). Nothing the family wrote on the web is changed: a real title, date, place, detail, tag, or song on the server stays, and the plan says "kept yours" wherever the manifest said otherwise; --overwrite turns that around. With --replace-long, a clip the bank holds at full length is replaced by the trimmed copy, its words and song carried over, and the long one removed. --dry-run prints the plan and writes nothing; writing to production needs --yes as well. --api http://localhost:8787 --bank dev-bank-tom with the seed's Loved One (SENIOR_HEALTH_BACKUP_EMAIL=loved.one@example.com, SENIOR_HEALTH_BACKUP_PASSWORD=daybreak-dev in the environment, which wins over backup.env) tries a manifest against the local Worker first.

The manifest, the clips, the sheets, and the trimmed copies are the family's and never go into git (.gitignore covers inputs/). When every clip is in the bank, move the clips and the manifest to the shared drive's Assets folder for that senior with mv -n, as the repo's CLAUDE.md says, so nothing is overwritten. The logic lives in apps/api/src/upload-videos.ts, with its tests; the scripts in apps/api/scripts/ run ffmpeg and talk to the Worker.

Adding a photo

  1. Drop the file in apps/mobile/assets/<seniorId>/photos/, or get a public URL.
  2. Add an entry to photoAssets with that ownerId and the same required description. Photos carry no caption: the memory detail holds the words the senior reads.
  3. Set mediaId on a question in src/features/stories/questions.ts:
{ id: 'q-wedding', mediaId: 'wedding-1959', prompt: 'Where were you married?', ... }

The Stories screen shows the photo above the prompt, using the description as its accessible label.

The rules

  • A description is required. validateMediaAsset rejects a blank one, and canShow is checked before anything renders, so an undescribed photo is never displayed rather than displayed unlabeled. This is the same Born Accessible gate the video quiz applies.
  • Ids are unique across the whole catalog, not just within one senior. validateCatalog reports duplicates.
  • Every asset has an owner. A senior only ever sees their own media, and a quiz's seniorId must match its clip's ownerId.
  • requireVideo throws on a typo. Quizzes are authored at module load, so a bad id fails immediately in development and in tests instead of rendering an empty player.
  • tests/media-catalog.test.ts enforces all of the above on the shipped catalog, including that every registered video is actually used by a quiz.
  • docs/dev/multiple-seniors.md — how ownerId scopes the catalog to one person.
  • docs/prototypes/video-quiz.md — the Born Accessible video quiz feature.
  • docs/prototypes/photo-questions.md — a separate, deferred EXIF-driven photo quiz. That feature would read location and date from a photo's own metadata; the catalog here is about photos attached to authored Stories questions, and the two can coexist.
  • docs/dev/accessibility.md — the project-wide accessibility requirements.