Skip to main content

Server Side Ad Insertion using Brightcove

The fl-ads-brightcove library enables the playback of Brightcove-curated streams with advertisements, providing Server Side Ad Insertion (SSAI) capability for VOD content.

Specifications

  1. Server-side ads insertion (SSAI) provides a combined video stream of ads and content (ads stitching), resulting in a seamless viewing experience.
  2. Support for various ad formats, including standard in-stream ads and skippable ads.
  3. Multiple ad placements: pre-roll, mid-roll, and post-roll ads.
  4. Thumbnail preview support for enhanced user experience.
  5. Integration with Brightcove Data Collection API for analytics and reporting.

Usage

Create Content Player

First, create a content player using the PlayerBuilder. This player will handle the main video content.

const playbackOptions = {
autoPlayOnLoad: true,
};

const player = createPlayerBuilder()
.mediaElement(videoElement)
.mediaUrl(assetDetail.contentUrl)
.drmLicenseUrl(assetDetail.licenseUrl)
.mediaType(mediaType)
.certificate(certificate)
.playbackOptions(playbackOptions)
.webVTTThumbnailPreview(assetDetail.thumbnailUrl)
.logger(configuration.getLogger())
.build();

Configure Ad Playback Policies

Define the playback policies for ad handling. These policies control how the player behaves during different playback scenarios.

const playbackPolicies = {
fastForwardMode: PlaybackFastForwardMode.TRICK_FW_PLAY_ALL,
rewindMode: PlaybackRewindMode.TRICK_RW_PLAY_ALL,
autoSeekMode: PlaybackAutoSeekMode.AUTO_SEEK_PLAY_ALL,
repeatMode: PlaybackRepeatedMode.REPEAT_ALWAYS_PLAY,
interruptMode: PlaybackInterruptedMode.INTERRUPT_RESUME,
};

const adPlaybackPolicy = playbackPolicies;

Get Cuepoint Data

Retrieve the ad cuepoint data from the VMAP URL. This data contains information about when and where ads should be played.

const promos = await DefaultBrightcoveManager.getCuepointData(
assetDetail.vmapUrl
);

Create Brightcove Ads Player

Create the Brightcove ads player by combining the content player with ad configuration.

const brightcovePlayer =
await DefaultBrightcoveManager.createBrightcoveAdsPlayer(
player,
configuration.getLogger(),
promos,
adPlaybackPolicy
);

This player can be used like a conventional player from the FLPlayer library for playback.

Thumbnail Preview

The Brightcove ads player supports thumbnail previews for enhanced navigation. You can retrieve thumbnail sprites for a specific playhead position.

// Get thumbnail for a specific position (in seconds)
const response = await brightcovePlayer.getThumbnail(position);

// Access the sprite URL
const spriteUrl = response.url[0];

Listening to Ad Events

The Brightcove ads player can subscribe to ad events to track the state of ad playback and implement custom UIs. The following ad events are available:

Event NameDescription
adbreakstartCalled when an ad break starts
adbreakendCalled when an ad break ends
adstartCalled when playback of an advert starts
adendCalled when playback of an advert ends
adcuepointsCalled when cue points are available
adprogressupdateCalled when an advert is playing
aderrorCalled when an error occurs during ad playback
brightcovePlayer.subscribe('adbreakstart', (adBreakInfo) => {
console.log('Ad break started', adBreakInfo);
// Update the player controls
});

brightcovePlayer.subscribe('adstart', (adInfo) => {
console.log('Ad started', adInfo);
// Display ad information
});

brightcovePlayer.subscribe('adprogressupdate', (adInfo, progress) => {
console.log('Ad progress', progress);
// Update ad countdown timer
});

brightcovePlayer.subscribe('adend', (adInfo) => {
console.log('Ad ended', adInfo);
});

brightcovePlayer.subscribe('adbreakend', (adBreakInfo) => {
console.log('Ad break ended', adBreakInfo);
});

brightcovePlayer.subscribe('aderror', (error) => {
console.error('Ad error', error);
// Handle ad playback errors
});

Ad Metadata

AdBreakInfo

Represents an ad break object.

PropertyTypeDescription
adBreakIDstringUnique id of the ad break
contentTimePositionAdContentTimePositionThe position of the ad break, can be one of preroll, midroll or postroll
adBreakStartTimeOffsetMsnumberThe start position in milliseconds
remainingTimeMsnumberThe time remaining in the ad break from the playhead provided, in milliseconds
durationMsnumberThe duration of the ad break, in milliseconds
totalAdsnumberTotal number of adverts in the ad break
adBreakIndexnumberThe index of the current ad break

AdInfo

Represents an advert object.

PropertyTypeDescription
adIDstringThe identifier of the advert
sequencenumberThe sequence of the advert
adStartTimeOffsetMsnumberThe start playhead position of the advert in milliseconds
durationMsnumberThe duration of the advert in milliseconds
remainingTimeMsnumberReturns the natural playback time remaining for the advert in milliseconds
isSkippablebooleanIndicates if the ad is skippable
skipOffsetMsnumberThe value of skip offset for the advert, in milliseconds. If the VAST skip offset is not defined then this method returns -1, signifying that the advert cannot be skipped.
isFillerbooleanWhether this advert represents filler content
adBreakInfoAdBreakInfoThe ad break in which the advert belongs in
adVastPropertiesAdVastPropertiesRepresents VAST properties of this advert

AdVastProperties

Represents VAST properties object.

