Author: TomdeMan
Related Categories:
ColdFusion
September 10, 2007
This topic seems to come up often.
I worked on a project recently that required the use of FFMPEG to convert videos into FLV. Your typical YouTube approach. There are some posts out there that offer what they can, but most using the native CFEXECUTE. Which I can say myself was not an effective solution.
It seems the thread would either close too early or not at all. No matter what you set for your timeout.
Our solution was to use the Java Runtime library.
The function looked like this:
(Keep in mind your arguments will vary depending on what you are trying to do here)
<cfargument name="binPath" required="Yes" type="string" />
<cfargument name="srcPath" required="Yes" type="string" />
<cfargument name="destPath" required="Yes" type="string" />
<cfset var rtnStruct = structNew() />
<cfset var r = '' />
<cfset var ar_arg = arrayNew(1) />
<cfscript>
rtnStruct.success = false;
arrayappend(ar_arg, "-i");
arrayAppend(ar_arg, '"#arguments.srcPath#"');
arrayappend(ar_arg, "-g 300");
arrayappend(ar_arg, "-y");
arrayappend(ar_arg, "-s");
arrayappend(ar_arg, "320x240");
arrayappend(ar_arg, "-aspect");
arrayappend(ar_arg, "4:3");
arrayappend(ar_arg, "-f");
arrayappend(ar_arg, "flv");
arrayappend(ar_arg, "-ar");
arrayappend(ar_arg, "44100");
arrayAppend(ar_arg, '"#arguments.destPath#"');
try{
r = createObject('java','java.lang.Runtime').getRuntime();
r.exec('#arguments.binPath#\ffmpeg.exe #arraytoList(ar_arg,' ')#');
r.runFinalization();
r.freeMemory();
rtnStruct.success = true;
}
catch(excpt any){
rtnStruct.message = excpt.message;
}
</cfscript>
<cfreturn rtnStruct />
</cffunction>




