Skip to main content

Create Apple HLS video stream using AWS S3 Bucket, Cloud Front, Elastic Transcoder ,Lambda function | Make your own Netflix or YouTube | Create video stream

Create Apple HLS video stream  using AWS S3 Bucket, Cloud Front,  Elastic Transcoder ,Lambda function, Make your own Netflix or YouTube,  Create video stream

Make HLS Stream using AWS (S3 Bucket, Cloud Front, Elastic Transcoder ,Lambda function ) | Make your own Netflix or YouTube

1. Create source (input) S3 bucket  
2. Create destination (output) s3 bucket
3. Create cloud-front for Serve data 
4. Setup Elastic transcoder (Create pipeline, Create job, Job execute)
5. Create role for lambda function 
6. Create lambda function and create trigger and write program add access role
7. Check Lambda function logs in cloud-watch 
8. Generate Key Management Service for transcoder pipeline 
9. Configure transcoder pipeline 
10. Configure  transcoder job with aes-128 encryption 
11. Modify lambda function 


1. Create source (input) S3 bucket  

    Create new S3 bucket
Create Apple HLS video stream  using AWS S3 Bucket, Cloud Front,  Elastic Transcoder ,Lambda function, Make your own Netflix or YouTube,  Create video stream

Create Folder

Create Apple HLS video stream  using AWS S3 Bucket, Cloud Front,  Elastic Transcoder ,Lambda function, Make your own Netflix or YouTube,  Create video stream, mrlokesh


2. Create destination (output) s3 bucket

Create new s3 bucket 
Create Apple HLS video stream  using AWS S3 Bucket, Cloud Front,  Elastic Transcoder ,Lambda function, Make your own Netflix or YouTube,  Create video stream, mrlokesh

Set block all public access 

Create Apple HLS video stream  using AWS S3 Bucket, Cloud Front,  Elastic Transcoder ,Lambda function, Make your own Netflix or YouTube,  Create video stream, mrlokesh

Set CORS configuration 


<?xml version="1.0" encoding="UTF-8"?>
<CORSConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
<CORSRule>
    <AllowedOrigin>*</AllowedOrigin>
    <AllowedMethod>GET</AllowedMethod>
    <MaxAgeSeconds>3000</MaxAgeSeconds>
    <AllowedHeader>Authorization</AllowedHeader>
</CORSRule>
<CORSRule>
    <AllowedOrigin>http://localhost:4200</AllowedOrigin>
    <AllowedMethod>GET</AllowedMethod>
    <MaxAgeSeconds>3000</MaxAgeSeconds>
    <AllowedHeader>Authorization</AllowedHeader>
</CORSRule>
</CORSConfiguration>


Create Apple HLS video stream  using AWS S3 Bucket, Cloud Front,  Elastic Transcoder ,Lambda function, Make your own Netflix or YouTube,  Create video stream, mrlokesh

3. Create cloud-front for Serve data 

Go to cloud-front Distributions
Create Distributions

Create Apple HLS video stream  using AWS S3 Bucket, Cloud Front,  Elastic Transcoder ,Lambda function, Make your own Netflix or YouTube,  Create video stream, mrlokesh

 Select WEB click on get started

Create Apple HLS video stream  using AWS S3 Bucket, Cloud Front,  Elastic Transcoder ,Lambda function, Make your own Netflix or YouTube,  Create video stream, mrlokesh

Select Origin Domain Name s3 bucket name 
Origin Path is is folder name start  with ‘/’
Restrict bucket access =>  yes
Origin access identity => create new identity 
Grant read permissions  on bucket => yes update bucket policy 

Create Apple HLS video stream  using AWS S3 Bucket, Cloud Front,  Elastic Transcoder ,Lambda function, Make your own Netflix or YouTube,  Create video stream, mrlokesh

Viewer protocol policy => HTTP and HTTPS

Allowed HTTP methods => GET,HEAD,OPTION

Cached HTTP Method => check OPTIONS

Object caching => select use origin cache header

Smooth streaming => No

Restrict viewer access => no

Compress object automatically => No


Create Apple HLS video stream  using AWS S3 Bucket, Cloud Front,  Elastic Transcoder ,Lambda function, Make your own Netflix or YouTube,  Create video stream, mrlokesh
Create Apple HLS video stream  using AWS S3 Bucket, Cloud Front,  Elastic Transcoder ,Lambda function, Make your own Netflix or YouTube,  Create video stream, mrlokesh

