Media APIs
Register  ·  Sign In  ·  Help
Jump to Page:   1
  Reply   Reply  

Selecting Rendition using the Media API
Options    Options  
EJ
Contributor
Posts: 10
Registered: 02-11-2009


EJ

Message 1 of 10

Viewed 2,769 times


I noticed that using the Player API, you are able to select the rendition using:

 

setRenditionSelectionCallback(callback:Function):void

 Does anyone know of a way to select a rendition using the Media API. Currently the API only returns the 512 kbps rendition.

 

Can this be done using an API call?

 

http://api.brightcove.com/services/library?command=find_video_by_id
&video_id=149210661776&fields=name,renditions
&token=0Z2dtxTdJAxtbZ-d0U7Bhio2V1Rhr5Iafl5FFtDPY8E.

 

Is there something missing that I can add to the call to select a rendition by bitrate?

 

Thanks for the help 

Kudos!
Solved!
Go to the Solution
Go to Solution
05-19-2009 01:14 PM
  Reply   Reply  

Re: Selecting Rendition using the Media API
Options    Options  
BC-Sean
Brightcove Team
Posts: 76
Registered: 01-09-2009


BC-Sean

Message 2 of 10

Viewed 2,760 times


First you need to get a url enabled token from customer support.  Once you have that you should be able to recieve an array of renditions each should look something like this:

