Android java 应用程序上的 FFMPEG
FFMPEG on Android java application
我正在使用 Cordova 制作混合应用程序的原型:https://cordova.apache.org. Also using this plugin: https://github.com/jbavari/cordova-plugin-video-editor
该插件使用 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 的日志记录功能,我无法将其 return 返回到 Java 日志,这确实限制了我可以调试的内容:(
al.add("-loglevel");
al.add("debug");
如有任何帮助,我们将不胜感激!
原来的命令行有这些选项:
-strict, experimental
你的新人有这个:
-strict, -2, experimental
看来这就是它崩溃的原因。如果没有,请记录 stdout/stderr 以便您查看它抱怨的内容。
所以这是允许使用 cordova-plugin-video-editor 呈现多个视频的工作代码及其依赖库 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
这里有一个使用 android-ffmpeg-java 库的 cordova-plugin-video-editor 的替代版本:
https://github.com/jbavari/cordova-plugin-video-editor/pull/13
我正在使用 Cordova 制作混合应用程序的原型:https://cordova.apache.org. Also using this plugin: https://github.com/jbavari/cordova-plugin-video-editor
该插件使用 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 的日志记录功能,我无法将其 return 返回到 Java 日志,这确实限制了我可以调试的内容:(
al.add("-loglevel");
al.add("debug");
如有任何帮助,我们将不胜感激!
原来的命令行有这些选项:
-strict, experimental
你的新人有这个:
-strict, -2, experimental
看来这就是它崩溃的原因。如果没有,请记录 stdout/stderr 以便您查看它抱怨的内容。
所以这是允许使用 cordova-plugin-video-editor 呈现多个视频的工作代码及其依赖库 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
这里有一个使用 android-ffmpeg-java 库的 cordova-plugin-video-editor 的替代版本:
https://github.com/jbavari/cordova-plugin-video-editor/pull/13