2015-07-09 45 views
1

我正在使用Cordova原型製作混合應用程序:https://cordova.apache.org。同樣使用這個插件:https://github.com/jbavari/cordova-plugin-video-editorAndroid java應用程序上的FFMPEG

該插件使用FFMPEG將視頻轉換爲新格式。的代碼完成這項功能,具體的一條是在這裏:

https://github.com/jbavari/cordova-plugin-video-editor/blob/master/src/android/VideoEditor.java

al.add("ffmpeg"); 
al.add("-i"); 
al.add(videoSrcPath); 
String[] ffmpegCommand = al.toArray(new String[al.size()]); 
vk.run(ffmpegCommand, workFolder, appContext); 
Log.d(TAG, Arrays.toString(ffmpegCommand)); 

當Android Studio中使用變量退出是:

[ffmpeg, -y, -i, /storage/emulated/0/DCIM/Camera/20150709_172753.mp4, -strict, experimental, -s, 320x320, -r, 24, -vcodec, libx264, -preset, ultrafast, -b, 2097152, -ac, 1, -ar, 22050, -t, 2.0, /storage/emulated/0/Movies/HelloWorld/VID_render-1436477283566.mp4] 

這是可以正常使用。

我想修改此命令以允許多個視頻和其他選項。下面是我在我的機器上工作的測試FFMPEG終端命令:

./ffmpeg -i a.mp4 -i b.mp4 -filter_complex "[0:0] [0:1] [1:0] [1:1] concat=n=2:v=1:a=1 [v] [a]" -map "[v]" -map "[a]" -loglevel debug -strict -2 output.mp4 

我已經嘗試修改Java代碼,但這個失敗:

al.add("ffmpeg"); 
al.add("-i"); 
al.add(videoSrcPath); 
al.add("-i"); 
al.add(videoSrcPath2); 
al.add("-filter_complex"); 
al.add("[0:0] [0:1] [1:0] [1:1] concat=n=2:v=1:a=1 [v] [a]"); 
al.add("-map"); 
al.add("[v]"); 
al.add("-map"); 
al.add("[a]"); 
al.add("-strict"); 
al.add("-2"); 

這是失敗的命令時註銷與變量:

[ffmpeg, -y, -i, /storage/emulated/0/DCIM/Camera/20150709_175137.mp4, -i, /storage/emulated/0/Movies/HelloWorld/20150709_234321.mp4, -filter_complex, [0:0] [0:1] [1:0] [1:1] concat=n=2:v=1:a=1 [v] [a], -map, [v], -map, [a], -strict, -2, experimental, -s, 320x320, -r, 24, -vcodec, libx264, -preset, ultrafast, -b, 2097152, -ac, 1, -ar, 22050, -t, 2.0, /storage/emulated/0/Movies/HelloWorld/VID_render-1436478706526.mp4] 

我嘗試使用FFMPEG的日誌功能,我不能讓它回到返回Java日誌,這確實限制了什麼,我可以調試:(

al.add("-loglevel"); 
al.add("debug"); 

任何幫助將不勝感激!

回答

0

因此,這是工作代碼,允許多部影片使用科爾多瓦 - 插件的視頻編輯器來渲染,它的扶養庫ffmpeg4android:

的index.html

VideoEditor.transcodeVideo(
    videoTranscodeSuccess, 
    videoTranscodeError, 
    { 
     fileUri: file.fullPath, 
     fileUri2: file2.fullPath, 
     outputFileName: videoFileName, 
     quality: VideoEditorOptions.Quality.LOW_QUALITY, 
     outputFileType: VideoEditorOptions.OutputFileType.MPEG4, 
     optimizeForNetworkUse: VideoEditorOptions.OptimizeForNetworkUse.YES, 
     duration: 2 
    } 
); 

VideoEditor.js線99

final File inFile = this.resolveLocalFileSystemURI(options.getString("fileUri")); 
if (!inFile.exists()) { 
    Log.d(TAG, "input file does not exist"); 
    callback.error("input video does not exist."); 
    return; 
} 

final File inFile2 = this.resolveLocalFileSystemURI(options.getString("fileUri2")); 
if (!inFile2.exists()) { 
    Log.d(TAG, "input file2 does not exist"); 
    callback.error("input video2 does not exist."); 
    return; 
} 

final String videoSrcPath = inFile.getAbsolutePath(); 
final String videoSrcPath2 = inFile2.getAbsolutePath(); 

VideoEditor。JS線230

al.add("ffmpeg"); 
al.add("-i"); // input file 
al.add(videoSrcPath); 
al.add("-i"); // input file 2 
al.add(videoSrcPath2); 
al.add("-filter_complex"); 
al.add("[0:0] [0:1] [1:0] [1:1] concat=n=2:v=1:a=1 [v] [a]"); 
al.add("-map"); 
al.add("[v]"); 
al.add("-map"); 
al.add("[a]"); 
al.add("-strict"); 
al.add("-2"); 
al.add("-preset"); 
al.add("ultrafast"); 
al.add(outputFilePath); // output file at end of string 

String[] ffmpegCommand = al.toArray(new String[al.size()]); 
vk.run(ffmpegCommand, workFolder, appContext); 

自從得到這個工作,我注意到ffmpeg4android庫需要許可證:

I/Videokit﹕ licenseCheck in path: /data/data/com.example.hello/files 
I/Videokit﹕ isLicExistsComplex... 
I/Videokit﹕ trying to open /data/data/com.example.hello/files/ffmpeglicense.lic 
I/Videokit﹕ license file found... 
I/Videokit﹕ You used 1 of your 15 trial days. 

許可證信息可以在這裏找到:

http://www.appfree.org/item.php?item_id=com.netcompss.ffmpeg4android http://ffmpeg4android.netcompss.com/home/purchase

有一個替代版本的cordova-plugin-video-editor使用android-ffmpeg-java天秤座RY這裏:

https://github.com/jbavari/cordova-plugin-video-editor/pull/13

0

原來的命令行具有以下選項:

-strict, experimental 

你的新的具有這樣的:

-strict, -2, experimental 

看起來這是什麼使得它打破。如果沒有,請記錄stdout/stderr,以便您可以看到它抱怨的內容。

+0

這是需要保證的AAC編碼器使用!我設法通過刪除其他屬性來實現它的工作 –

+0

這裏有一些文檔,它有助於:http://androidwarzone.blogspot.co.il/2011/12/ffmpeg4android.html –