Author Archives: Vibhav Sinha

Set IP Geo restriction on videos via API/Dashboard: VdoCipher DRM

VdoCipher provides a complete DRM with encryption, backend licensing and viewer specific watermarking to safeguard video content. Sometimes owing to the rights and permissions to distribute a video, businesses look to white-list or blacklist content for certain geographies & IPs. Here is an API guide to do IP & Geo restriction for your VdoCipher account. This should allow you to configure any complicated setting of IP and country restrictions.

Rules are defined by a JSON string called rule-set. This JSON contains an array of rule objects:

  1. Every rule is an object containing action, ipSet and countrySet
  2. Each matching rule overrides the previous matching rule.
  3. Action can be either ‘true’ or ‘false’, whether to allow or deny
  4. ipSet and countrySet are string arrays.
  5. Subnet CIDR block can also be set in ipSet string array.
  6. Both IPv4 and IPv6 addresses and subnet are allowed
  7. countrySet has two-digit country codes (ISO 3166-1 alpha-2.).
  8. Empty set matches everything of that type.
[
  {
    "action": "false",
    "ipSet": ["122.0.0.0/16", "49.323.23.56"],
    "countrySet": []
  },
  {
    "action": "true",
    "ipSet": [],
    "countrySet": ["IN", "GB"]
  }
]

The first part of above code will block your videos from playing in the mentioned IP addresses. The second part of the code will allow the video to play only in countries – UK & India. As mentioned in point 2 , the second rules is the dominant one for common users. Thus as an example, if some user has IP – 49.323.23.56 and resides in UK, his videos will not play. So various combination of codes can be used to create custom restrictions. If there is any confusion, drop us a mail and we can provide sample codes.

Benefit of subnet restriction is that you don’t have to write specifically multiple IP addresses. You can configure it to restrict a group of IPs under subnet.

API for setting IP-Geo restriction is the same as the video update API as provided in docs.

Here is a sample HTTP Request:

POST https://dev.vdocipher.com/api/videos/______________
Content-Type: application/json'
Accept: application/json
Authorization: Apisecret ____________

{
  "ipGeoRules": "string_containing_json_encoded_ruleset"
}

Dashboard interface for IP & GEO restriction

*This feature is also present in dashboard. Please click on the top right circular button on any video to open video settings. In it, there will be an IP/geo restriction section. Using above documentation, you can add any restriction.

Let us know at info@vdocipher.com for queries & doubts.

IP & Geo Restrict Video DRM

Import videos from S3 bucket with “Import from AWS S3”

Import videos directly from Amazon S3 bucket to VdoCipher for secure video hosting

Import videos directly from Amazon S3 bucket to VdoCipher for secure video hosting

AWS is the most popular cloud service provider at the moment and a lot of our customers have their videos stored in their S3 bucket. Their usual method of import was to generate temporary download URL and using them to import videos. This usually involved a bit of programming to AWS S3 API. With this new feature, we plan to make import videos from S3 to VdoCipher process a lot easier.

Steps to import videos from S3 Bucket

Import from AWS S3 for Secure Video Streaming

Interface for Importing video from AWS S3 Bucket for secure video hosting

  1. You need to create a new IAM user in your AWS account with the permission to do action ListObjects and GetObjects in the desired bucket. AWS IAM console will give you the aws_access_key_id and aws_secret_key.
  2. In your VdoCipher dashboard, click on import and chose the option to “import from S3”.
  3. You can enter the region, bucket, key_id, and secret_key. Upon connecting, you will see a list of your root objects and you can navigate around like a regular file browser.
  4. On clicking the import button, our backend will create temporary download URL for the video object and add it to your list of videos. You will be able to see the video id and current status.
  5. Once you have the videos imported, you can go back to the dashboard to set correct title, description, and tags for the video. Adding tags is recommended because it helps to sort and manage your videos. The files should now be processing. Give the video some time to process. Once their status is ready, you can embed it in your website or mobile app.

Any file with video extensions will have an import button. Currently, we support five extensions (MP4, AVI, FLV, WMV, MOV). Let us know, if you like to have another file extension in this list. learn more about using the dashboard

Permission required for IAM key

