Create SMIL file in NodeJS

Posted By : Chandan Kumar Singh | 05-Jan-2017

SMIL NodeJS

In this blog we will write smil (Synchronized Multimedia Integration Language
)  files by nodejs program using fs module. As we know smil files enable us to group the high bitrate stream and the new renditions together in logical groups for live adaptive bitrate delivery.

 

We have a array with  3 different bitrate and width of video. We have named video as width of video, example 360.mp4, 480.mp4, 640.mp4.

 var bitRate = [{
    "width": 640,
    "bit_rate": "600k"
}, {
    "width": 480,
    "bit_rate": "400k"
}, {
    "width": 360,
    "bit_rate": "200k"
}];
function createSmilFile(){
var smilefile = "";
for (var i = 0; i < bitRate.length; i++) {
       var bit = bitRate[i].bit_rate;
       bit = bit.replace("k", '000');
smilefile = smilefile+"<video src='" + bitRate[i].width + ".mp4" +
 "' type='video/mp4'> <param name='videoBitrate' value='" +
 bit + "' valuetype='data'> </param> </video >";
}
smilefile = smilefile + "</switch > </body > </smil > ";
 var smil_file_name = test + ".smil";
fs.writeFile( '/opt/smil/' + smil_file_name, smilefile, function(err) {
               if (err) {
                  console.error("error in create smil file: ", err);
               } else {
                   console.log("smil file created successfully");
               }
           });

 

THANKS

About Author

Author Image
Chandan Kumar Singh

Chandan is a bright Web Developer with expertise in Java and Spring framework and ORM tools Hibernate. He loves technologies like Blockchain and IoT.

Request for Proposal

Name is required

Comment is required

Sending message..