Quick example of posting videos to Brightcove

This post is more than 2 years old.

A reader asked for help using Brightcove's API to upload a video using ColdFusion. While I do not plan on writing a full wrapper, or going into great detail, I thought a quick blog post on what he tried, and why it failed, could help others who plan on using the service.

Let's first look at his original code and a description of the problem he had.

<cfhttp url="http://api.brightcove.com/services/post" method="post" timeout="600" result="resultVar" multipart="true">

<cfhttpparam type="file" name="file" file="c:\com\brightcove\AT_T_test.mp4" />

<cfset jsonRequest = '{"method": "create_video", "params": {"video": {"name": "test", "shortDescription": "test"},"token": "blahblahblah.."}}'>

<cfhttpparam type="url" name="json" value="#jsonRequest#">

<cfhttpparam type="body" name="json" value="#jsonRequest#">


Even without knowing the API, you can see that it makes use of JSON to pass parameters about the upload. This code won't work at all because you can't mix a httpparam of type body with type file. The API docs though seemed to imply you needed to send the JSON values as the body. I first attempted to simply save the JSON to the file system and send it as a second file. This didn't work. I then dig a bit of digging and discovered this forum post by the Brightcove team: http://forum.brightcove.com/brgh/board/message?board.id=Developer_2&message.id=85

It pointed out that the JSON data could be sent as a form field, and it showed that my reader was missing a bit of data as well. Oddly - another issue was the order of the HTTP params. I can't image why this makes a difference, but if the JSON data isn't the first httpparam, then nothing else works. The final, working code, is below. Note - I removed his API key so you can't run this as is.

<cfset json = '{"method": "create_video", "params": {"video": {"name": "CFHTTP create","shortDescription": "test video"},"token": "falkeapikey"},"filename": "actual2.mp4","maxsize":640000}'>

<cfhttp url="http://api.brightcove.com/services/post" method="post" timeout="600" result="resultVar" multipart="true">

<cfhttpparam type="formfield" name="json" value="#json#"> <cfhttpparam type="file" name="actual2.mp4" file="/Users/ray/Documents/workspace/youtubecfc/unittests/actual2.mp4" /> </cfhttp>

<cfdump var="#resultvar#">

Anyway - I don't have time to dig into the Brightcove API more, but I'm sure someone out there could whip up a quick component.

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 https://www.raymondcamden.com

Archived Comments

Comment 1 by Brian Deitte posted on 12/1/2009 at 11:46 PM

Nice to see. Note that Brightcove has media API wrappers for Java, .NET, Python, AS, PHP, and more. See http://echove.net for a good example. If anybody creates one for ColdFusion, I'm sure Jeremy Allaire would be happy. :)

Comment 2 by Bill Davidson posted on 12/2/2009 at 9:51 AM

I'm said 'reader'. :) I can't believe Jeremy hasn't had SOMEONE at his company do a quick CF wrapper... at least for 'old times sake'. The PHP one is done by Brightcove employees, but not supported officially by Brightcove.

I do plan on writing a "full" API wrapper. I already have some of the read API methods done from awhile ago. The write API uses a different endpoint and seems to be more picky. If the client allows, I'll try to open source the API wrapper.

Thanks again to Ray for helping me out on this!

Comment 3 by Brian Deitte posted on 12/2/2009 at 7:58 PM

The PHP one was created by the services team for a project, and I'm guessing that they were asked by the client to use PHP. They did a similar thing for .NET with a client that I know asked to use this. So we just need some CF clients here. :) I've heard of Jeremy playing around with the media APIs in CF, but no one has been asked to create any of the media API wrappers here. I hope you do get to open source yours- let me know if you do, and I'll make sure it gets mentioned on the Brightcove site.

Comment 4 by William Haun posted on 12/3/2009 at 9:35 PM

Here's a big question I've had for a long, long time. Is there a way to read metadata from a MP4 video file with ColdFusion? Flash only plays MP4s encoded with the H.264 codec and I have users all the time encoding video with the MP4 file extension but not with the H.264 codec. What then happens is the Flash player plays the audio but not the video.

I found a way in the Flash player to read the metadata once the video is loaded (using a AS3 property called videocodecid) but I'd rather stop the video creator from uploading the poorly encoded MP4 at all.

In regards to your code above, it would be great for CF to check the MP4's codec before uploading it to BrightCove (after all their Flash video player can only play H.264 too).

Any ideas?!

Comment 5 by Raymond Camden posted on 12/3/2009 at 9:44 PM

ffmpeg can do just about anything with video. You can use the command line via cfexecute to do it that way.

If you can find a good Java wrapper (google returned this one: https://contributions.corem... - but no idea how good it is) then you can use it via CF.

Comment 6 by Brian Deitte posted on 12/3/2009 at 9:49 PM

The code above doesn't need to check if it's an H.264 file, as uploaded files to Brightcove will be transcoded to a playable format if needed.

Comment 7 by Bill Davidson posted on 12/15/2009 at 12:03 AM

Brian (et al)-

Version 1.0 of my Brightcove SDK is done... Waiting for approval on Riaforge and it will hopefully live there.

Comment 8 by Raymond Camden posted on 12/15/2009 at 12:46 AM

Luckily I know the guy who runs RIAForge. Project approved.

Comment 9 by Brian Deitte posted on 12/15/2009 at 1:02 AM

Very nice! I'm sending an email out so that the media API team and Jeremy know about this.

Comment 10 by Bill Davidson posted on 12/15/2009 at 1:22 AM

Ray - thanks.
Brian - cool!

It's up now at: http://cfBCove.riaforge.org/

Comment 11 by Brian Deitte posted on 12/15/2009 at 7:51 AM

Jeremy replied and said he loved it. :)

There may be a blog post on it somewhere on the site, as that often happens for things like this. I'll post a link here if there is one.

Comment 12 by Brian Deitte posted on 12/15/2009 at 5:22 PM
Comment 13 by Bill Davidson posted on 12/16/2009 at 8:34 AM