Developers Support Customer login
+1 800.513.1740
Media API Documentation   |   Sub Account API Documentation   |   Supported Source Media Formats   |   Sample Scripts    |   Recent Changes    |   Common Errors    |   Brightcove
VBScript sample
PHP sample
Java sample
CFM sample
C# sample


VBScript sample

You can use the following code as a sample:
    Dim xml, sURL, sRequest, result, userID, userKey
   
    ' put your real userID and userKey below
    userID = "0"
    userKey = "your_key"
   
    xml = "<?xml version=""1.0""?>" & VbCrLf
    xml = xml & "<query>" & VbCrLf
    xml = xml & "<userid>" & userID & "</userid>" & VbCrLf
    xml = xml & "<userkey>" & userKey & "</userkey>" & VbCrLf
    xml = xml & "<action>" & "GetMediaList" & "</action>" & VbCrLf
    xml = xml & "</query>" & VbCrLf
   
    sUrl = "http://manage.encoding.com"
    sRequest = "xml=" & xml
    result = HTTPPost(sUrl, sRequest)
   
    Function HTTPPost(sUrl, sRequest)
      Set oHTTP = CreateObject("Microsoft.XMLHTTP")
      oHTTP.open "POST", sUrl,false
      oHTTP.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
      oHTTP.setRequestHeader "Content-Length", Len(sRequest)
      oHTTP.send sRequest
      HTTPPost = oHTTP.responseText
    End Function



PHP sample

This sample script allows user to enter parameters and send API request for encoding to FLV format:

HTML form:
<form action="action.php" method="POST">
	<input type="hidden" name="format[output]" value="flv" />
	<table>
		<tr>
			<td>Source URL</td>
			<td>
				<input type="text" name="source" />
 			</td>
		</tr>
		<tr>
			<td>Size</td>
			<td>
				<select name="format[size]">
					<option value="320x240">320 x 240</option>
					<option value="368x192">368 x 192</option>
					<option value="480x360">480 x 360</option>
					<option value="640x480">640 x 480</option>
					<option value="800x600">800 x 600</option>
					<option value="852x480">852 x 480</option>
					<option value="128x96">128 x 96</option>
					<option value="176x144">176 x 144</option>
					<option value="352x288">352 x 288</option>
					<option value="704x576">704 x 576</option>
					<option value="1280x720">1280 x 720</option>
					<option value="1408x1152">1408 x 1152</option>
					<option value="1920x1080">1920 x 1080</option>
				</select>
			</td>
		</tr>
		<tr>
			<td>Bitrate (kbps)</td>
			<td>
				<select name="format[bitrate]">
					<option value="256k">256k</option>
					<option value="300k">300k</option>
					<option value="512k">512k</option>
					<option value="784k">784k</option>
					<option value="1024k">1024k</option>
					<option value="1600k">1600k</option>
				</select>
			</td>
		</tr>
		<tr>
			<td>Audio bitrate (kbps)</td>
			<td>
				<select name="format[audio_bitrate]">
					<option value="32k">32k</option>
					<option value="40k">40k</option>
					<option value="48k">48k</option>
					<option value="56k">56k</option>
					<option value="64k" selected>64k</option>
					<option value="80k">80k</option>
					<option value="96k">96k</option>
					<option value="112k">112k</option>
					<option value="128k">128k</option>
					<option value="144k">144k</option>
					<option value="160k">160k</option>
					<option value="192k">192k</option>
					<option value="224k">224k</option>
					<option value="256k">256k</option>
					<option value="320k">320k</option>
				</select>
			</td>
		</tr>
		<tr>
			<td>Audio sample rate (Hz)</td>
			<td>
				<select name="format[audio_sample_rate]">
					<option value="44100" selected>44100</option>
					<option value="22050">22050</option>
					<option value="11025">11025</option>
				</select>
			</td>
		</tr>
		
		<tr>
			<td>Audio channels number</td>
			<td>
				<select name="format[audio_channels_number]">
					<option value="1">1</option>
					<option value="2" selected>2</option>
				</select>
			</td>
		</tr>
		<tr>
			<td>Frame Rate</td>
			<td>
				<input type="text" name="format[framerate]" />
			</td>
		</tr>
		<tr>
			<td>2 pass encoding</td>
			<td>
				<select name="format[two_pass]">
					<option value="yes">yes</option>
					<option value="no" selected>no</option>
				</select>
			</td>
		</tr>
		<tr>
			<td>Constant bitrate</td>
			<td>
				<select name="format[cbr]">
					<option value="yes">yes</option>
					<option value="no" selected>no</option>
				</select>
			</td>
		</tr>
		<tr>
			<td>De-interlacing </td>
			<td>
				<select name="format[deinterlacing]">
					<option value="yes">yes</option>
					<option value="no" selected>no</option>
				</select>
			</td>
		</tr>
		<tr>
			<td>Destination File</td>
			<td>
				<input type="text" name="format[destination]" />
			</td>
		</tr>
		<tr>
			<td>Add meta data</td>
			<td>
				<select name="format[add_meta]">
					<option value="yes">yes</option>
					<option value="no" selected>no</option>
				</select>
			</td>
		</tr>
		<tr>
			<td></td>
		<td>
			<input type="submit" name="send" value="Send Request" />
		</td>
	</tr>
	</table>
