Media Server Implementation (VideoJS)


    Introduction

       A media server refers either to a dedicated computer appliance or to a specialized application software, ranging from an enterprise class machine providing video on demand, to, more commonly, a small personal computer or NAS (Network Attached Storage) for the home, dedicated for storing various digital media (meaning digital videos/movies, audio/music, and picture files).

   Server requirements

1. Linux machine installed ffmpeg version 3.1.3(Version supported hls key encryption)
2. LAMP (PHP 5.5.0 at least)

Client requirements

1. Video JS 
2. Any browser (Chrome, firefox etc)

Techniques used

1. HLS (HTTP Live Streaming) 
2. AES HLS encryption

HLS: HTTP Live Streaming (also known as HLS) is an HTTP-based media streaming communications protocol implemented by Apple Inc. It is similar to MPEG-DASH in that it works by breaking the overall stream into a sequence of small HTTP-based file downloads, each download loading one short chunk of an overall potentially unbounded transport stream. As the stream is played, the client may select from a number of different alternate streams containing the same material encoded at a variety of data rates, allowing the streaming session to adapt to the available data rate. At the start of the streaming session, it downloads an extended M3U playlist containing the metadata for the various sub-streams which are available.

Encryption - AES 128 encrypted HLS with clear key encryption and keyserver. The content is encrypted with AES 128, and the manifest contains a link to a key that allows the decryption of the HLS content.

This alone is not providing security, since once the key is obtained, the content can be easily decrypted and redistributed. There are few mechanisms in place that allow to protect the key, such as serving it over HTTPs, or different token authentication models. It secures the content against most standard users trying to get the content, but is not considered DRM level content protection.

Actual Process: While uploading video to the server (Which is to be store in server and played using video js), Video encryption key info file is generated which is to be used for segment encryption. The first line of key_info_file specifies the key URI written to the playlist. The key URL is used to access the encryption key during playback. The second line specifies the path to the key file used to obtain the key during the encryption process. The key file is read as a single packed array of 16 octets in binary format. The optional third line specifies the initialization vector (IV) as a hexadecimal string to be used instead of the segment sequence number (default) for encryption.

Depending on the video resolution, we are generating two quality types segments - HD and SD. ie for lower resolution videos(Lets say height < 700), generates only SD segments, otherwise both. Then video is splitted into small chunks and creates a m3u8 file which specifies these chunks in the playback order and the key file location if the encryption is enabled. We are generating an xml file which contains the basic details of the videos like, title, duration and m3u8 file location(Both hd and sd).
Specify the generated m3u8 file location in video tag as source and we can play the video.

Note:
Add .htaccess file in the output folder to prevent listing of files when accessing the folder path directly in the browser(The htaccess content should be Options -Indexes).

Installation

The following linux packages needs to be installed.

   1. Mediainfo     

        apt-get install -y libav-tools x264 gpac mediainfo
        apt-get install -y wget libexpat1-dev libslang2-dev libncurses-dev build-essential
     
   2Yasm

        If yasm not found error occurs run the following commands:
            Download the latest version of Yasm: http://yasm.tortall.net/
            Type “wget http://www.tortall.net/projects/yasm/releases/yasm-1.3.0.tar.gz”
            Type ” tar -xvf yasm-1.3.0.tar.gz” to uncompressed the yasm-1.3.0.tar.gz file
            Type “cd yasm-1.3.0” , then Type ‘./configure‘ to create the configuration.
            Type ‘make‘ to build FFmpeg.
            Type ‘make install‘ to install all binaries and libraries you built.
            You can type “yasm –version” to verify if yasm is installed successfully.

   3. Xml-coreutils

         wget http://www.lbreyer.com/gpl/xml-coreutils-0.8.1.tar.gz
         tar xzf xml-coreutils-0.8.1.tar.gz
 cd xml-coreutils-0.8.1
 ./configure --prefix /usr/local
 make

 make install

  4. ffmpeg

 Download or clone ffmpeg from :
 https://github.com/FFmpeg/FFmpeg
 Extract the compressed folder
 cd extracted_folder_path
 ./configure --enable-libx264 --enable-gpl
 make

 make install


Reference

FFMPEG -  http://ffmpeg.org/ffmpeg-all.html
Video JS - http://docs.videojs.com/




No comments:

Post a Comment

Technologies

1. Nodejs
  • Express
  • Loopback
  • SailsJs
2. Angular
  • 2
  • 4
  • 5
  • 8
3. JQuery
4. PHP
  • LAMP
  • Codeigniter
  • Lumen
5. Database
  • MySQL
  • PostgreSQL
  • MongoDB
6. Artificial Intelligence
  • IBM Watson API
7. Amazon
  • S3
  • EC2
  • SES
  • ELB
8. REST & SOAP API integrations
9. Push notifications
  • FCM - Android
  • APNS - IOS
10. RETS(Real estate domain) servers
11. Standard Implementations
  • 508
  • LTI