# Live ad builder

This example app is a web page you run on your own computer. You change an ad's pictures and text, press **Render**, and watch the new video play while it is still rendering.

```video
src: /docs/blitframe/videos/live-ad-builder.mp4
poster: /docs/blitframe/images/live-ad-builder-poster.jpg
caption: The live ad builder: change an ad's pictures and text, render it, and compare it with the original
```

The code is open source: [github.com/CodeArtworks/blitframe-live-ad-builder](https://github.com/CodeArtworks/blitframe-live-ad-builder).

## What you can do with it

It comes with four sample ads.

1. Choose an ad.
2. Pick the pictures, or drop your own image on **Your image**. Blitframe fits your image into the picture's place in the ad.
3. Change any text.
4. Press **Render**. A 13-second ad is typically ready in a few seconds.

You can replay each render or download it as an MP4.

## Run it

You need [Node.js](https://nodejs.org) 22.18 or later and an API key from the [console](https://app.codeartworks.com/blitframe/api-keys). To run it:

```bash
git clone https://github.com/CodeArtworks/blitframe-live-ad-builder.git
cd blitframe-live-ad-builder
npm install
npm start
```

Open `http://localhost:3000` in your browser and paste your API key when the app asks for it. The app's server, which runs on your computer, saves the key in a `.env` file, so the next start connects by itself. You can also put the key in `.env` yourself, as `.env.example` shows. The page in the browser never keeps the key.

![The live ad builder: a stage playing the Tour teaser ad on the left, and on the right the four ad tabs, venue and artist choices each with a Your image tile, the text fields and a Render button.](/docs/blitframe/images/example-live-ad-builder.webp)

## How it uses the API

The API behind each feature:

| Step | API |
|---|---|
| The app sends each ad's template folder to a project of its own, which holds the composition and its files. | [Projects and versions](/docs/blitframe/projects) |
| The app reads the template's layers and fills the form with their text. | [Editable layers](/docs/blitframe/layers#editable-layers) |
| When you pick a picture, each of the picture's layers gets a replacement, a change to that one layer, which points it at another file that is already among the project's files, so nothing is uploaded. | [Replacements](/docs/blitframe/layers#replacements) |
| An image of your own is sent to Blitframe as an upload, once for each layer it fills. | [Uploads and ZIP import](/docs/blitframe/uploads) |
| **Render** queues one render in the `hls` format, with replacements that change the text and images for that video only. | [Render with replacements](/docs/blitframe/renders#render-with-replacements) |
| The page plays the video as a stream as soon as its first seconds are rendered, and links the MP4 when the render finishes. | [Live HLS](/docs/blitframe/renders#live-hls) |

## Make it yours

Each ad is a folder in the repository, with its template and an `ad.json` file that lists what the page may change. To make another text layer editable, give the layer a unique name in the template's `data.json` and add it to the `fields` in `ad.json`.

The app is made to run on your own computer. Before you host it, put it behind your own sign-in and limit how many renders one visitor can start. Otherwise anyone who finds the app can spend your render seconds. The repository's README covers both.
