> ## Documentation Index
> Fetch the complete documentation index at: https://help.pixwel.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Slurpee3

> The serverless media-processing pipeline behind ingest, encoding, and automated localization — AWS Step Functions, Lambda, MediaConvert, and Batch.

**Slurpee3** is Pixwel's media-processing engine. When a file is ingested, an encode is requested, or an automated localization order runs, Slurpee3 does the actual media work — probing, transcoding, rendering subtitles and graphics, and writing the resulting files back to storage.

It's the serverless successor to the original [Slurpee](/slurpee) (and Slurpee2), which were long-running PHP/SWF importers. Slurpee3 replaces that with **AWS Step Functions orchestrating Lambda functions**, plus **AWS Elemental MediaConvert** for transcoding and **AWS Batch** for subtitle/graphics rendering.

## Architecture

| Piece              | Role                                                                                                                                            |
| ------------------ | ----------------------------------------------------------------------------------------------------------------------------------------------- |
| **Step Functions** | State machines that orchestrate each pipeline, with `waitForTaskToken` pauses for external verification.                                        |
| **Lambda**         | The individual steps (`mediainfo`, `ingestPrepare`, `gfxEncode`, `createFile`, …). Mostly Node.js, some Python.                                 |
| **MediaConvert**   | AWS Elemental MediaConvert does the transcoding (`GfxEncode`, the encode workflow).                                                             |
| **AWS Batch**      | Containerized subtitle/graphics rendering (`GfxSubtitles`, a `batch:submitJob.sync` task).                                                      |
| **S3 buckets**     | `IngestOutputBucket`, `EncodeOutputBucket`, `GfxEncodeOutputBucket` — outputs land here; `ObjectCreated` events trigger the completion Lambdas. |
| **EventBridge**    | Rules that fire completion handlers (e.g. `EventGfxEncodeAudioComplete`).                                                                       |

It's defined as **AWS SAM** (`slurpee3/template.yaml`, deployed via `deploy.sh`) alongside a **CDK** project (`slurpee3/cdk/`, including the `autosub` stack). Source lives under `slurpee3/workflows/{ingest,encodes,localization}`.

## The pipelines

### Ingest

Runs when a source file is uploaded (see [Ingests](/features/ingests) for the product view):

1. **`mediainfo`** — read media metadata (always).
2. **`ingestScratchPreview`** — a quick scratch preview (video only).
3. **`ingestPrepare`** — `ffprobe` for video; updates the ingest's status, `mediainfo`, `selected`, and `ffprobe` data.
4. **Wait for verification** — a `waitForTaskToken` pause while the detected metadata is confirmed.
5. **`ingestProcess`** — generate the preview and thumbnail (video only).
6. **`copyFile` / `createFile`** — copy the download file when a download is requested.
7. **`ingestVerify`** — finalize, updating the asset and ingest records.

`ingestError` propagates failures to the ingest status.

### Encodes

Produces deliverable encodes through MediaConvert: **`createFile`** sets up the output, **`encode`** submits the MediaConvert job, and **`encodeComplete`** (triggered by an S3 `ObjectCreated` event on `EncodeOutputBucket`) registers the finished file back on the platform.

### Localization (gfx)

The state machine in `statemachine/gfx.asl.json` — *"Generates gfx render for a submitted order master file"* — is what powers [Automated Localization](/features/work-requests/automated-localization) (subtitles and graphics):

1. **`GfxPrepare`** — set up the render from the order's master and translation.
2. **`GfxEncode`** — MediaConvert transcode of the base video.
3. **`GfxEncodeAudio`** — audio handling (`waitForTaskToken`).
4. **`GfxSubtitles`** — AWS Batch container that renders/burns subtitles and graphics.
5. **`GfxEncodeOffline`** — produce the reviewable [offline](/glossary).
6. **`CopyFiles`** — a map state fanning out `CopyFile` to place outputs.
7. **`GfxCreateOffline`** — register the offline back on the work request.

`GfxError` handles failures, and S3-triggered completion Lambdas (`gfxEncodeComplete`, `gfxEncodeOfflineComplete`, `gfxEncodeAudioComplete`) advance the flow as each render lands.

## How it connects to platform2

The [API](/api/overview) starts the work — an ingest or a [work request](/features/work-requests) kicks off the relevant state machine. Slurpee3 processes the media and **calls back to the API** to update ingest, asset, and order status as steps complete (the `waitForTaskToken` pattern lets the API or a verification step resume a paused execution). Finished files land in S3 and are registered as platform [files](/features/projects/files).

## Supporting pieces

* **`mediainfo/`** — a Lambda wrapping the MediaInfo CLI (bundles `libcurl`) for metadata extraction.
* **`copyFile/`** — a Python Lambda for S3-to-S3 copies.
* **`collect-metrics/`** — gathers pipeline metrics.
* **`cdk/autosub/`** — the CDK stack for the autosub side of localization.

## Deploying

* **SAM:** `cd slurpee3 && ./deploy.sh` (uses `template.yaml` / `packaged.yml`).
* **CDK:** from `slurpee3/cdk/`, the standard `cdk deploy` flow.

<Note>
  StepFunctions bills per transition, so the workflows keep state machines lean — choices are pre-computed into simple string/boolean hinges, and a step is only crossed when it genuinely needs orchestration (e.g. spanning Lambda → Batch → MediaConvert).
</Note>