"renditions": [
  {
  "displayName": "Punisher.mov",
  "encodingRate": 1500000,
  "frameHeight": 768,
  "frameWidth": 1024,
  "referenceId": null,
  "remoteStreamName": null,
  "remoteUrl": null,
  "size": 8144122,
  "type": "FLV_FULL",
  "url": "http://brightcove.vo.llnwd.net/d5/unsecured/media/270881182/270881182_4664369001_Punisher.flv",
  "videoCodec": "ON2",
  "videoDuration": 66131
  }...

Then you just compare the encoding rate to the one you want.  We return all renditions that exist, let me know if you see more than one in the media module but only one in the api.

Thanks,
Sean
1
Kudos!
05-19-2009 01:45 PM
  Reply   Reply  

Re: Selecting Rendition using the Media API
Options    Options  
EJ
Contributor
Posts: 10
Registered: 02-11-2009


EJ

Message 3 of 10

Viewed 2,752 times


Thanks Sean,

 

I'm not the strongest Javascript guy, so I was wondering if there were any examples on the Brightcove developer site on how to do this, or if you could possible help me out with an example?

 

Currently, I am using the API example. I have included my code below:

 

 

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
   
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
    <title>Player API Example - HTML</title>
    <link rel="stylesheet" href="displayTitles.css"/>

<script>
function JSONscriptRequest(fullUrl) {
    // REST request path
    this.fullUrl = fullUrl;
    // Keep IE from caching requests
    this.noCacheIE = '&noCacheIE=' + (new Date()).getTime();
    // Get the DOM location to put the script tag
    this.headLoc = document.getElementsByTagName("head").item(0);
    // Generate a unique script tag id
    this.scriptId = 'JscriptId' + JSONscriptRequest.scriptCounter++;
}

// Static script ID counter
JSONscriptRequest.scriptCounter = 1;

// buildScriptTag method
//
JSONscriptRequest.prototype.buildScriptTag = function () {

    // Create the script tag
    this.scriptObj = document.createElement("script");
   
    // Add script object attributes
    this.scriptObj.setAttribute("type", "text/javascript");
    this.scriptObj.setAttribute("charset", "utf-8");
    this.scriptObj.setAttribute("src", this.fullUrl + this.noCacheIE);
    this.scriptObj.setAttribute("id", this.scriptId);
}
 
// removeScriptTag method
//
JSONscriptRequest.prototype.removeScriptTag = function () {
    // Destroy the script tag
    this.headLoc.removeChild(this.scriptObj); 
}

// addScriptTag method
//
JSONscriptRequest.prototype.addScriptTag = function () {
    // Create the script tag
    this.headLoc.appendChild(this.scriptObj);
}     
</script>   
    <script>
   
   
    // The web service call
    var token = "xxxxxxxxxxxx.";
   
    var req = "http://api.brightcove.com/services/library?";
    req += "command=find_all_videos&token=" + encodeURIComponent(token);  // tokens need to be URL-encoded
    req += "&fields=id,name,shortDescription,FLVURL,thumbnailURL,length,renditions&callback=response";

    function initCall() {
        // Create a new request object
        bObj = new JSONscriptRequest(req);
        // Build the dynamic script tag
        bObj.buildScriptTag();
        // Add the script tag to the page
        bObj.addScriptTag();
    }
   
   
    // Define the callback function
    // writes out the HTML for each title item in the list
    function response(jsonData) {

       
        var items = jsonData["items"];
        var tDiv = document.getElementById("titleList");
        var i=0;
       
        while (i<items.length) {
       
            var str = "";
                        str += '<div class="VideoEntryHolder">';

            str += '<div class="VideoPicHolder">';
            str += '<a href="'+ items[i].FLVURL+'"/>';
            str += '<img src="' + items[i].thumbnailURL  +'" width="120"/></a></div>';
            str += '<div class="VideoInfoHolder">' + items[i].name + ' (' + formatTime(items[i].length) + ')'+ '<br>';
            str += '<font class="style3">' + items[i].shortDescription + '</font>';
            str += '</div>';
            str += '</div>';
            str += '</div>';
            str += '<br>';

            tDiv.innerHTML += str;
            i++;
        }
    }
   
    // time is stored in milliseconds; we need to convert to a mm:ss display format
    function formatTime(time) {
       
        var t_secs = Math.round(time/1000);
        var mins = Math.floor(t_secs/60);
        var secs = t_secs - (mins*60);
        return mins + ":" + secs;
    }   




    </script>
   
</head>

<body onload="initCall()">



<div id="titleList">
</div>


</body>
</html>

Kudos!
05-19-2009 03:36 PM
  Reply   Reply  

Re: Selecting Rendition using the Media API
Options    Options  
BC-Sean
Brightcove Team
Posts: 76
Registered: 01-09-2009


BC-Sean

Message 4 of 10

Viewed 2,750 times


I am not 100% on this but I think if you replace:

  str += '<a href="'+ items[i].FLVURL+'"/>';
with:
  for( var rend in items[i].renditions){
  if(rend.encodingRate == 512000){ 
  str += '<a href="'+ rend.url+'"/>';
  break;
  }
  }

where 512000 is the bit rate you want to show. Of course you might not want to have a strict == you might want to do a >= or <= since the numbers can be close but not always exact.
2
Kudos!
05-19-2009 03:49 PM
  Reply   Reply  

Re: Selecting Rendition using the Media API
Options    Options  
EJ
Contributor
Posts: 10
Registered: 02-11-2009


EJ

Message 5 of 10

Viewed 2,737 times


Hi Sean,

 

I gave that a try, I replaced the 512000 with the bitrate that I was looking for, and still no luck.  

 

It seems to detect the bitrate I'm looking for, but when it creates the link, it is undefined, so it seems that rend.url is not working.

 

 

Kudos!
05-20-2009 02:54 PM
  Reply   Reply  

Re: Selecting Rendition using the Media API
Options    Options  
BC-Sean
Brightcove Team
Posts: 76
Registered: 01-09-2009


BC-Sean

Message 6 of 10

Viewed 2,730 times


So the if gets triggered but url is being replaces with undefined?  Can you see any other meta-data on rend if you step through it in firebug or can you get any other data from it if you try rend.displayName or even rend.  My gut is telling me it might be a capitalization or syntax error.  Let me know I will keep trying to find a solution.
Kudos!
05-21-2009 09:09 AM
  Reply   Reply  

Re: Selecting Rendition using the Media API   [ Edited ]
Options    Options  
jerjou
Contributor
Posts: 38
Registered: 12-11-2008


jerjou

Message 7 of 10

Viewed 2,707 times


Javascript is weird in that the for-loop syntax iterates on the index rather than the value. So, what once was:


for( var rend in items[i].renditions){
if(rend.encodingRate == 512000){
str += '<a href="'+ rend.url+'">';
break;
}
}


should actually be:


for( var rend in items[i].renditions){
if(items[i].renditions[rend].encodingRate == 512000){
str += '<a href="'+ items[i].renditions[rend].url+'">';
break;
}
}


A little cleaner:


var renditions = items[i].renditions;
for(var j=0; j<renditions.length; j++) {
if(renditions[j].encodingRate == 512000){
str += '<a href="'+ renditions[j].url+'">';
break;
}
}
Message Edited by jerjou on 05-26-2009 10:40 AM
Message Edited by jerjou on 05-26-2009 10:41 AM
4
Kudos!
Accepted Solution
Accepted Solution
05-26-2009 10:36 AM
  Reply   Reply  

Re: Selecting Rendition using the Media API
Options    Options  
EJ
Contributor
Posts: 10
Registered: 02-11-2009


EJ

Message 8 of 10

Viewed 2,702 times


I cannot thank you enough, this works perfect!!
Kudos!
05-26-2009 11:41 AM
  Reply   Reply  

Re: Selecting Rendition using the Media API
Options    Options  
jerjou
Contributor
Posts: 38
Registered: 12-11-2008


jerjou

Message 9 of 10

Viewed 2,698 times


I take gratitude in the form of delicious cupcakes ;)
Kudos!
05-26-2009 11:53 AM
  Reply   Reply  

Re: Selecting Rendition using the Media API
Options    Options  
EJ
Contributor
Posts: 10
Registered: 02-11-2009


EJ

Message 10 of 10

Viewed 2,696 times


Next time your in DC, stop by, I'll have a dozen waiting for you.

 

Kudos!
05-26-2009 12:48 PM
Jump to Page:   1