</form>



action.php
<?php
function sendRequest($xml)
{
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, "http://manage.encoding.com/");
    curl_setopt($ch, CURLOPT_POSTFIELDS, "xml=" . urlencode($xml));
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_HEADER, 0);
    return curl_exec($ch);
}  

// Begin processing User's POST
if(!empty($_POST['source']))
{
    // Preparing XML request
   
    // Main fields
    $req = new SimpleXMLElement('<?xml version="1.0"?><query></query>');
    $req->addChild('userid', MY_ID);
    $req->addChild('userkey', MY_KEY);
    $req->addChild('action', 'AddMedia');
    $req->addChild('source', $_POST['source']);
   
    $formatNode = $req->addChild('format');
    // Format fields
    foreach($_POST['format'] as $property => $value)
    {
        if ($value !== '')
        $formatNode->addChild($property, $value);
    }
   
    // Sending API request
    $res = sendRequest($req->asXML());
   
    try
    {
        // Creating new object from response XML
        $response = new SimpleXMLElement($res);
       
        // If there are any errors, set error message
        if(isset($response->errors[0]->error[0])) {
            $error = $response->errors[0]->error[0] . '';
        }
        else
        if ($response->message[0]) {
            // If message received, set OK message
            $message = $response->message[0] . '';
        }
    }
    catch(Exception $e)
    {
        // If wrong XML response received
        $error = $e->getMessage();
    }
   
    // Displaying error if any
    if (!empty($error)) {
        echo '<div class="error">' . htmlspecialchars($error) . '</div>';
    }
   
    // Displaying message
    if (!empty($message)) {
        echo '<div class="message">' . htmlspecialchars($message) . '</div>';
    }
    exit;
}


Please also check the Symfony plugin for encoding.com: http://www.symfony-project.org/plugins/sfEncodingComPlugin


Java sample

import java.io.*;
import java.net.*;

public class EncodingTest {

