Skip to content

Unofficial Javascript client library for MS Azure Video Indexer APIs

License

Notifications You must be signed in to change notification settings

nwaughachukwuma/ms-video-indexer-js

Repository files navigation

MS Azure Video Indexer

Unofficial Javascript client library for Azure Video Indexer, with support for a couple of API's: accessToken, index/upload video, indexed Output, and image (Jpeg/base64) from thumbnail-id. Feel free to contribute an API you find useful to your project

Installation

yarn add ms-video-indexer

pnpm install ms-video-indexer

npm install --save ms-video-indexer

TODO

  • Add major handlers for relevant APIs
    • fetch and cache access token
    • index video file from a downloadable URI
    • get result of video analysis
    • get video thumbnails for any item/model which described the video, such as face, scene or shot.
  • Jest Test.
  • Examples
  • Handlers for other API calls to be implemented based on need/request

Example/Usage

import videoIndexer from 'ms-video-indexer'

const api = videoIndexer({
  accountId: 'the-account-id',
  location: 'the-location',
  subscriptionKey: 'the-subscription-key',
})

// to get the cached token
const accessToken = await api.getToken()

// to index a video
const videoURL = 'https://url-to-a-downloadable-cloud-resource'
const uuid = 'id-recognising-the-video-on-your-platform'

await api.indexVideo(videoURL, {
  name: 'Into the Spiderverse',
  externalId: uuid,
})

API

getToken(forceFetch?)

Returns a promise to a cached access token. This functions ensures you don't always have to poll the access token

  • it's fetched once and cached using simple cache for t < 60sec before it's refreshed.
  • token is always valid within a 1hr expiry period.

forceFetch Type: undefined|boolean

Set to true to fetch a new token

indexVideo(videoURL, options)

Used to ingest a video to be analyzed.

videoURL Type: string

Video file url to analyze. The URL must point to a media file (HTML pages are not supported). Please read more here. Be aware of cases where the video file is protected by an access token and note that those must be encoded properly. See this Stack Overflow question

options Type: UploadVideoRequest

Custom options for your video like name and externalId. Please note the following about the interface:

interface UploadVideoRequest {
  location?: string
  accountId?: string
  name: string
  privacy?: 'Private' | 'Public'
  priority?: 'Low' | 'Normal' | 'High'
  description?: string
  partition?: string
  externalId?: string
  externalUrl?: string
  callbackUrl?: string
  metadata?: string
  language?: string
  videoUrl?: string
  fileName?: string
  indexingPreset?:
    | 'Default'
    | 'AudioOnly'
    | 'VideoOnly'
    | 'BasicAudio'
    | 'Advanced'
    | 'AdvancedAudio'
    | 'AdvancedVideo'
  streamingPreset?:
    | 'NoStreaming'
    | 'Default'
    | 'SingleBitrate'
    | 'AdaptiveBitrate'
  linguisticModelId?: string
  personModelId?: string
  animationModelId?: string
  sendSuccessEmail?: boolean
  assetId?: string
  brandsCategories?: string
}

getIndexedOutput(videoId)

Used to retrieve/fetch the result of a successful index operation.

videoId Type: string

The id of the indexed video.

getThumbnail(videoId, thumbnailId, format?)

Used to retrieve video thumbnail.

videoId Type: string

Id of the indexed video.

thumbnailId Type: string

A guid string identifying the thumbnail.

format Type: undefined|'base64'|'Jpeg'

The preferred thumbnail format. Allowed values are Jpeg and Base64. Defaults to base64

References