Loading...

Heywatch and php

Heywatch is a cool video encoding web service that is being used by different clients like Sony, Fotolia, Kickapps, MTv, among others for their video conversion needs.

One nice thing about this service is that it has a REST based API that is simple to implement in php. However, the documentation that comes with heywatch shows only how to access the API using PEAR – this becomes a disadvantage if your shared hosted webhost doesn’t have PEAR installed. I also personally think that using PEAR just to call this api is basically overkill.

Why not use curl instead? I basically changed the PEAR functions in the API documentation to that of php curl functions (which are basically native and available in practically all shared php webhosting)


<?
$video_url = "http://osaddict.com/files/elephantsdream-480-h264-st-aac.mov";
$format_id = "1086"; // 1086 for flash h264, 31 for flash flv
$ftp = "ftp://username:password@ftphost.com";
$ping_after_encode = "http://host/heywatch/success.php?myvideoid=5&myuserid=1";
$ping_if_error = "http://host/heywatch/error.php";
$ch = curl_init();
$your_username = "";
$your_password = "";
$arr = array($video_url,"format_id"=>$format_id,"automatic_encode"=>"true","ftp_directive"=>$ftp,"title"=>"My Video Title","keep_video_size"=>"true");
curl_setopt($ch, CURLOPT_USERPWD, $your_username.':'.$your_password);
curl_setopt($ch, CURLOPT_POSTFIELDS,$arr);

$data = curl_exec($ch);

if (curl_errno($ch)) {
print curl_error($ch);
exit;
} else {
curl_close($ch);
}

header(“Content-Type: text/xml;charset=UTF-8”);
header(“Pragma: no-cache”);
echo $data;
?>

What this code does is to download a video, convert it to h264 flash format, then upload it to a select ftp host in just one step (success.php and error.php are ping functions where the developer is notified if conversion was successful or not).

One thing to take note is that heywatch doesn’t like special characters in the ftp url, if you place such characters in the $ftp variable, heywatch upload fails.

Have fun!

 
 

2 comments
Leave a Reply

Your email address will not be published. Required fields are marked *