Click on create distribution 
Create Apple HLS video stream  using AWS S3 Bucket, Cloud Front,  Elastic Transcoder ,Lambda function, Make your own Netflix or YouTube,  Create video stream, mrlokesh

Create Apple HLS video stream  using AWS S3 Bucket, Cloud Front,  Elastic Transcoder ,Lambda function, Make your own Netflix or YouTube,  Create video stream, mrlokesh


If status in Deployed click on id and check again 
Create Apple HLS video stream  using AWS S3 Bucket, Cloud Front,  Elastic Transcoder ,Lambda function, Make your own Netflix or YouTube,  Create video stream, mrlokesh

Check setting

Create Apple HLS video stream  using AWS S3 Bucket, Cloud Front,  Elastic Transcoder ,Lambda function, Make your own Netflix or YouTube,  Create video stream, mrlokesh

Create Apple HLS video stream  using AWS S3 Bucket, Cloud Front,  Elastic Transcoder ,Lambda function, Make your own Netflix or YouTube,  Create video stream, mrlokesh

Create Apple HLS video stream  using AWS S3 Bucket, Cloud Front,  Elastic Transcoder ,Lambda function, Make your own Netflix or YouTube,  Create video stream, mrlokesh

Create Apple HLS video stream  using AWS S3 Bucket, Cloud Front,  Elastic Transcoder ,Lambda function, Make your own Netflix or YouTube,  Create video stream, mrlokesh

Create Apple HLS video stream  using AWS S3 Bucket, Cloud Front,  Elastic Transcoder ,Lambda function, Make your own Netflix or YouTube,  Create video stream, mrlokesh

Create Apple HLS video stream  using AWS S3 Bucket, Cloud Front,  Elastic Transcoder ,Lambda function, Make your own Netflix or YouTube,  Create video stream, mrlokesh

Create Apple HLS video stream  using AWS S3 Bucket, Cloud Front,  Elastic Transcoder ,Lambda function, Make your own Netflix or YouTube,  Create video stream, mrlokesh

4. Setup Elastic transcoder (Create pipeline, Create job, Job execute)

Go to Elastic Transcoder 
Click on create new pipeline 

Write pipeline name
Select input bucket 
Select default role

Create Apple HLS video stream  using AWS S3 Bucket, Cloud Front,  Elastic Transcoder ,Lambda function, Make your own Netflix or YouTube,  Create video stream, mrlokesh


Configuration for Amazon S3 Bucket for Transcoded Files and Playlists
Select output bucket 
Storage class => standard
Add permission =>
Grantee type => Amazon s3 group 
Grantee => all user 
Access => check Open/Download 

Create Apple HLS video stream  using AWS S3 Bucket, Cloud Front,  Elastic Transcoder ,Lambda function, Make your own Netflix or YouTube,  Create video stream, mrlokesh

Configuration for Amazon S3 Bucket for Thumbnails

Select output bucket for thumb
Storage class => standard 
Add permission => 
Grantee type => amazon s3 group 
Grantee => all users
Access => checked open/Download

Create Apple HLS video stream  using AWS S3 Bucket, Cloud Front,  Elastic Transcoder ,Lambda function, Make your own Netflix or YouTube,  Create video stream, mrlokesh

Create Apple HLS video stream  using AWS S3 Bucket, Cloud Front,  Elastic Transcoder ,Lambda function, Make your own Netflix or YouTube,  Create video stream, mrlokesh
Click on save
Create Apple HLS video stream  using AWS S3 Bucket, Cloud Front,  Elastic Transcoder ,Lambda function, Make your own Netflix or YouTube,  Create video stream, mrlokesh



Create job
Click on Create new job
Create Apple HLS video stream  using AWS S3 Bucket, Cloud Front,  Elastic Transcoder ,Lambda function, Make your own Netflix or YouTube,  Create video stream, mrlokesh

Select pipeline
Output key prefix is basically folder name start with ‘/’
Select input detail 

Create Apple HLS video stream  using AWS S3 Bucket, Cloud Front,  Elastic Transcoder ,Lambda function, Make your own Netflix or YouTube,  Create video stream, mrlokesh

Output Details 
Select Preset = > system preset: HLS 400k
Segment duration => 10
Output key (file name)=> hls_out_400k1

If you want multiple output click on “add another output”
Create Apple HLS video stream  using AWS S3 Bucket, Cloud Front,  Elastic Transcoder ,Lambda function, Make your own Netflix or YouTube,  Create video stream, mrlokesh