AWS recommends creating a new IAM user for every purpose. In this case, you should create a new user with permission to ListBucket and GetObject. Here is a sample policy file that you can use for this purpose. Replace the NAME_OF_BUCKET with the real name of your bucket.

Auto play, Loop Video, Time Calculation, Custom Video Player

Many a times , video streaming sites look to autoplay the video through the video player as soon as the page is loaded. Also, you may wish to loop the media in video player and present the content again and again to same viewer. It is generally desired that the bandwidth does not get consumed again on the same page, when video is repeated.

Some of you may want to hide player skin, or use custom colors and controls for the video player. Certain times, you will need to get total time viewed by each viewer for each video to put certain restrictions on the user.

VdoCipher along with secure video streaming aims to provide a complete suit to our customers to make custom player. Here are the details for the following functionalities. Do check our embed api first to see how to embed videos.

  1. Autoplay in video player

    Here is the code –

    window.onVdoCipherAPIReady = function(){
       var videos = vdo.getObjects(); // use global variable vdo to query
       var video = videos[videos.length - 1];
       video.addEventListener('loaded', function(){
           video.start(); // set video to autoplay
       });
    }

    Just add this to your html will cause the video to autoplay

  2. Loop Video in player – Replay the video when it reaches end

    window.onVdoCipherAPIReady = function(){
       var videos = vdo.getObjects(); // use global variable vdo to query
       var video = videos[videos.length - 1];
       video.addEventListener('end', function(){
           video.seek(0);
       });
    }
  3. Time Calculation per video playback

<div id="vdo<?= $OTP ?>" style="height: 300px; width: 520px;"></div>
<input type="text" id="totalPlayed" value="" />

/// this is the embed code

<script>
    (function(v,i,d,e,o){v[o]={}; v[o].a = v[o].a || function V(a){ (v[o].d=v[o].d||[]).push(a);};
    if(!v[o].l) { v[o].l=1*new Date(); a=i.createElement(d), m=i.getElementsByTagName(d)[0];
    a.async=1; a.src=e; m.parentNode.insertBefore(a,m);}
    })(window,document,'script','//de122v0opjemw.cloudfront.net/vdo.js','vdo');
    vdo.a({
        o: "<?= $OTP ?>",
    });
</script>

/// this is the script

<script>		
function onVdoCipherAPIReady(){
    console.log("VdoCipher API init");
    var videoObjects = vdo.getObjects();
    var video_ = videoObjects[0];
    video_.addEventListener("ready", function(data){
        console.log("ready event called" , data);
    });
    video_.addEventListener("progress", function(data){
        document.getElementById('totalPlayed').value = data.totalPlayed;
    });
    }
</script>

Note: Make sure you are using the latest embed script in your code as described at https://www.vdocipher.com/page/api.curl

A formal JS API for specific player functions is coming up.

5. Custom Video Player – Beta Feature

This is the link to custom video player – the colors, controls, themes , call to actions on the video player all can be customized.

https://www.vdocipher.com/page/mpml
https://www.vdocipher.com/files/c58f5a32961/demo/

For a free full version 5GB  secure video streaming , custom video player trial, Sign up at VdoCipher.

 

Custom Video Player

Custom Video Player – Autoplay, Loop video

Where does VdoCipher DRM video fit in your tech stack.

Traditional Video integration

In case of most media integration, a static media URL is sent to the client. The client can use this to begin playing media. A client in this case can be either a web app or a mobile/tv application. The data to provided to the client is a long-lived url which can be used multiple times.

DRM video integration

When you are working with premium content, a requirement for secure video hosting is that you give only a one-time usable resource. This URL to DRM video should be generated only when the client is authenticated and has the permission to get access to the file. Only the server component has the authority to generate this temporary resource access.

DRM Video for Secure Video Hosting

Workflow for DRM videos

In case of Vdocipher, the temporary access URL is the otp while the authority to generate this OTP is the api secret key.

The API secret key must never be shipped along with the app code. The app SDK just needs an OTP for playback. Hence, the right way of doing this is to create an API endpoint as part of the app backend that you already have. This API endpoint should receive an authenticated HTTP request for playing a video (assuming you are authenticating users by some means such as login, etc.) and respond with an OTP. It is the backend system which should be responsible for making API calls. The viewer simply asks to play a particular video. This is followed by an access check on your web server. Your web server then takes the VdoCipher id for that video, and calls for OTP on the VdoCipher API.

