Video Conversion (api.encoding.com) API

The Encoding.com API allows you to automate a high volume workflow by integrating a fast and scalable media processing platform into your, CMS, MAM, or application. Our XML or JSON API is the most mature, well documented and feature rich cloud encoding API on the market. Our API Builder will help generate properly format, and test your JSON or XML requests before writing a single line of code.

Here is how is works:

Your application sends either the AddMedia or AddMediaBenchmark API request to Encoding.com which includes:

  • The source location of your video.
  • Job notification location (http or email)
  • One or multiple custom or preset desired encoding recipes.
  • One or multiple delivery points for your video.

Encoding.com responds immediately with a media ID so your application can track the progress of the job.

With the fastest SLA backed queue times in the industry, Encoding.com processes all of your jobs in parallel on dedicated multi core servers. Chose from three processing speed level, Baseline (4 core), Turbo (8 core), Twin Turbo (16 core). Our platform scales and assigns compute in realtime based on your needs so if you sent us 1 jobs with 1 output, it would process just as fast as if you sent us 250 jobs each with 10 outputs.

You can read all other details here: http://api.encoding.com/

Reference OF API: http://api.encoding.com/#APIOverview

So Here I am writing a complete PHP example to use api.encoding.com services::

<?php 
define(MY_ID, '479dfdsf39');
define(MY_KEY,'5efdfcsdf372e5f51f2aef4a6f10fac7446');
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['submitBtn']))
{

	 /* examples of POST
	  		source='http://mylogin:mypassword@files.mybucket.s3.amazonaws.com/video/source/file_in.mov';
	  		format['output']='flv';
	  		format['size']='320x240';
	  		format['bitrate']='256k';
	  		format['audio_bitrate']='40k';
	  		format['destination']='http://mylogin:mypassword@files.mybucket.s3.amazonaws.com/video/dest/file_out.flv';
	  */
              
		/* basic configuration */
		$req = new SimpleXMLElement('&lt;?xml version="1.0"?-->');
		$req->addChild('userid', MY_ID);
                $req->addChild('userkey', MY_KEY);
		$req->addChild('action', 'AddMedia');
		$req->addChild('source', 'sftp://user:pass@host/var/www/html/test/video/wp-content/uploads/2013/12/pp.mp4');
                
                $req->addChild('Notify', 'ppgeu89@gmail.com'); //set email for notifying
                
                /* conversion format configuration */
		$formatNode = $req->addChild('format');
                $formatNode->addChild('output','flv');
                $formatNode->addChild('size','320x240');
                $formatNode->addChild('bitrate','256');
                $formatNode->addChild('audio_bitrate','40k');

               /* giving destination for converted video */
                $formatNode->addChild('destination', 'sftp://user:pass@host/var/www/html/test/video/wp-content/uploads/2013/12/pp2.flv'); //destination can be your ftp server or amazon bucket or rackspace server (for more details of destination you can check reference site)
                
                // generating thumb 
                $formatNode->addChild('output','thumbnail');
                $formatNode->addChild('time','2'); //capture thumb in 2nd second of video
                $formatNode->addChild('width','500');
               // $formatNode->addChild('height','100');
                $formatNode->addChild('destination', 'sftp://user:pass@host/var/www/html/test/video/wp-content/uploads/2013/12/ppthumb.jpg');
	 
		// Sending API request (for uploading video)
		$res = sendRequest($req->asXML()); //video will be uploaded in api.encoding.com servers and after conversion api.encoding.com will put video in given destination
		 
		try
		{
		// Creating new object from response XML
	           $response = new SimpleXMLElement($res);
                 
                 //getting all media list from api.encoding.com processing server

                $req2 = new SimpleXMLElement('<!--?xml version="1.0"?-->');
		$req2->addChild('userid', MY_ID);
		$req2->addChild('userkey', MY_KEY);
                $req2->addChild('action', 'GetMediaList'); //get all the media submitted for user
                $req2->addChild('action', 'getstatus'); //for getting complete info of a media
                $req2->addChild('extended', 'yes'); //for getting additional info
                $res2 = sendRequest($req2->asXML());
                $response = new SimpleXMLElement($res2);
                print_r($response); //will print all media that were sent to api.encoding.com

                //getting media info of single media that was uploaded

                $req2 = new SimpleXMLElement('<!--?xml version="1.0"?-->');
		$req2->addChild('userid', MY_ID);
		$req2->addChild('userkey', MY_KEY);
                $req2->addChild('action', 'getstatus');
                $req2->addChild('mediaid', '40982345');  //(we can get this id by $req2->addChild('action', 'GetMediaList'))
                $req2->addChild('extended', 'yes'); //getting info in deep (gives processing status also)
                $res2 = sendRequest($req2->asXML());                
                $response = new SimpleXMLElement($res2);
                print_r($response);
		 //getting media info of a media that was ends here
		
                 // handling response
		if(isset($response->errors[0]->error[0])) 
		{
			$error = $response->errors[0]->error[0] . '';
		}
		elseif ($response->message[0]) 
		{
		// If message received, set OK message
			$message = $response->message[0] . '';
		}
		} //try closed
		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;
}
?>

Calling the fuction can be done by form(Just an example)

<form action="" enctype="multipart/form-data" method="post">
<input name="source" type="file" /> 
<input name="submitBtn" type="submit" />
</form>