Click on add playlist
Create Apple HLS video stream  using AWS S3 Bucket, Cloud Front,  Elastic Transcoder ,Lambda function, Make your own Netflix or YouTube,  Create video stream, mrlokesh

Write playlist name
Select format=> HLSv3
Add output master playlist
Then click create new job 
Create Apple HLS video stream  using AWS S3 Bucket, Cloud Front,  Elastic Transcoder ,Lambda function, Make your own Netflix or YouTube,  Create video stream, mrlokesh

Create Apple HLS video stream  using AWS S3 Bucket, Cloud Front,  Elastic Transcoder ,Lambda function, Make your own Netflix or YouTube,  Create video stream, mrlokesh

After your job status is complete go on s3 output bucket and check output files are created or not 

5. Create role for lambda function 

Create new role for assign lambda function 
Simply click on create role 

Create Apple HLS video stream  using AWS S3 Bucket, Cloud Front,  Elastic Transcoder ,Lambda function, Make your own Netflix or YouTube,  Create video stream, mrlokesh
select lambda and go next
Create Apple HLS video stream  using AWS S3 Bucket, Cloud Front,  Elastic Transcoder ,Lambda function, Make your own Netflix or YouTube,  Create video stream, mrlokesh

Add this three policy's

1.       AmazonElasticTranscoder_FullAccess

2.       AmazonS3FullAccess

3.       AWSLambdaBasicExecutionRole

And go to next 

Create Apple HLS video stream  using AWS S3 Bucket, Cloud Front,  Elastic Transcoder ,Lambda function, Make your own Netflix or YouTube,  Create video stream, mrlokesh

Create Apple HLS video stream  using AWS S3 Bucket, Cloud Front,  Elastic Transcoder ,Lambda function, Make your own Netflix or YouTube,  Create video stream, mrlokesh

Write role name  and click on create role
Create Apple HLS video stream  using AWS S3 Bucket, Cloud Front,  Elastic Transcoder ,Lambda function, Make your own Netflix or YouTube,  Create video stream, mrlokesh

6. Create lambda function and create trigger and write program 

Simply click on “create  function “

Create Apple HLS video stream  using AWS S3 Bucket, Cloud Front,  Elastic Transcoder ,Lambda function, Make your own Netflix or YouTube,  Create video stream, mrlokesh

Write function name 
Select node.js for programming 
Create Apple HLS video stream  using AWS S3 Bucket, Cloud Front,  Elastic Transcoder ,Lambda function, Make your own Netflix or YouTube,  Create video stream, mrlokesh

Select => use existing role 
Create Apple HLS video stream  using AWS S3 Bucket, Cloud Front,  Elastic Transcoder ,Lambda function, Make your own Netflix or YouTube,  Create video stream, mrlokesh
Then click on create function
Create Apple HLS video stream  using AWS S3 Bucket, Cloud Front,  Elastic Transcoder ,Lambda function, Make your own Netflix or YouTube,  Create video stream, mrlokesh

after add trigger
Create Apple HLS video stream  using AWS S3 Bucket, Cloud Front,  Elastic Transcoder ,Lambda function, Make your own Netflix or YouTube,  Create video stream, mrlokesh

Select S3 
Select input bucket 
Select event type => all object create event 
Write prefix (folder name)
Finally click on add 
Create Apple HLS video stream  using AWS S3 Bucket, Cloud Front,  Elastic Transcoder ,Lambda function, Make your own Netflix or YouTube,  Create video stream, mrlokesh

click on your function name
Create Apple HLS video stream  using AWS S3 Bucket, Cloud Front,  Elastic Transcoder ,Lambda function, Make your own Netflix or YouTube,  Create video stream, mrlokesh

and write this program

***************start

var aws = require('aws-sdk');

var elastictranscoder = new aws.ElasticTranscoder();

 

// return filename without extension

function baseName(path) {

   return path.split('/').reverse()[0].split('.')[0];

}

 