PropertyTypeDescription
adSystemstringThe source ad server of the advert
adTitlestringThe common name of the advert
adServingIdstringAn identifier used to compare impression-level data across systems
adIdstringThe Ad identifier of the creative
creativeIdstringThe identifier of the creative
categorystringCategory of the advert content
descriptionstringThe longer description of the advert
advertiserstringAdvertiser name
pricingstringPricing element of the advert
surveystringA URI to any resource file having to do with collecting survey data
expiresstringNumber of seconds in which the ad is valid for execution

Brightcove Data Collection API

The fl-ads-brightcove package supports analytics reporting to Brightcove's Data Collection API v2, enabling tracking of playback events, user engagement, and optional QoE (Quality of Experience) metrics.

Configuration Options

ParameterTypeRequiredDefaultDescription
accountIdnumberYes-Your Brightcove Video Cloud account ID
videoIdstringYes-The Video Cloud video ID being tracked
videoNamestringNo-Human-readable name of the video for analytics reports
sessionIdstringNoAuto-generated UUID v4Custom session identifier. Must be globally unique to prevent data collisions
engagementEventIntervalnumberNo10000Interval in milliseconds between video_engagement events (range: 5000-30000)
includeQoEMetricsbooleanNofalseEnable optional QoE metrics in engagement events. Warning: May impact performance on low-end devices (LG Smart TVs, Tizen, Vizio)
userIdstringNoIP + User-Agent hashUnique user identifier. Should be hashed with SHA-256 for privacy
deviceTypestringNoAuto-detectedDevice type override. Values: 'mobile', 'tablet', 'tv', 'desktop', 'other'
deviceOsstringNoAuto-detectedOperating system override. Values: 'android', 'ios', 'linux', 'mac', 'windows', 'tv', 'tvos', 'roku', 'tizen'
deviceOsVersionstringNoAuto-detectedOS version (e.g., '14.5', '11')
deviceManufacturerstringNo-Device manufacturer (e.g., 'Apple', 'Samsung', 'Sony')
browserTypestringNoAuto-detectedBrowser type (e.g., 'chrome', 'firefox', 'safari')
countrystringNoAuto-detected from IPISO-3166 alpha-2 country code (e.g., 'US', 'GB', 'DE')
countryNamestringNoAuto-detectedHuman-readable country name (e.g., 'United States')
regionstringNoAuto-detected from IPISO-3166 alpha-2 region code (e.g., 'CA' for California, 'NY' for New York)
regionNamestringNoAuto-detectedHuman-readable region name (e.g., 'California', 'New York')
citystringNoAuto-detected from IPCity name
dmastringNoAuto-detected from IPDesignated Market Area code for US locations
destinationstringNodocument.location.hrefCurrent page URL where the video is being played
sourcestringNodocument.referrerReferring page URL
playerIdstringNo-Custom identifier for the player instance
playerNamestringNo-Human-readable name for the player
applicationstringNo-Custom application identifier
debugLoggingbooleanNofalseEnable debug logging for troubleshooting

Example Configuration

const dataCollectionConfig = {
// Required
accountId: 123456,
videoId: 'video_abc123',

// Optional - Session tracking
sessionId: 'custom-session-uuid',
engagementEventInterval: 10000,

// Optional - QoE metrics (disabled by default for performance)
includeQoEMetrics: false,

// Optional - User identification
userId: 'hashed-user-id-sha256',

// Optional - Device information (auto-detected if not provided)
deviceType: 'tv',
deviceOs: 'tizen',
deviceOsVersion: '6.0',
deviceManufacturer: 'Samsung',

// Optional - Geographic data (auto-detected from IP if not provided)
country: 'US',
region: 'NY',
city: 'New York',
dma: '501',

// Optional - Player identification
playerId: 'my-custom-player',
playerName: 'Living Room TV',
application: 'my-tv-app',

// Optional - Debugging
debugLogging: false,
};

const brightcovePlayer =
await DefaultBrightcoveManager.createBrightcoveAdsPlayer(
player,
configuration.getLogger(),
promos,
adPlaybackPolicy,
dataCollectionConfig // Pass the config here
);

Tracked Events

The data collection feature automatically tracks the following mandatory events to Brightcove's metrics.brightcove.com endpoint:

Event NameDescription
player_loadSent when player is initialized
video_impressionSent when video metadata is loaded
play_requestSent when playback is requested
video_viewSent when video playback starts (after pre-roll ads)
video_engagementSent periodically during playback (interval configurable via engagementEventInterval, default: 10000ms / 10 seconds)
ad_mode_beginSent when an ad break starts
ad_mode_completeSent when an ad break ends
errorSent when playback errors occur

QoE Metrics (Optional)

When includeQoEMetrics: true, the following optional quality metrics are included in video_engagement events:

MetricDescription
rendition_urlURL of the current video rendition
rendition_indicated_bpsBitrate of the current rendition
rendition_mime_typeMIME type of the rendition
rendition_heightHeight of the video rendition in pixels
rendition_widthWidth of the video rendition in pixels
measured_bpsMeasured bandwidth (from playbackStatistics.estimatedBandwidth)
dropped_framesNumber of dropped frames (from playbackStatistics.droppedFrames)
player_widthPlayer width in pixels
player_heightPlayer height in pixels
note

QoE metrics are disabled by default to optimize performance on low-end devices. Enable only if you need detailed quality analytics.

Session Management

  • Session ID is automatically generated using UUID v4
  • Optionally override with a custom sessionId in the config
  • Session ID is consistent across all events in a tracking session

Performance Considerations

  • Minimal mode (default): Only sends mandatory events with required parameters
  • QoE mode: Subscribes to trackschanged events and extracts detailed metrics
  • For low-end devices (Smart TVs), keep includeQoEMetrics: false