Video encoding with Zencoder

This post is more than 2 years old.

This is something I found a few months ago but I'm just now finally finding the time to write it up. If you've ever had to work with video encoding, you know it can be somewhat difficult, especially if you are looking for an automated solution. I've worked with ffmpeg before, and while it's pretty darn powerful, it can be a chore to set it up correctly and figure out the exact right API to get the results you need. If a client came to me asking for some form of video encoding solution I'd probably punt and say - just use Youtube. That's before I found Zencoder.

Zencoder is a commercial service that provides video encoding over the Internet. At first that seemed a bit crazy. Most videos are pretty large and I couldn't imagine how well such a service would work. Zencoder though can connect to your videos in multiple ways, including via Amazon S3. As long as Zencoder can suck down the file it can process it on it's own servers and spit out your videos with multiple results:

  • You can output to 6 different video formats and 4 for audio (see output formats)
  • You can resize the video
  • You can modify quality, bitrate, framerate, and other things that are way above me
  • You can generate thumbnails from the video
  • You can add a watermark
  • You can create a clip (ie, just a portion from the original)
  • and more...

Best of all - of this works via a simple to use API. If you read my blog, you know I love APIs and I especially like services that go out of their way to make things simple. The full docs for their API may be found here:

For the most part, your interaction with Zencoder comes down to sending a request to them telling Zencoder where your video may be accessed. Your video is then put into a queue. Their API supports multiple ways of working with your own queue. You can ask it to ping you HTTP, email, or just use another API call to check the status. When Zencoder is done it can then copy the results back to you via FTP, SFTP, FTPS, or even better - S3.

This service is not free. You can see their price list here. To me - this looks pretty reasonable. They have a web based dashboard so you can do adhoc conversions and I could see myself using this for my blog. I know there are tools I could run locally, but for a few bucks I'd much rather let Zencoder handle it.

So by now you may be asking - is there a ColdFusion wrapper for this service? The answer is - of course - heck yes. Todd Schlomer has written a wrapper and it works really well. You can find it on Github here: (And yes - he also created a RIAForge project so you will find it if you search there.)

I whipped up a quick ColdFusion script that shows a basic set of calls with his API. It just starts a job and doesn't actually check the result. But I wanted to show how easy this was, especially with ColdFusion 901's simple S3 integration. Here is template - and again - please consider this ugly test code.

<cfset apikey = "myapikey"> <cfset zen = new zencoder.Zencoder(apikey)>

<cfset s3dir = "s3://">

<cfif not fileExists(s3dir & "/lynn.3gp")> <cfset fileCopy(expandPath("./lynn.3gp"), s3dir & "/lynn.3gp")> </cfif>

<cfset source = s3dir & "/lynn.3gp">

<cfset outputs = new zencoder.ZencoderOutputArray()> <cfset thumbs = new zencoder.ZencoderThumbnails()> <cfset thumbs.addThumbnail({"number"=6,"size"="160x120","base_url"="s3://",label="thumblabel"})>

<cfset outputs.addOutput( new zencoder.ZencoderOutput(base_url="s3://", filename="foo2.mp4", label="Label_1", thumbnails=thumbs, public=1) )>

<cfset res = zen.createEncodingJob(source,outputs)>

<cfdump var="#res#"> <cfoutput> <cfif structkeyexists(res, "message")>message=#res.message.tostring()#</cfif> <p> Done. </cfoutput>

There isn't a lot going on here really. I begin by creating an instance of the Zencoder library with my API key. I then copy - if it isn't already there, a video I made locally to a S3 folder. Next I create a Zencoder output array. You can request multiple outputs when processing but for this template I'll just work with one. I also asked for 6 thumbnails. Finally I tell Zencoder where to store the file and then create my job.

And that's it! Obviously I'm leaving off the slightly more complex portion - handling the result. As I said, you can ping the API to check the status o jobs or have Zencoder run a HTTP call against your site. I'd imagine you could set up a simple Ajax based checker on your site in a few minutes.

All in all - this is a darn impressive service, and I'm looking forward to working with it in the future. I'd love to hear from anyone who has had a chance to use this in production yet.

Raymond Camden's Picture

About Raymond Camden

Raymond is a senior developer evangelist for Adobe. He focuses on document services, JavaScript, and enterprise cat demos. If you like this article, please consider visiting my Amazon Wishlist or donating via PayPal to show your support. You can even buy me a coffee!

Lafayette, LA

Archived Comments

Comment 1 by Robert Zehnder posted on 4/26/2011 at 4:51 PM

I looked at them a while back because I have a client that wanted to be able to upload any format of video and have it converted into FLV for display on their site, but for their needs (a non-profit) it was a little cost prohibitive.

It would be really cool to see a similar service written in CF though. :)

Comment 2 by Robert Reinhardt posted on 4/27/2011 at 2:14 AM

How well does Zencoder create adaptive streaming output for Flash and iOS? I'm starting to compare offerings against my own video encoding / hosting service at, but most online encoding services have simply "announced" forthcoming support for adaptive streaming presets.

RE: non-profits @ Robert Zehnder, I've provided one non-profit with pro-bono hosting and encoding (site will launch soon) specially for adaptive streaming deployment. I'm still working on the public API for, but there will be AMF remoting support in addition to other data xfer formats.

Comment 3 by Jon Dahl posted on 4/27/2011 at 2:28 AM

Great article, and thanks for the writeup of Zencoder. We have a number of ColdFusion customers and are happy to support customers who use CF (or any language).

@Robert R: not sure what adaptive streaming has to do with this post, but Zencoder has done adaptive streaming for iOS for quite a while, and have a number of customers using it. We create segmented TS with perfect keyframe placement and let you control the segment length. We can create m3u8 playlists for a single stream and for multiple streams (adaptive bitrate). You can also add an image (like album art) for an audio-only stream, or even automatically take one thumbnail for every segment of an audio-only stream.

But Flash (HDS) is still forthcoming.

Comment 4 by Robert Reinhardt posted on 4/27/2011 at 8:08 AM

@Jon Dahl, you're right--I was a bit presumptuous. I mentioned adaptive streaming because Ray didn't say either way if supported adaptive streaming, and if so, for which players/browser/etc. It's my opinion that online encoding services should not only mimic desktop encoders, but provide services that desktop can't/doesn't provide (e.g. my work on my motion analysis procedures and predictive bitrates, as an example). I have a recent blog post outlining the case for why more developers, designers, integrators, etc, need to be more aware of adaptive streaming and its benefits, which requires the cooperation of proper encoding and proper deployment across all adaptive streaming types.