Server-side ad insertion (SSAI) is a method of inserting advertisements into streaming video content directly on the server side, rather than the client side. SSAI allows for smoother ad transitions, a more consistent user experience, and improved control over ad targeting, content delivery, and analytics.

This method addresses common challenges associated with client-side ad insertion, such as ad blocking and inconsistent ad playback, by providing a more seamless, server-controlled approach.

How SSAI Works

SSAI works by stitching ads directly into the video content stream on the server before it's delivered to the client. This process involves the server fetching video content, inserting an ad break, and re-encoding the content to ensure smooth playback without the need for client-side interaction.

The main steps in SSAI include:

  1. Video Content Fetching: The server retrieves the video content (VOD or live) from a media server or storage system.
  2. Ad Selection: Based on the user's profile, geographic location, or viewing history, relevant ads are selected for insertion.
  3. Ad Stitching: The server inserts the ads into the video stream at designated breakpoints. This is done by concatenating the video content and ad assets into a single stream.
  4. Encoding and Delivery: After the ad is inserted, the content is re-encoded (if necessary) and delivered to the client as a unified stream.

This method ensures that the ad is part of the original video stream and avoids the latency issues or disruptions that can occur with client-side ad insertion.

Server Side Ad-insertion

SSAI Integration with Streaming Protocols

SSAI works with popular streaming protocols like HLS (HTTP Live Streaming) and DASH (Dynamic Adaptive Streaming over HTTP) to deliver video content and ads.

SSAI with HLS

HLS is one of the most commonly used streaming protocols for delivering both live and VOD content. With SSAI, ads are inserted at specific breakpoints within the HLS playlist. The server generates a new HLS playlist that includes both video and ad segments, ensuring a smooth transition between content and ads without client-side intervention.

Ad Stitching in HLS: In HLS, ads are inserted into the .m3u8 playlist. SSAI involves creating custom HLS playlists with interspersed ad segments. The video and ad segments are then played in sequence as part of the overall streaming experience.

Example Command for SSAI with HLS:

code
ffmpeg -i main_video.mp4 -i ad_video.mp4 -filter_complex "[0][1]concat=n=2:v=1:a=1[out]" -map "[out]" -f hls -hls_time 4 -hls_list_size 0 output.m3u8

Explanation:

  • The command concatenates the main video and ad video as part of a single HLS stream.
  • -hls_time 4: Defines segment duration for the stream.
  • -hls_list_size 0: Ensures that all segments are included in the playlist, useful for VOD.

SSAI with DASH

DASH supports fragmented MP4 (fMP4), allowing ads to be seamlessly inserted into the video stream. SSAI tools combine video and ad segments into a single DASH stream with the necessary .mpd manifest.

Example Command for SSAI with DASH:

code
ffmpeg -i main_video.mp4 -i ad_video.mp4 -filter_complex "[0][1]concat=n=2:v=1:a=1[out]" -map "[out]" -f dash -dash_segment_filename "segment_%03d.m4s" -master_pl_name "master.mpd" output.mpd

Explanation:

  • This command generates a unified video and ad stream in DASH format.
  • -dash_segment_filename "segment_%03d.m4s": Specifies the naming pattern for DASH segments.
  • -master_pl_name "master.mpd": Creates a master manifest file.

Best Practices for Implementing SSAI

Ad Stitching Quality

Use proper encoding parameters to ensure that the ad stitching process does not introduce noticeable visual artifacts or latency. Additionally, use high-quality encoding for both the video and ad content to maintain visual consistency.

Command for Encoding Ads and Video with FFmpeg:

code
ffmpeg -i main_video.mp4 -i ad_video.mp4 -c:v libx264 -crf 23 -preset slow -f mpegts output_stream.ts

Explanation:

  • -c:v libx264: Uses H.264 codec for encoding.
  • -crf 23: Constant Rate Factor to balance file size and quality.
  • -preset slow: Provides higher quality compression at the cost of encoding time.

Dynamic Ad Insertion

For dynamic ad insertion, ensure the SSAI system can adjust ad placement based on real-time data. For instance, ads can be targeted to specific users based on their location or viewing behavior. Implementing real-time ad decisioning systems can improve ad relevance and performance.

Secure Delivery

Incorporate DRM and encryption mechanisms to protect both video and ads from piracy or unauthorized redistribution. Use secure protocols like HTTPS for delivery and integrate with existing DRM solutions like FairPlay, Widevine, or PlayReady for content protection.