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

# Transparent output

> Get a Video Remix render with an alpha video for compositing, or on a solid color for green-screen workflows.

By default a Video Remix render keeps the motion video's background. For compositing, set `background_mode` to `transparent`: the render then returns the character video plus a matching alpha video you use as its mask. If your editor works better with a keyed color, use a solid background instead.

## Background modes

| `background_mode` | You get | Extra field |
| - | - | - |
| `original` (default) | The character in the motion video's background | |
| `transparent` | `video_url` (the character video) and `alpha_url` (its alpha mask video) | |
| `solid` | The character on a flat color | `bg_color` as `R,G,B`, for example `0,255,0` for green |

`bg_color` is only valid with `solid`; sending it with another mode is rejected with `400`. In the [draft flow](https://docs.viggle.ai/v1/video/video-remix#draft-flow), the `output.background_mode` shortcuts `green` and `white` give a solid green or white background.

The background mode doesn't change the price: $0.01 per character per second of finished video, minimum 0.5 credit. A 10-second transparent render costs 10 credits ($0.10).

## Render with alpha

Export `VIGGLE_API_KEY` and run one of these as-is. They use a sample character image and motion video hosted by Viggle. The script prints both URLs when the render is ready. The cURL version needs `jq`.

```bash cURL theme={null}
#!/usr/bin/env bash
set -euo pipefail
API="https://apis.viggle.ai/v1"

render_id=$(curl -sS --fail-with-body "$API/renders" \
  -H "Authorization: Bearer $VIGGLE_API_KEY" \
  -F image_url="https://assets.viggle.ai/pub/www/developers/threed-source-image-3f2f6787.webp" \
  -F motion_video_url="https://assets.viggle.ai/pub/www/developers/sample-motion-97bb074a.mp4" \
  -F background_mode="transparent" | jq -er '.id')
echo "Submitted $render_id"

for _ in $(seq 1 120); do
  render=$(curl -sS --fail-with-body "$API/videos/$render_id" \
    -H "Authorization: Bearer $VIGGLE_API_KEY")
  case $(echo "$render" | jq -r '.status') in
    ready) echo "$render" | jq -r '"video: \(.video_url)\nalpha: \(.alpha_url)"'; exit 0 ;;
    failed|cancelled) echo "$render" | jq -c '.error' >&2; exit 1 ;;
  esac
  sleep 5
done
echo "Timed out waiting for $render_id" >&2; exit 1
```

```javascript Node.js theme={null}
// Node.js 20+. Save as transparent.mjs, then run: node transparent.mjs
const API = "https://apis.viggle.ai/v1";
const headers = { Authorization: `Bearer ${process.env.VIGGLE_API_KEY}` };

async function call(path, init = {}) {
  const res = await fetch(`${API}${path}`, { ...init, headers });
  const body = await res.json();
  if (!res.ok) throw new Error(`HTTP ${res.status}: ${JSON.stringify(body.error)}`);
  return body;
}

const form = new FormData();
form.append("image_url", "https://assets.viggle.ai/pub/www/developers/threed-source-image-3f2f6787.webp");
form.append("motion_video_url", "https://assets.viggle.ai/pub/www/developers/sample-motion-97bb074a.mp4");
form.append("background_mode", "transparent");
const { id } = await call("/renders", { method: "POST", body: form });
console.log(`Submitted ${id}`);

for (let i = 0; i < 120; i++) {
  const render = await call(`/videos/${id}`);
  if (render.status === "ready") {
    console.log(`video: ${render.video_url}\nalpha: ${render.alpha_url}`);
    process.exit(0);
  }
  if (render.status === "failed" || render.status === "cancelled") {
    throw new Error(`${render.status}: ${JSON.stringify(render.error)}`);
  }
  await new Promise((resolve) => setTimeout(resolve, 5000));
}
throw new Error(`Timed out waiting for ${id}`);
```

```python Python theme={null}
import os
import time

import requests

API = "https://apis.viggle.ai/v1"
HEADERS = {"Authorization": f"Bearer {os.environ['VIGGLE_API_KEY']}"}


def check(resp):
    if not resp.ok:
        raise RuntimeError(f"HTTP {resp.status_code}: {resp.text}")
    return resp.json()


# Passing fields through files= makes requests send multipart/form-data.
render = check(requests.post(f"{API}/renders", headers=HEADERS, timeout=300, files={
    "image_url": (None, "https://assets.viggle.ai/pub/www/developers/threed-source-image-3f2f6787.webp"),
    "motion_video_url": (None, "https://assets.viggle.ai/pub/www/developers/sample-motion-97bb074a.mp4"),
    "background_mode": (None, "transparent"),
}))
print("Submitted", render["id"])

for _ in range(120):
    render = check(requests.get(f"{API}/videos/{render['id']}", headers=HEADERS))
    if render["status"] == "ready":
        print("video:", render["video_url"])
        print("alpha:", render["alpha_url"])
        break
    if render["status"] in ("failed", "cancelled"):
        raise RuntimeError(f"{render['status']}: {render['error']}")
    time.sleep(5)
else:
    raise TimeoutError(f"Timed out waiting for {render['id']}")
```

A ready transparent render looks like this (other fields trimmed):

```json theme={null}
{
  "id": "render_job_3f9a2c71b5e04d18",
  "status": "ready",
  "video_url": "https://...",
  "alpha_url": "https://..."
}
```

## Composite the result

Download both files: they are deleted 24 hours after the render finishes. In your editor, place `video_url` as the foreground layer and use `alpha_url` as its mask, then put any background underneath.

For a green-screen workflow instead, render with `background_mode=solid` and `bg_color=0,255,0`, and key out the green in your editor.

## Next steps

> [card] [Video Remix](https://docs.viggle.ai/v1/video/video-remix)
>
> Inputs, price, the draft flow and multi-person renders.

> [card] [Reusable characters and motions](https://docs.viggle.ai/v1/video/reusable-characters-and-motions.md)
>
> Save a character once and render it on many backgrounds.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.