A workflow in this case will be:
1. Client logs in and has an auth token for your backend framework
2. Client requests to play that hot new video.
3. Your Backend translates that hot new video into the corresponding VdoCipher id
4. Your Backend makes the API call to Vdocipher to get an otp.
5. Your Backend responds to the request with OTP
6. Client uses this OTP to play the video.

Setting desired bitrate for video playback for multiple devices

Different devices and internet speeds require different bitrate to be served. Based on device type and your viewer connection, some of you may opt to provide particular bitrates forcefully.  Often you like to provide playback at the certain quality or constrain the network data. Bitrate, Dimensions ,Quality thus can be configured. Below are the steps.

First, Send in an extra parameter while setting up the otp. Append a post parameter called “forcedBitrate”. This need to be an integer. During load time, the player obtains the list of available resolutions from the server. If the forcedBitrate is set, it starts playing the bitrate which is closest to that one.

Example

If you have a video with bitrates created at [300, 900, 1500, 2100].  By default, the player will try to guess the correct bitrate based on a number of factors. If you believe that the default rate should be 900, set the value of forcedBitrate to 900. If the forcedBitrate is set to 1100, then player will calculate the bitrate closest to it and play it. This will ensure that the player will continue playing inspire of any error.

Here is a sample curl command for the otp call with forcedBitrate included:

curl 'http://api.vdocipher.com/v2/otp?video=xxxxxxxxxxxxxx' -H 'Content-Type: application/x-www-form-urlencoded' --data 'clientSecretKey=CLIENT_SECRET_KEY&forcedBitrate=1100'

Check the Api page under /otp for more info and other APIs.

ASP.net C# web forms embed vdocipher video

The following code is the complete set up for embedding video in ASP.NET Web forms using vdocipher secure streaming. This code has been generated using Visual Studio Community 2015.

For the MVC implementation, please check: https://www.vdocipher.com/blog/2016/02/example-code-for-streaming-protected-video-in-asp-net/

For  vbscript implementation of aspx, check this: https://www.vdocipher.com/blog/2015/01/asp-net-implementation-vdocipher-api/

Vdocipher video in asp.net: aspx and aspx.cs files:

Do not save API Secret in the code

API secret is a key which gives your website authority to generate access tokens (OTPs) for video playback. This secret key can also be used to upload, delete videos in your vdocipher account. Hence, it should not be hard-coded in the application. It should be kept as an app secret. In the above example, it has been added to the web.config file which is not the recommended method. Please read this official article on best practices of saving secret keys in ASP.NET.

Complete code

Download the complete sample application from the Github.

Adding watermark to the videos

Watermark can be added when generating the OTP in the controller file. Please read this article on structuring your watermark and a sample code. The watermark has to be URLencoded and sent as a post data. You shall need to change around line 33 to send annotation information. Let us know if you find any trouble with the watermark setup.

A note about caching

OTP generated here is temporary. You can not cache this OTP and send it to multiple users as it might cause trouble. The OTP once used gets expired and can no longer be used to play video. Some extensions might try to automate the page rendering and especially when on pages which do not need login. The configuration must be set to make sure pages with embedded videos are not cached and cause error while playback.

vdocipher api illustration

For reference about how everything works, please check API reference.

Do let us know about your experiences setting up your secure video in asp.net to create your own PPV or subscription-based video portal. and how we can make the integration simpler.

PHP sample video upload from browser to VdoCipher

[This article is based on API v2 as document here.]

The Upload API workflow and overview can be found here.

Please find below a sample code for enabling video upload from your PHP website’s users. Note that this is sample code and you will need to configure it according to the controller-view structure in your application. It is not a recommended to put Controller logic and HTML output in a single file.

When setting up your front-end, you will like to enable better interface with AJAX upload such that your user’s can have a seamless experience. For this it is recommended to use one of the available libraries(angularjs, jquery or standalone, etc.) . Note that all these can be modified to be used in this set up. You can also see a sample implementation of the angular’s ng-file-upload library in your vdocipher dashboard itself.

