Skip to content

Create a reframed version of a video ​

The Aive API allows you to turn a video into reframed versions of itself — for example, to get vertical and square versions of a landscape video — without building a montage by hand.

Creating a reframed version of a video is a four-step process:

text
Upload & analyse the video
      ↓
Create a montage from the container
      ↓
Reframe the montage (update it, or create a reframed copy)
      ↓
Render the montage(s)

This guide walks through the whole flow and links to the dedicated guides for the details of each step.

Prerequisites ​

Before you start:

  • You know your workspace ID. Retrieving a workspace ID works exactly the same way as for scoring — follow step 1 of Score a container if you haven't done so yet.
  • You know the ID of the folder you want to upload the video and create the montages in. See Upload a container for how to retrieve a folder ID.
  • You know the target format(s) (width and height) you want to reframe the video to.
  • Your workspace has enough credits to analyse, reframe and render the video.

Step 1 - Upload and analyse the video ​

Upload the video file as a container, then analyse it:

  1. Follow Upload a container to upload the file and wait for its extraction to succeed. Keep the ID of the created container.
  2. Follow Analyse a container to start its analysis, unless your workspace analyses containers automatically.
  3. Wait for the analysis of every stream of the container to complete, with an analysisStatus of succeeded. See Monitor analysis status.

The montage can not be created until the analysis is complete: the next step is rejected with containerNotAnalyzed while any stream of the container is still being analysed, or has failed its analysis.

Any manifestLevel lets you create the montage. The reframe uses the analysis results, though: with scaleMode: auto (see Step 3), it avoids cropping out on-screen text and logos, which are only detected from manifestLevel: M and XL respectively. See Analysis levels.

Step 2 - Create a montage from the container ​

Use the createMontageFromContainer mutation to create a montage that plays the whole video, in its original format:

  • the montage has the format of the container's video stream;
  • it has a single video lane playing the video stream from start to end;
  • if the container also has an audio stream, it has an audio lane playing the video's audio, synchronized with the video lane.

CreateMontageFromContainer mutation ​

graphql
mutation CreateMontageFromContainer($input: CreateMontageFromContainerInput!) {
  createMontageFromContainer(input: $input) {
    ... on CreateMontageFromContainerResult {
      id
    }
    ... on CreateMontageFromContainerError {
      code
      message
    }
  }
}

CreateMontageFromContainer variables ​

json
{
  "input": {
    "name": "<montage_name>",
    "folderId": "<folder_id>",
    "containerId": "<container_id>"
  }
}

CreateMontageFromContainer input parameters ​

ParameterTypeDescription
nameStringThe name of the montage.
folderIdIDThe destination folder for the new montage.
containerIdIDThe container to create the montage from. It must have a video stream, and be fully analysed.

CreateMontageFromContainer response ​

json
{
  "data": {
    "createMontageFromContainer": {
      "id": "<montage_id>"
    }
  }
}

createMontageFromContainer is synchronous — the montage exists, with its content, as soon as the mutation returns. Keep its id for the next steps.

Step 3 - Reframe the montage ​

The montage created in Step 2 still has the original format of the video. Reframing it to a new format works exactly as described in Reframe a montage:

  1. Read the montage's content with the montage query.
  2. Set the target format in settings.format on a copy of that content, and optionally adjust settings.reframeParams.
  3. Call reframeMontageContent with the edited content. It returns the reframed content, without saving it.

Montage query ​

graphql
query MontageContent($id: ID!) {
  montage(id: $id) {
    content
  }
}

ReframeMontageContent mutation ​

graphql
mutation ReframeMontageContent($input: ReframeMontageContentInput!) {
  reframeMontageContent(input: $input) {
    ... on ReframeMontageContentResult {
      content
    }
  }
}

ReframeMontageContent variables ​

json
{
  "input": {
    "workspaceId": "<workspace_id>",
    "content": "<content_with_updated_settings_format>",
    "args": {}
  }
}

content is the MontageContent JSON object itself, not a string: replace the placeholder, quotes included, with the edited object. The same goes for the content of updateMontage and createMontage below. See Reframe a montage for the other reframeMontageContent parameters.

You then have two ways to save the reframed content.

Option A - Update the montage ​

If you only need the reframed version, replace the montage's content with the reframed content using updateMontage. The montage then has the new format, and the original format is no longer kept.

graphql
mutation UpdateMontage($input: UpdateMontageInput!) {
  updateMontage(input: $input) {
    ... on UpdateMontageResult {
      ack
    }
    ... on UpdateMontageError {
      code
      message
    }
  }
}
json
{
  "input": {
    "id": "<montage_id>",
    "content": "<reframed_montage_content>"
  }
}

Option B - Create a reframed copy ​

If you want to keep the montage in the original format, or need several formats, save the reframed content as a new montage with createMontage instead. Repeat the reframe and createMontage for each target format, always starting from the content of the original montage: you get one montage per format, next to the original one.

graphql
mutation CreateMontage($input: CreateMontageInput!) {
  createMontage(input: $input) {
    ... on CreateMontageResult {
      id
    }
  }
}
json
{
  "input": {
    "folderId": "<folder_id>",
    "name": "<montage_name>",
    "content": "<reframed_montage_content>"
  }
}

Keep the id of each montage you create, for the next step.

Step 4 - Render the montage(s) ​

Render each reframed montage into a video file with renderMontageFromSettings, as described in Render a montage. Rendering uses each montage's saved content, so render the montage updated with Option A, or each copy created with Option B.

RenderMontageFromSettings mutation ​

graphql
mutation RenderMontageFromSettings($input: RenderMontageFromSettingsInput!) {
  renderMontageFromSettings(input: $input) {
    ... on RenderMontageFromSettingsResult {
      renditionId
    }
    ... on RenderMontageError {
      code
      message
    }
  }
}

RenderMontageFromSettings variables ​

json
{
  "input": {
    "montageId": "<montage_id>",
    "settings": {
      "container": "mp4",
      "videoParams": {
        "codec": {
          "h264": {
            "crf": 23,
            "pixelFormat": "yuv420p"
          }
        },
        "fps": 30,
        "colorspace": "bt709"
      },
      "audioParams": {
        "codec": {
          "aac": {
            "enable": true,
            "sampleRate": 48000
          }
        },
        "integratedLoudnessTarget": -14,
        "truePeak": -1
      }
    }
  }
}

Rendering is asynchronous: the mutation returns a renditionId as soon as the render job is queued. Poll the rendition until its state is succeeded, then download the file from its downloadUrl. See Wait for the rendition and download it.

Errors ​

createMontageFromContainer returns a typed error through its output union:

Error codeDescription
containerNotAnalyzedAt least one stream of the container has not been successfully analysed. Wait for the analysis to complete, then try again.
missingVideoStreamThe container has no video stream, e.g. it is an audio-only file. Only a container with a video stream can be turned into a montage.

Other failures, such as a missing permission on the folder or the container, are returned as standard errors.

For the errors of the other steps, see the Errors section of Analyse a container, Reframe a montage and Render a montage.

Best practices ​

  • Wait for the analysis of every stream of the container to succeed before calling createMontageFromContainer, rather than retrying on containerNotAnalyzed.
  • Prefer subscribing to the analysisCompleted webhook event over polling the streams' analysisStatus.
  • To get several formats of the same video, create one reframed copy per format from the original montage, rather than reframing an already reframed montage: each reframe then starts from the full original frame.
  • Always save the reframed content with updateMontage or createMontage before rendering — reframeMontageContent does not save anything, and rendering uses the montage's saved content.
  • Poll each rendition until its state is succeeded or failed, and only then request its downloadUrl.