hi i am trying to setup a mini video site where guys can upload videos from 
devices like mobile phones and video cameras and i am using flex and coldfusion 
to do it. one thing i would like to know is how to use ffmpeg along with 
coldfusion and flex to allow guys to upload videos of any format and get them 
encoded to flv format on the fly and stored on the server for delivery. i have 
a small coldfusion snippet that uses ffmpeg and would like to get it work in 
flex. here it is

<!--- test file paths --->
<cfset ffmpegPath = "c:\bin\ffmpeg.exe">
<cfset inputFilePath = "c:\bin\testInput.mp4">
<cfset ouputFilePath = "c:\bin\testOuput.flv">
<cfset resultLog = "c:\bin\testOuput_result.log">
<cfset errorLog = "c:\bin\testOuput_error.log">

<!--- convert the file --->
<cfset results = structNew()>
<cfscript>
    try {
        runtime = createObject("java", "java.lang.Runtime").getRuntime();
        command = '#ffmpegPath# -i "#inputFilePath#" -g 300 -y -s 300x200 -f 
flv -ar 44100 "#ouputFilePath#"'; 
        process = runtime.exec(#command#);
        results.errorLogSuccess = processStream(process.getErrorStream(), 
errorLog);
        results.resultLogSuccess = processStream(process.getInputStream(), 
resultLog);
        results.exitCode = process.waitFor();
    }
    catch(exception e) {
        results.status = e;    
    }
</cfscript>

<!--- display the results --->
<cfdump var="#results#">


<!--- function used to drain the input/output streams. Optionally write the 
stream to a file --->
<cffunction name="processStream" access="public" output="false" 
returntype="boolean" hint="Returns true if stream was successfully processed">
    <cfargument name="in" type="any" required="true" hint="java.io.InputStream 
object">
    <cfargument name="logPath" type="string" required="false" default="" 
hint="Full path to LogFile">
    <cfset var out = "">
    <cfset var writer = "">
    <cfset var reader = "">
    <cfset var buffered = "">
    <cfset var line = "">
    <cfset var sendToFile = false>
    <cfset var errorFound = false>
    
    <cfscript>
        if ( len(trim(arguments.logPath)) ) {
            out = createObject("java", 
"java.io.FileOutputStream").init(arguments.logPath);
            writer = createObject("java", "java.io.PrintWriter").init(out);
            sendToFile = true;
        }

        reader = createObject("java", 
"java.io.InputStreamReader").init(arguments.in);
        buffered = createObject("java", "java.io.BufferedReader").init(reader);
        line = buffered.readLine();
        while ( IsDefined("line") ) {
            if (sendToFile) {
                writer.println(line);
            }
            line = buffered.readLine();
        }    
           if (sendToFile) {
           errorFound = writer.checkError();
           writer.flush();
           writer.close();
        }
    </cfscript>
    <!--- return true if no errors found. --->
    <cfreturn (NOT errorFound)>
</cffunction>


Reply via email to