Magic Hour’s API allows you to upload various types of assets needed for video generation. This guide explains how to manage these assets effectively.

Supported asset types

The follow file extensions are supported by our APIs:

Video

mp4, m4v, mov, webm

Audio

mp3, mpeg, wav, aac, aiff, flac

Image

png, jpg, jpeg, webp, avif, jp2, tiff, bmp

gif extension is only supported by face swap API’s video_file_path field.

Using assets

You have two options when it come to using input files:

  • Pass a URL as the input
  • Upload to our storage

Passing a file URL

This is the simplest method if you have the files hosted somewhere. When calling our APIs, you can simply pass the URL as the video_file_path, image_file_path, or audio_file_path.

For Example

{
  "assets": {
    "video_file_file": "https://cdn.yourwebsite.com/video.mp4"
  }
}

The URL can be an authenticated url, as long as we can validate the file extension is supported.

Upload to Magic Hour storage

To upload assets for video generation, you’ll need to follow a two-step process:

1

Get presigned upload URLs

First, request upload URLs for your assets.

res = client.v1.files.upload_urls.create(
    items=[
        {"extension": "mp4", "type_field": "video"},
    ]
)
{
  "items": [
    {
      // send a PUT request to this url to upload your file
      "upload_url": "https://videos.magichour.ai/api-assets/id/video.mp4?auth-value=1234567890",
      // when the authenticated url expires. This is set to be 15 minutes
      "expires_at": "2024-07-25T16:56:21.932Z",
      // the value to send to the API as `video_file_path`, `image_file_path`, or `audio_file_path`
      "file_path": "api-assets/id/video.mp4"
    }
  ]
}

If requesting multiple upload urls, the response array will be in the same order as the request body.

2

Upload files

After receiving the upload URLs, send a PUT request to each URL with your file data and the appropriate content type header.

Make sure to add Content-type: 'application/octet-stream' header to the request.

import requests

with open('/path/to/file/video.mp4', 'rb') as file:
    response = requests.put(
        'https://videos.magichour.ai/api-assets/id/video.mp4?auth-value=1234567890',
        data=file,
        headers={'Content-Type': 'application/octet-stream'}
    )

Using uploaded assets

After successfully uploading your assets, you can reference them in your video generation API calls using .items.[].file_path value from the upload urls API call.

For example,

{
  "assets": {
    "video_file_path": "api-assets/id/video.mp4"
  }
}

Uploaded file lifecycle

Uploaded files are automatically cleaned up after 7 days.

You can reference the value in .items.[].file_path in multiple API calls before the file is cleaned up.

If you have use cases where having more permanent storage is required, please reach out to our team at support@magichour.ai.