exports.handler = function(event, context) {

    console.log('Received event:', JSON.stringify(event, null, 2));

    var key = event.Records[0].s3.object.key;

    var outputPrefix = baseName(key);

 

    var params = {

      Input: {

        Key: key

      },

      PipelineId: '1577189858990-pxg05d', /*Your Elastic Transcoder Pipeline Id*/

      OutputKeyPrefix: 'videocontent/', /*output folder name*/

      Outputs: [   

        {

          Key: outputPrefix + '_hls_out_600k', /*write output prefix filename*/

          PresetId: '1351620000001-200040', /*select your preset and and write this preset id*/

          SegmentDuration: '10',

        }

      ],

      Playlists: [

        {

            Format: 'HLSv3', /*this for formate*/

            Name: outputPrefix, /*this playlist name is same as file name*/

            OutputKeys: [outputPrefix + '_hls_out_600k'] /*add all output prefix file name*/

        }

      ]

    };

 

    elastictranscoder.createJob(params, function(err, data) {

      if (err) console.log(err, err.stack); // an error occurred

      else     console.log(data);           // successful response

    });

};

 

*****************end

 

Create Apple HLS video stream  using AWS S3 Bucket, Cloud Front,  Elastic Transcoder ,Lambda function, Make your own Netflix or YouTube,  Create video stream, mrlokesh

If you want to test  , configure test event
Select event template => Amazon S3 put
Write event name => tests3

************************start
{
  "Records": [
    {
      "eventVersion": "2.0",
      "eventSource": "aws:s3",
      "awsRegion": "ap-south-1",
      "eventTime": "1970-01-01T00:00:00.000Z",
      "eventName": "ObjectCreated:Put",
      "userIdentity": {
        "principalId": "EXAMPLE"
      },
      "requestParameters": {
        "sourceIPAddress": "127.0.0.1"
      },
      "responseElements": {
        "x-amz-request-id": "EXAMPLE123456789",
        "x-amz-id-2": "EXAMPLE123/5678abcdefghijklambdaisawesome/mnopqrstuvwxyzABCDEFGH"
      },
      "s3": {
        "s3SchemaVersion": "1.0",
        "configurationId": "testConfigRule",
        "bucket": {
          "name": "videostreamingapp",
          "ownerIdentity": {
            "principalId": "AHDSKDKDF876"
          },
          "arn": "arn:aws:s3:::videostreamingapp"
        },
        "object": {
          "key": "videocontent/3211lambda.mp4",
          "size": 1024,
          "eTag": "0123456789abcdef0123456789abcdef",
          "sequencer": "0A1B2C3D4E5F678901"
        }
      }
    }
  ]
}

*********************end

Finish this all work and click on save and click on test for fire test event if your output is proper and check transcoder job count is increase and your output file are generated properly mines  your lambda function working fine


7. Check Lambda function logs in cloud-watch 

If you want to see lambda function logs simply go to cloud-watch 
Create Apple HLS video stream  using AWS S3 Bucket, Cloud Front,  Elastic Transcoder ,Lambda function, Make your own Netflix or YouTube,  Create video stream, mrlokesh

Click on “logs” then click on “let’s get started”
Create Apple HLS video stream  using AWS S3 Bucket, Cloud Front,  Elastic Transcoder ,Lambda function, Make your own Netflix or YouTube,  Create video stream, mrlokesh

Select your function name
Create Apple HLS video stream  using AWS S3 Bucket, Cloud Front,  Elastic Transcoder ,Lambda function, Make your own Netflix or YouTube,  Create video stream, mrlokesh

And select task for view detail logs 
Create Apple HLS video stream  using AWS S3 Bucket, Cloud Front,  Elastic Transcoder ,Lambda function, Make your own Netflix or YouTube,  Create video stream, mrlokesh

8. Generate “Key Management Service(KMS)” for transcoder pipeline 

Go to key management service and simply click on “create key”
In Key administrators ADD “Elastic_Transcoder_Default_Role”
In Key users ADD “Elastic_Transcoder_Default_Role”
And 
Add tags Key: transpipe ,  Value: transpipejob

Create Apple HLS video stream  using AWS S3 Bucket, Cloud Front,  Elastic Transcoder ,Lambda function, Make your own Netflix or YouTube,  Create video stream, mrlokesh

Create Apple HLS video stream  using AWS S3 Bucket, Cloud Front,  Elastic Transcoder ,Lambda function, Make your own Netflix or YouTube,  Create video stream, mrlokesh

Create Apple HLS video stream  using AWS S3 Bucket, Cloud Front,  Elastic Transcoder ,Lambda function, Make your own Netflix or YouTube,  Create video stream, mrlokesh

9. Configure transcoder pipeline 

Simply copy ARN in Your KMS and goto transcoder pipeline and edit your pipeline and 

Encryption panel AWS KMS Key ARN select custom  and paste this ARN in this textbox and click on save

