Skip to content

How to Integrate with the Video Transcoding API?

Flávio Ribeiro edited this page Dec 16, 2016 · 6 revisions

This document aims to describe the steps to integrate a transcoding provider with the Video Transcoding API. In a high level, an encoding provider should be able to store Presets and run encoding Jobs.

TranscodingProvider Interface

func (t *TranscodingProvider) CreatePreset(db.Preset) (string, error)

A Preset consists of a set of configurations such as codec, resolution, bitrate, GOP size and others. The Transcoding API will be responsible to call the CreatePreset() method and map the presetID returned by the call in an internal PresetMap so the same Preset can be reused across all providers.

Alternatively, if your encoding provider doesn't support the creation and handling of presets, you can use the API's LocalPreset which leverages our internal database to save them. For an example on how to do it, you can checkout Zencoder integration.

You can check the presets being used at The New York Times.

func (t *TranscodingProvider) DeletePreset(presetID string) error

Delete the preset on the provider.

func (t *TranscodingProvider) GetPreset(presetID string) (interface{}, error)

Returns a interface{} with the provider's preset.

func (t *TranscodingProvider) Transcode(db.Job) (JobStatus, error)

This is the main function for the integration. When triggering a new job, the Transcoding API will call this function with a set of outputs (which is basically a map of output filename and the preset to be applied to the given output). In case that one or more of the outputs is ABR, the StreamingParams struct will be filled with some details such as SegmentDuration and PlaylistFilename. Make sure to pass hls or dash on the Protocol field.

func (t *TranscodingProvider) JobStatus(db.Job) (JobStatus, error)

Every time that a client makes GET /jobs/JobID, the Transcoding API will call this method. The JobStatus struct contains information such as the Progress and State of the job. There's also a ProviderStatus field that can be filled with any details related to the provider.

func (t *TranscodingProvider) CancelJob(jobID string) error

Cancel the job on the provider.

func (t *TranscodingProvider) Healthcheck() error

Healthcheck should return nil if the provider is currently available for transcoding videos, otherwise, it should return an error explaining what's going on.

func (t *TranscodingProvider) Capabilities() Capabilities

Capabilities describes the available features in the provider. It defines which input and output formats/codecs/containers the provider supports, along with supported destinations (s3, ftp, etc).

Structs

Here are the most important structs for the integration. You can always look at the types file and provider structs.

Job

type Job struct {
	ID              string `redis-hash:"jobID" json:"jobId"`
	ProviderName    string `redis-hash:"providerName" json:"providerName"`
	ProviderJobID   string `redis-hash:"providerJobID" json:"providerJobId"`
	StreamingParams StreamingParams `redis-hash:"streamingparams,expand" json:"streamingParams,omitempty"`
	CreationTime    time.Time `redis-hash:"creationTime" json:"creationTime"`
	SourceMedia     string `redis-hash:"source" json:"source"`
	Outputs         []TranscodeOutput `redis-hash:"-" json:"outputs"`
}

StreamingParams

This struct is used when the Job has HLS outputs.

type StreamingParams struct {
	SegmentDuration uint `redis-hash:"segmentDuration" json:"segmentDuration"`
	Protocol string `redis-hash:"protocol" json:"protocol"`
	PlaylistFileName string `redis-hash:"playlistFileName" json:"playlistFileName,omitempty"`
}

TranscodeOutput

TranscodeOutput represents a transcoding output. It's a combination of the preset and the output file name.

type TranscodeOutput struct {
	Preset PresetMap `redis-hash:"presetmap,expand" json:"presetmap"`
	FileName string `redis-hash:"filename" json:"filename"`

JobStatus

type JobStatus struct {
	ProviderJobID  string                 `json:"providerJobId,omitempty"`
	Status         Status                 `json:"status,omitempty"`
	ProviderName   string                 `json:"providerName,omitempty"`
	StatusMessage  string                 `json:"statusMessage,omitempty"`
	Progress       float64                `json:"progress"`
	ProviderStatus map[string]interface{} `json:"providerStatus,omitempty"`
	Output         JobOutput              `json:"output"`
	SourceInfo     SourceInfo             `json:"sourceInfo,omitempty"`
}