    private static int startEncodingWorkflow() {
        // replace ID and key with your own
        String userID = "ID";
        String userKey = "key";
        String mediaID = "1";
        StringBuffer xml = new StringBuffer();

        xml.append("<?xml version=\"1.0\"?>");
        xml.append("<query>");
        xml.append("<userid>"+userID+"</userid>");
        xml.append("<userkey>"+userKey+"</userkey>");
        xml.append("<action>GetMediaInfo</action>");
        xml.append("<mediaid>"+mediaID+"</mediaid>");
        xml.append("</query>");

        URL server = null;
        try {
            String url = "http://manage.encoding.com";
            System.out.println("Connecting to:"+url);
            server = new URL(url);
        } catch (MalformedURLException mfu) {
            mfu.printStackTrace();
            return 0;
        }

        try {
            String sRequest = "xml=" + URLEncoder.encode(xml.toString(), "UTF8");
           
            System.out.println("Open new connection to tunnel");
            HttpURLConnection urlConnection = (HttpURLConnection) server.openConnection();
            urlConnection.setRequestMethod( "POST" );
            urlConnection.setDoOutput(true);
            urlConnection.setConnectTimeout(60000);
            urlConnection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");

            BufferedWriter out = new BufferedWriter( new OutputStreamWriter( urlConnection.getOutputStream() ) );
            out.write(sRequest);
            out.flush();
            out.close();
            urlConnection.connect();
            InputStream is = urlConnection.getInputStream();
           
            String str = urlConnection.getResponseMessage();
            System.out.println("Response:"+urlConnection.getResponseCode());
            System.out.println("Response:"+urlConnection.getResponseMessage());
            StringBuffer strbuf = new StringBuffer();
            byte[] buffer = new byte[1024 * 4];
            try {
                int n = 0;
                while (-1 != (n = is.read(buffer))) {
                    strbuf.append(new String(buffer, 0, n));
                }
                is.close();
            } catch (IOException ioe) {
                ioe.printStackTrace();
            }
            System.out.println(strbuf.toString())
        } catch (Exception exp) {
            exp.printStackTrace();
        }
        return 0;
    }

    public static void main (String[] args) {
        startEncodingWorkflow();
    }
}



CFM sample

You can use the following code as a sample:
    <!-- Building our query -->
    <cfsavecontent variable="xml">
        <?xml version="1.0" ?>
        <query>
            <action>AddMedia</action>
            <userid>0</userid>
            <userkey>your_key</userkey>
            <source>http://your.server.tld/some/path/file</source>
            <format>
                <output>3gp</output>
            </format>
            <format>
                <output>wmv</output>
            </format>
            <format>
                <output>flv</output>
            </format>
        </query>
    </cfsavecontent>
   
    <!-- Setting up the URL to send the request -->
    <cfset theURL = "http://manage.encoding.com">
   
    <!-- Sending the request -->
    <cfhttp url="#theURL#" charset="utf-8" method="post">
        <cfhttpparam type="formfield" name="xml" value="#xml#">
    </cfhttp>
   
    <!-- Getting the result -->
    <cfdump var="#cfhttp.fileContent#">





C# sample

static string HTTPPost(string sUrl, string sRequest)
{
    HttpWebRequest request = (HttpWebRequest)WebRequest.Create(sUrl);
    request.Method = "POST";
    request.ContentType = "application/x-www-form-urlencoded";
    request.ContentLength = sRequest.Length;
    request.GetRequestStream().Write(Encoding.UTF8.GetBytes(sRequest), 0, sRequest.Length);
    request.GetRequestStream().Close();
    HttpWebResponse response = (HttpWebResponse)request.GetResponse();
    StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.UTF8);
    string result = reader.ReadToEnd();
    reader.Close();
    return result;
}
 
static void Main_Encoding(string origin, string destination)
{
    string xml, sUrl, sRequest, result, userID, userKey;

    //put your real userID and userKey below
    userID = "0";
    userKey = "your_key";
               
    xml = string.Format(
@"<?xml version=""1.0""?>
<query>
<userid>{0}</userid>
<userkey>{1}</userkey>
<action>AddMedia</action>
<source>{2}</source>
<format>
<output>flv</output>
<destination>{3}</destination>
</format>
</query>"
, userID, userKey, origin, destination);

    sUrl = "http://manage.encoding.com/";
    sRequest = "xml=" + HttpUtility.UrlEncode(xml);
    result = HTTPPost(sUrl, sRequest);
}

 
static void Main(string[] args)
{
    String origin = "http://yoursite.com/video/movie.avi";
    String destination = "ftp://username:password@yourftphost.com/video/encoded/test.flv";
    Main_Encoding(origin, destination);
}