Create Apple HLS video stream  using AWS S3 Bucket, Cloud Front,  Elastic Transcoder ,Lambda function, Make your own Netflix or YouTube,  Create video stream, mrlokesh

10. Configure  transcoder job with aes-128 encryption 

Copy you old HLS working jobs go on Playlist section in content protection select HLS AES 
Key Storage Policy: select With Variant Playlists
Checked  Auto generate encryption key

Finally click on create job 
Create Apple HLS video stream  using AWS S3 Bucket, Cloud Front,  Elastic Transcoder ,Lambda function, Make your own Netflix or YouTube,  Create video stream, mrlokesh

11. Modify lambda function 

Configure playlist section in lambda function 


  Playlists: [
        {
            Format: 'HLSv3',
            Name: outputPrefix,
            OutputKeys: [outputPrefix + '_hls_out_600k'],
            HlsContentProtection: {
              Method: 'aes-128',
              KeyStoragePolicy: "WithVariantPlaylists"
            }
        }
      ]
Create Apple HLS video stream  using AWS S3 Bucket, Cloud Front,  Elastic Transcoder ,Lambda function, Make your own Netflix or YouTube,  Create video stream, mrlokesh

**********************start 

var aws = require('aws-sdk');
var elastictranscoder = new aws.ElasticTranscoder();

// return filename without extension
function baseName(path) {
   return path.split('/').reverse()[0].split('.')[0];
}

exports.handler = function(event, context) {
    console.log('Received event:', JSON.stringify(event, null, 2));
    var key = event.Records[0].s3.object.key;
    var outputPrefix = baseName(key);

    var params = {
      Input: { 
        Key: key
      },
      PipelineId: '1579157724628-1vsykj', /*Your Elastic Transcoder Pipeline Id*/
      OutputKeyPrefix: 'videocontent/',
      Outputs: [    
        {
          Key: outputPrefix + '_hls_out_600k',
          PresetId: '1351620000001-200040', // HLS v3 and v4 (Apple HTTP Live Streaming), 600 kilobits/second, Video-only
          SegmentDuration: '10',
        }
      ],
      Playlists: [
        {
            Format: 'HLSv3',
            Name: outputPrefix,
            OutputKeys: [outputPrefix + '_hls_out_600k'],
            HlsContentProtection: {
              Method: 'aes-128',
              KeyStoragePolicy: "WithVariantPlaylists"
            }
        }
      ]
    };

    elastictranscoder.createJob(params, function(err, data) {
      if (err) console.log(err, err.stack); // an error occurred
      else     console.log(data);           // successful response
    });
};

**********************end

If you like this blog so pls share and Write Comments about Your experience,
Thank You.


Comments

Popular posts from this blog

What is OOP (objects oriented programming) in C#

 What is OOP? in C# OOP is Object Oriented programming miens contain methods and data in objects it's called objects oriented programming(OOP) OOP Advantages Provides clear visibility and code for the programs easier to maintain, modify and debug Faster development easier and faster to execute create reusable code make your code neat and clean and easy to understand What is Class and objects in C# Class and object are the two main points of OOP (object oriented programming), when fruit is a class then Apple, Guava, Banana,  is object, when the individual objects are created they inherits all variables and method form the class, class is a template for the objects and object is instance of the class If you like this blog so pls share and  Write Comments  about Your experience, Thank You.

Make api in DotNet Core in 10sec | Create universal api for SQL server

Make API in Dot Net Core in 10sec | Create universal API for SQL server Universal API is great concept for app and angular developer need only connect to data base add table name and access table crud operation using API's  If you like this blog so pls share and  Write Comments  about Your experience, Thank You.

How to Optimize Your LinkedIn Profile as a Software Developer: Tips for Success

How to Optimize Your LinkedIn Profile as a Software Developer: Tips for Success To make your LinkedIn profile more attractive and discoverable as a software developer, you should focus on creating a compelling profile that showcases your skills, experience, and potential. Below are some specific strategies: 1. Professional Profile Picture Use a clear, professional photo where you look approachable and confident. A headshot with a neutral background works well. 2. Headline Your headline should be more than just your job title. Make it a powerful value proposition. Consider including: Your current role, tech stack, or specialization. Highlight key skills (e.g., "JavaScript | React | Node.js | Full-Stack Developer"). Optional: Include a personal tagline (e.g., "Building innovative web applications that solve real-world problems"). Example: "Full-Stack Developer | React, Node.js, Python | Passionate About Clean Code & Scalable Systems" 3. Summary (About Se...