Transcoding

Your source video files must be transcoded into our video formats in order to be streamed correctly to the supported devices.

Each transcoded video belonging to a media is called an asset.

There are different assets available.

Note that live media also have assets, even though these are not transcoded files.

Assets

  • video:
    • mp4_h264_aac_ld: H264 video @180KBps with AAC audio @64KBps in a mp4 container with a max size of 320x240 (iPhone compatible)
    • mp4_h264_aac: H264 video @360KBps with AAC audio @96KBps in a mp4 container with a default size of 512x384 (iPhone compatible)
    • mp4_h264_aac_hq: H264 video @800KBps with AAC audio @128KBps in a mp4 container with a default size of 848x480 (iPhone 4 / iPad compatible)
    • mp4_h264_aac_hd: H264 video @1.5MBps with AAC audio @128KBps in a mp4 container with a default size of 1280x720 (iPhone 4 / iPad compatible)
    • mp4_h264_aac_fhd: H264 video @6MBps with AAC audio @128KBps in a mp4 container with a default size of 1920x1080 (iPhone 4 / iPad compatible)
    • abs: Adaptive Bitrate Streaming
    • abs_fa: DRM Adobe Access
    • abs_pr: DRM Microsoft PlayReady
    • live: live
  • thumbnails:
    • jpeg_thumbnail_small: a jpeg thumbnail with a default size of 80x60
    • jpeg_thumbnail_medium: a jpeg thumbnail with a default size of 160x120
    • jpeg_thumbnail_large: a jpeg thumbnail with a default size of 320x240
    • jpeg_thumbnail_source: a jpeg thumbnail with a maximum width of 848 and a height relative to the frame ratio

Create assets

In order to create any of these assets, you can use the methods create or set_assets from the Media object.

Create previews

It is possible to create preview assets, with a shorter duration than the source’s.

You have to use the encoding parameter max_duration in the asset_parameters (see examples below).

This parameter accepts an integer value representing the limit in seconds for the encoded asset’s duration.

Examples

Python:

from cloudkey import CloudKey
user_id = ''
api_key = ''
media_id = ''
cloudkey = CloudKey(user_id, api_key)
# We create an asset
cloudkey.media.set_assets(id=media_id, assets=[{'name': 'abs'}])
# We get the source asset url
res = cloudkey.media.get_assets(id=media_id, assets_names=['source'])
source_url = res['source']['download_url']
# We create another media
media_id_preview = cloudkey.media.create(meta={'title': 'my preview'})['id']
print 'created preview media id', media_id_preview
# We create the preview source using the main media url
cloudkey.media.set_assets(id=media_id_preview,
        assets=[{'name': 'source', 'url': source_url}])
# We create a preview asset
parameters = {
    'max_duration': 30,
    }
cloudkey.media.set_assets(id=media_id_preview, assets=[{
        'name': 'abs',
        'parameters': parameters,
        }])

PHP:

require_once 'CloudKey.php';
$user_id = '';
$api_key = '';
$media_id = '';
$cloudkey = new CloudKey($user_id, $api_key);
# We create an asset
$cloudkey->media->set_assets(array('id' => $media_id, 'assets' => array(array('name' => 'abs'))));
// We get the source asset url
$res = $cloudkey->media->get_assets(array('id' => $media_id, 'assets_names' => array('source')));
$source_url = $res->source->download_url;
// We create the preview media
$res = $cloudkey->media->create(array('meta' => array('title' => 'my preview')));
$media_id_preview = $res->id;
print('created preview media id ' . $media_id_preview . "\n");
// We create the preview source using the main media url
$assets = array(array('name' => 'source', 'url' => $source_url));
$cloudkey->media->set_assets(array('id' => $media_id_preview, 'assets' => $assets));
// We create the preview asset
$parameters = array('max_duration' => 30);
$assets = array(array('name' => 'abs', 'parameters' => $parameters));
$res = $cloudkey->media->set_assets(array('id' => $media_id_preview, 'assets' => $assets));

Java:

import net.dmcloud.cloudkey.*;
import net.dmcloud.util.*;
import java.io.*;
import java.util.*;
public class Transcode {
    private static String user_id = "";
    private static String api_key = "";
    private static String media_id = "";
    public static void transcode() {
        try {
            CloudKey cloudkey = new CloudKey(user_id, api_key);
            DCObject result;
            // We create an asset
            DCArray assets1 = DCArray.create()
                .push(DCObject.create()
                    .push("name", "abs")
                    );
            result = cloudkey.call(
                "media.set_assets",
                DCObject.create()
                    .push("id", media_id)
                    .push("assets", assets1)
                );
            // We get the source asset url
            result = cloudkey.call(
                "media.get_assets",
                DCObject.create()
                    .push("id", media_id)
                    .push("assets_names", DCArray.create().push("source"))
                );
            Map info = (Map)result.get("source");
            String url = (String)info.get("download_url");
            // We create another media
            DCObject meta2 = DCObject.create()
                .push("title", "my preview");
            result = cloudkey.call(
                "media.create",
                DCObject.create()
                    .push("meta", meta2)
                );
            String media_id_preview = (String)result.get("id");
            System.out.println("created preview media id " + media_id_preview);
            // We create the preview source using the main media url
            DCArray asset_source = DCArray.create()
                .push(DCObject.create()
                    .push("name", "source")
                    .push("url", url)
                    );
            result = cloudkey.call(
                "media.set_assets",
                DCObject.create()
                    .push("id", media_id_preview)
                    .push("assets", asset_source)
                );
            // We create a preview asset
            DCArray assets2 = DCArray.create()
                .push(DCObject.create()
                    .push("name", "abs")
                    .push("parameters", DCObject.create()
                        .push("max_duration", 30)
                    ));
            result = cloudkey.call(
                "media.set_assets",
                DCObject.create()
                    .push("id", media_id_preview)
                    .push("assets", assets2)
                );
        } catch(Exception e) {
            System.out.println("Error : " + e.getMessage());
        }
    }
    public static void main(String[] args) {
        transcode();
    }
}

Table Of Contents