Drupal module to embed vdocipher videos

Your videos on vdocipher are protected and can only be played when generating an access token for each video view. This access token needs to be generated securely in your website backend. The Drupal module does this thing in your Drupal website without getting your hands dirty in API programming.  With this module you can add videos inside any text field in content_type in your Drupal website.

The module uses a shortcode like syntax to parse and display videos inside any node such as an article or a page or a custom content type. The markup of the content body is processed and the shortcode syntax is replaced with the player code.

Download here

  1. Download the module file from the link above.
  2. Upload the module file from the install new module page in your Drupal “install new module” page.
  3. Enable the uploaded module.
  4. Click on the configure link in the module page to complete your setup.
  5. Copy your API secret key from vdocipher dashboard > config > general.
  6. Enter the API key in Drupal and save your settings.
  7. Save the configuration.
  8. Copy a video id from your vdocipher dashboard. Edit an existing node in Drupal and add this code in any text field (replace aaaaaaa with id of a video).
    1. [vdo id=aaaaaaa]
  9. Open the article on a page. You should see the video player in your Drupal website.

Q. I am seeing the message: Unauthorized
A. Most probably, you have extra spaces in the API key configuration. Go to the module configuration for vdocipher and make sure the API key is correct.

Q. I am seeing message: Video not found
A. This would probably mean that the video id is not correct. The rich-text editor you are using to add the shortcode might have added extra characters. Content saved in the database is HTML while you are shown rendered HTML in the editor. Click on one of the “view source” option in your editor and try re-pasting the shortcode. Also, make sure there are no spaces before or after the equality sign.

Q. How to set this up for selling video as PPV or subscription?
A. The video can only be viewed by the person who has purchased a membership or a video. You need to set up Drupal permissions such as only those persons can view the assigned content-type which has video.

Q. The height and width are not what I want
A. The height and width are taken from the module configuration and overridden from the shortcode. Did I tell you, you can also add the height and width info like the following. In case the provided width is greater than the available width, the width is set to 100% of available width and height is adjusted to keep the same aspect ratio as provided by the settings.

Q. Why is this not integrated with the media module
A. That what was the idea when we started working on it. But turns out there are certain permission concerns that we need to understand to make sure that using the media module is alright for your video accessibility.

Q. How to manage permission on creating video playable contents
A. The shortcode for video can be added to any node and thus anybody who has the permission to create node(any content type) can add a shortcode to play the video. Note that comment is not a node. We understand this might be a problem for your set-up in a multi-user environment. We plan to solve this problem in the next version with either a custom content type or using the media module to make it easy to control permissions. At the very least, we can add a white-list of content-types which can only have a video embedded in it but it might not work in all cases.

Note on watermark adding.

The watermark can be added to your videos to imprint info about the logged in user or an image for branding. You can configure the watermark from the module configuration page. Check this article for more information on the structure and format required to add watermark text or image in the video. We are going to add a new article on how to configure the watermark in Drupal.

A note about caching

OTP generated here is temporary. You can not cache this OTP and send it to multiple users as it might cause trouble. The OTP once used gets expired and can no longer be used to play video. Some extensions might try to automate the page rendering and especially when on pages which do not need login. The configuration must be set to make sure pages with embedded videos are not cached and cause error while playback.

vdocipher api illustration

For reference about how everything works, please check API reference.

Do let us know about your experiences setting up your secure video in Drupal to create your own PPV or subscription-based video portal. and how we can make the integration simpler.

 

C# sample video upload from browser to VdoCipher

To automate your video website platform, you need video upload directly through your website. Read this for details about this method. The following code gives an example written in C#.

Controller makes API request to vdocipher API to get authorized data about the upload. View file creates the HTML form required for uploading data. Note that the HTML form is only for illustration. You need to hide the extra input fields and perhaps use one of the better javascript libraries (angularjs, jquery or standalone, etc.) for video upload to make user flow better according to rest of your website.

After the video is uploaded, it is not ready instantly. Do not load the player immediately. Use the API to query when video is ready and only then render the video player. The API for querying video status is described in the API reference as videos/ .