FFMPEG 返回非零退出状态.检查标准冷聚变



我有一个冷聚变应用程序。我正在通过ffmpeg和coldfusion从移动设备转换录制的视频。这是我正在运行的 ffmpeg 命令。

ffmpegPath -i "inputfile" -vcodec libx264 -acodec aac "OutputFile"

输出文件类型为mp4。我想将所有视频转换为带有h.4和ACC声音的mp264。这样它就可以在所有平台上工作。

我收到以下错误:

java.io.IOException: ffmpeg returned non-zero exit status. Check stdout.

这是我正在运行的 CF 代码。

<cfset resultLog        = "pathtodirectorytestOuput_result.log">
<cfset errorLog         = "pathtodirectorytestOuput_error.log">
<cfset results  = structNew()> 
        <cfscript>
            try {  
                runtime = createObject("java", "java.lang.Runtime").getRuntime();
                command = 'ffmpegPath -i "inputfile" -vcodec libx264 -acodec aac "OutputFile"';
                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>
<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> 

我也使用了不同的ffmpeg.exe但得到了同样的错误。我还在 coldfusion 中使用了 ffmpeg-cli-wrapper java wrapper。我仍然得到同样的错误。任何人都可以帮我解决这个问题。

我能够解决这个问题。问题出在输入文件路径中。我已经通过将输入文件的绝对路径传递给 ffmpeg 来解决此问题

与错误无关,但你确定你真的需要Runtime.exec()吗?这通常是矫枉过正。大多数应用程序都可以用<cfexecute>调用,它基本上是Runtime.exec()的包装器,它做同样的事情,只是代码更少。

早在CF8中.exe cfexecute和ffmpeg就存在问题,这是由于早期版本的cfexecute没有捕获StdErr造成的。但是,这在CF8更新之一中得到了解决。假设您使用的是最新版本的 CF,它应该开箱即用。未经测试,但大致如下:

注意:请注意所有文件使用绝对路径

<!--- change to the appropriate timeout --->
<cfexecute name="c:pathtoffmpeg.exe" 
    arguments=' -i "c:pathtoin.file" -vcodec libx264 -acodec aac "c:pathtoout.file"'
    timeout="120" 
    variable="result"
    errorVariable="errorMessage"
    /> 
<!--- Display results --->
<cfoutput>
   result = #result#
   errorVariable = #errorVariable #
</cfoutput>

有关参数和语法的更多详细信息,请参阅cfexecute文档。

最新更新