AWS Video Processing Architecture in ASP.NET jMedia

This document provide detail about aws video processing architecture developed and utilized within ASP.NET jMedia

Overview

ASP.NET jMedia is a complete cloud enable media solution for managing, transcoding & streaming videos securely over cloud.

Regarding media, AWS provides various services for storing, transcoding and streaming media files. ASP.NET jMedia utilitzes not only the services provided by AWS Cloud Platform but also extends its services where it lacks.

There are two ways ASP.NET jMedia support AWS

  • Upload, process & save processed media files in cloud.
  • Upload and process media files directly within cloud.

This document focus on how the system works if utilizes AWS for upload & processings.

Features

ASP.NET jMedia utilizes various AWS cloud services to automate complex & heavy resource intense operation involve with video processing.

Core features involve

  • Uploads & directly save videos in S3 bucket.
  • Transcode uploaded video to various web & mobile streameable formats including MPEG-DASH, HLS, MP4 etc
  • Extract meta information from uploaded video e.g Duration, Width, Height etc
  • Generate multiple thumbnails from start to end of video.
  • Generate video preview clip to play preview on mouse over video thumbnail.
  • Generate short clip in case for previewing movie in free mode.
  • Process and save data in database.

These are operation happens within cloud infrastructure. Some features like transcoding videos directly supported by AWS, but you have to rely on third part tools and services when doing advance video processing including creating previews, extracting meta information from videos, generating thumbnails etc.

We built a complex unified solution for AWS that can be easily deploy and configure to achieve all video processing goales in one step that normally impossible or very complicated or time consuming

List of AWS services used by ASP.NET jMedia for video processing.

  • S3 For storing public and protected videos and thumbnails.
  • CloudFront for streaming public and protected videos.
  • Elastic Transcoder for transcoding & publishing videos.
  • Lambda for advance video processing.
  • SNS for communicating with other services while processing videos.

Uploading Videos to AWS

There are two ways ASP.NET jMedia supported for uploading and initializing video processing on uploaded videos.

  • Upload videos manually
  • Upload videos through Website

Upload Videos Manually

In this way you can upload videos directly to AWS S3 bucket under specific directory e.g uploads/ to trigger AWS Lambda function responsible for transcoding and processing video.

This option allow you to directly upload videos to AWS and it will be automatically processed and part of website with unapproved status in website. Site administrator will review, attach information and approve it for public view.

Upload videos through Website

In this way, videos will be uploaded by user via website using ASP.NET jMedia uploader. Once uploaded, AWS Lambda script will be initiated, process video and update information in database for uploaded video.

AWS Lambda Functions

ASP.NET jMedia uses few Lambda functions to automate the whole video processing operation. There are three core Lambda functions involved in whole operation.

  • i: jmediavideoconverter: This lambda function responsible for initiating elastic transcoder jobs for publishing uploaded video automatically.
  • ii: videoprocess: This lambda function responsible for doing advance operation including, exracting meta information, generating thumbnails from video, creating rotator video clip, creating preview clip and doing other advance operations utilizing third party scripts and utilities.
  • iii: jmediasnsnotifyv3: This lambda function responsible for inserting or updating video information in website.

List of each lambda function and their configuration includes

jmediavideoconverter

This lambda function is responsible for initiating publishing when video upload in S3 bucket under specific directory set via prefix..

This function need the following information to work according to your need.

  • PipelineID: It require the pipeline id of pipeline created and configure with selected bucket via Elastic Transcoder
  • Preset List: You can adjust preset list according to your publishing requirements. By default it support presets for 360p mp4, 480p mp4, 720p mp, mpeg-dash playlist, hls playlist.
  • Region: Set region for bucket, default 'us-east-1'

This lambda function need to be configured on S3: ObjectCreated event for each video type with specific directory prefix. e.g if videos uploaded in uploads/ directory, you have to setup prefix "uplodas/" and postifx extension of each allowed video types. You have to create event for every video type you want to support e.g ".flv, .mp4, .avi, .mov, .webm, .mpg

videoprocess

This is little bit complicated lambda function that relies on various third party tools including MediaInfo, FFMPEG etc for extracting meta information and generating thumbnails and preview clips

