Skip to content

Latest commit

 

History

History
262 lines (177 loc) · 16.3 KB

File metadata and controls

262 lines (177 loc) · 16.3 KB

InputVideo

Overview

Available Operations

  • create - Create media from URL
  • upload - Upload media from device

create

This endpoint allows developers or users to create a new video or audio media in FastPix using a publicly accessible URL. FastPix fetches the media from the provided URL, processes it, and stores it on the platform for use.

Public URL requirement:

The provided URL must be publicly accessible and must point to a video stored in one of the following supported formats: .m4v, .ogv, .mpeg, .mov, .3gp, .f4v, .rm, .ts, .wtv, .avi, .mp4, .wmv, .webm, .mts, .vob, .mxf, asf, m2ts

Supported storage types:

The URL can originate from various cloud storage services or content delivery networks (CDNs) such as:

  • Amazon S3: URLs from Amazon's Simple Storage Service.

  • Google Cloud Storage: URLs from Google Cloud's storage solution.

  • Azure Blob Storage: URLs from Microsoft's Azure storage.

  • Public CDNs: URLs from public content delivery networks that host video files.

Upon successful creation, the API returns an id that must be retained for future operations related to this media.

How it works

  1. Send a POST request to this endpoint with the media URL (typically a video or audio file) and optional media settings.

  2. FastPix uploads the video from the provided URL to its storage.

  3. Receive a response containing the unique id for the newly created media item.

  4. Use the id in subsequent API calls, such as checking the status of the media with the Get Media by ID endpoint to determine when the media is ready for playback.

FastPix uses webhooks to tell your application about things that happen in the background, outside of the API regular request flow. For instance, after the media file is created (but not yet processed or encoded), FastPix sends a POST request to your specified webhook URL with the event video.media.created.

After processing completes, monitor the events video.media.ready and video.media.failed to track the status of the media file.

Related guide: Upload videos from URL

Example Usage

import { Fastpix } from "@fastpix/fastpix-node";

const fastpix = new Fastpix({
  security: {
    username: "your-access-token",
    password: "your-secret-key",
  },
});

async function run() {
  const result = await fastpix.inputVideo.create({
    inputs: [
      {
        type: "video",
        url: "https://static.fastpix.io/fp-sample-video.mp4",
      },
    ],
    metadata: {
      "key1": "value1",
    },
  });

  console.log(result);
}

run();

Standalone function

The standalone function version of this method:

import { FastpixCore } from "@fastpix/fastpix-node/core.js";
import { inputVideoCreate } from "@fastpix/fastpix-node/funcs/inputVideoCreate.js";

// Use `FastpixCore` for best tree-shaking performance.
// You can create one instance of it to use across an application.
const fastpix = new FastpixCore({
  security: {
    username: "your-access-token",
    password: "your-secret-key",
  },
});

async function run() {
  const res = await inputVideoCreate(fastpix, {
    inputs: [
      {
        type: "video",
        url: "https://static.fastpix.io/fp-sample-video.mp4",
      },
    ],
    metadata: {
      "key1": "value1",
    },
  });
  if (res.ok) {
    const { value: result } = res;
    console.log(result);
  } else {
    console.log("inputVideoCreate failed:", res.error);
  }
}

run();

Parameters

Parameter Type Required Description
request models.CreateMediaRequest ✔️ The request object to use for the request.
options RequestOptions Used to set various options for making HTTP requests.
options.fetchOptions RequestInit Options that are passed to the underlying HTTP request. This can be used to inject extra headers for examples. All Request options, except method and body, are allowed.
options.retries RetryConfig Enables retrying HTTP requests under certain failure conditions.

Response

Promise<operations.CreateMediaResponse>

Errors

Error Type Status Code Content Type
errors.FastpixDefaultError 4XX, 5XX */*

upload

This endpoint enables accelerated uploads of large media files directly from your local device to FastPix for processing and storage.

NOTE

This version now supports uploads with no file size limitations and offers faster uploads. The previous endpoint (which had a 500MB size limit) is now deprecated. You can find details in the changelog.

How it works

  1. Send a POST request to this endpoint with optional media settings.

  2. The response includes an uploadId and a signed url for direct video file upload.

  3. Upload your video file to the provided url by making a PUT request. The API accepts the media file from your device and uploads it to the FastPix platform. (Refer to Step 3: Initiate the upload for complete instructions.)

  4. Once uploaded, the media undergoes processing and is assigned a unique ID for tracking. Retain this uploadId for any future operations related to this upload.

After uploading, you can use the Get Media by ID endpoint to check the status of the uploaded media asset and see if it has transitioned to a Ready status for playback.

To notify your application about the status of this API request check for the webhooks for media related events.

Example

A social media platform allows users to upload video content directly from their phones or computers. This endpoint facilitates the upload process. For example, if you are developing a video-sharing app where users can upload short clips from their mobile devices, this endpoint enables them to select a video, upload it to the platform.

Related guide: Upload videos directly

Example Usage

import { Fastpix } from "@fastpix/fastpix-node";

const fastpix = new Fastpix({
  security: {
    username: "your-access-token",
    password: "your-secret-key",
  },
});

async function run() {
  const result = await fastpix.inputVideo.upload({
    pushMediaSettings: {
      metadata: {
        "key1": "value1",
      },
    },
  });

  console.log(result);
}

run();

Standalone function

The standalone function version of this method:

import { FastpixCore } from "@fastpix/fastpix-node/core.js";
import { inputVideoUpload } from "@fastpix/fastpix-node/funcs/inputVideoUpload.js";

// Use `FastpixCore` for best tree-shaking performance.
// You can create one instance of it to use across an application.
const fastpix = new FastpixCore({
  security: {
    username: "your-access-token",
    password: "your-secret-key",
  },
});

async function run() {
  const res = await inputVideoUpload(fastpix, {
    pushMediaSettings: {
      metadata: {
        "key1": "value1",
      },
    },
  });
  if (res.ok) {
    const { value: result } = res;
    console.log(result);
  } else {
    console.log("inputVideoUpload failed:", res.error);
  }
}

run();

Parameters

Parameter Type Required Description
request operations.DirectUploadVideoMediaRequest ✔️ The request object to use for the request.
options RequestOptions Used to set various options for making HTTP requests.
options.fetchOptions RequestInit Options that are passed to the underlying HTTP request. This can be used to inject extra headers for examples. All Request options, except method and body, are allowed.
options.retries RetryConfig Enables retrying HTTP requests under certain failure conditions.

Response

Promise<operations.DirectUploadVideoMediaResponse>

Errors

Error Type Status Code Content Type
errors.FastpixDefaultError 4XX, 5XX */*