【问题标题】:FFMPEG on Android java applicationAndroid java应用程序上的FFMPEG
【发布时间】:2015-07-12 00:45:58
【问题描述】:

我正在使用 Cordova 制作一个混合应用程序的原型:https://cordova.apache.org。也在使用这个插件: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 的日志记录功能,我无法让它返回到 Java Log,这确实限制了我可以调试的内容:(

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

任何帮助将不胜感激!

【问题讨论】:

    标签: java android cordova video ffmpeg


    【解决方案1】:

    原来的命令行有这些选项:

    -strict, experimental
    

    你的新人有这个:

    -strict, -2, experimental
    

    看起来这就是它崩溃的原因。如果没有,请记录 stdout/stderr,以便查看它抱怨的内容。

    【讨论】:

    【解决方案2】:

    所以这是允许使用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

    【讨论】:

      猜你喜欢
      • 2021-06-19
      • 2011-02-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-05-01
      • 2015-09-13
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多