This lambda function have simple requirements including

  • i: bucketname: setup bucketname where videos are saved and to be saved after processing.
  • ii: thumbWidth: setup width of generating thumbnail.
  • iii: thumbHeight: setup height of generating thumbnail
  • iv: thumbnailprefix: directory path for saving thumbnails e.g thumbnails/
  • v: videouploadprefix: directory for published videos
  • vi: videoclipprefix: directory for saving clips
  • vii: total_thumbnail_capture: total number of thumbnails captured from start to end of video.
  • viii: cloudfrontUrl: cloud front streaming url for protected videos.
  • ix: cloudfrontUrl_public: cloud front streaming url for public videos
  • x: streamoutputs: output reference of all published contents e.g 'mp4_low,mp4_360,mp4_480,mp4_720,mpegdash, hls' shows that each video is published under low quality, 350p, 480p, 720p, mpeg-dash playlist, hls playlist to application. This is useful for preparing video player streaming settings based on available outputs.

jmediasnsnotifyv3

This function is responsible for saving processed media information in database.

It requires to setup database connectionstring for inserting or updating processed video informatin.

In case video uploaded directly via AWS S3, this lambda function will use to gather information and insert it as new record.

In case of video uploaded via website, it will update database record with processed media data.

By default it will uses the two directory uploads/ and siteuploads/ to make decision whether video is based on direct upload or website upload. In case of direct upload we configure solution in a way if site owner upload video under {bucket}/uploads/ directory, the lambda function will use insert operation. In case video uploaded in {bucket}/siteuploads/ the lambda function uses update opeartion.

AWS Architecture Configuration

There are various steps involved in properly configure the AWS Architecture for processing video and generating required outputs.

List of step include.

i: Create new bucket e.g jmedia2018

ii: Create required directories within created bucket including

  • uploads/ to be used for direct uploading vidoes by site owner or administrator.
  • siteuploads/ to be configured with website so that website videos uploaded here.
  • published/ to be used for saving published media files.
  • thumbnails/ to be used for creating thumbnails
  • previews/ to be used for saving video rotator previews.
  • clips/ to be used for saving video clips

iii: Next step is open created bucket and select permissions and update CORS Configuration to properly stream MPEG-DASH and HLS streams.


<CORSConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
<CORSRule>
<AllowedOrigin>*</AllowedOrigin>
<AllowedMethod>GET</AllowedMethod>
<MaxAgeSeconds>3000</MaxAgeSeconds>
<AllowedHeader>*</AllowedHeader>
</CORSRule>
</CORSConfiguration>

iv: Deploy all AWS Lambda functions with the following configurations.

  • i: jmediavideoconverter: create role to make sure it have fullaccess to Elastic Transcoder, S3 bucket and Lambda Basic Execution with timeout 5- 15 seconds and 50mb - 256mb
  • ii: videoprocess: create role with S3 FullAccess, SNS FullAccess, Lambda Basic Execution, timeout settings 30 - 40 seconds, memory greater than 1000mb recommended
  • iii: jmediasnsnotifyv3: create role with SNS FullAccess, Lambda Basic Execution, timeout settings 5 - 15 seconds, memory 100mb - 256mb

iv: Create two CloudFront web destribution for created Bucket. One for public contents and one for protected contents, once created, update cloudfront url paths, bucketname in videoprocess lambda function and save it.

v: Create Elastic Transcoder pipeline with settings shown in screenshot. Recommended to use same Bucket for both input and output files. Also make sure you must create SNS Topic for successfully published videos event as shown in screen below. Once created update pipeline id in jmediavideoconverter lamba function.

vi: After setup everything now need to setup triggers for each lambda function.

For jmediavideoconverter, you have to setup triggers for two directories within created bucket. uploads/ and siteuploads/ as shown in screenshot

You can create events under properties section of created bucket as shown in screen below.

Click on Events, then Add Notification then fill the form

  • Select ObjectCreate: All under Event section.
  • Enter prefix uploads/. Note: you have to repeast this process for creating new event for siteuploads/ separately.
  • Enter suffix .mp4. Note: you have to create event for each supported suffix separatly e.g .avi, .wmv, .mov, .webm etc
  • Select Lambda Function under send to.
  • Select jmediavideoconverter lambda to execute if matched creteria for this event.

Note: you have to repeate and create events for each prefix and suffix to make sure jmediavideoconverter trigger on every supported media type uploads within both uploads/ and siteuploads/ directories.

For videoprocess lambda function open lambda console under AWS Lambda management and attach SNS notification created with pipeline that pushed notification when videos successfully published as shown in screenshot.

For jmediasnsnotifyv3 lambda function first create new SNS notification under SNS management section and update SNS topic urn within videoprocess code to properly pushed processed media information

Once created, add new trigger for jmediasnsnotifyv3, attach SNS topic as shown below.

This sns topic automatically trigger jmediasnsnotifyv3 function to receive processed media information and save in database.

Articles