Android 中的 JavaCV

JavaCV in Android

我下载了JavaCV-1-3-1。

现在我有两个问题:

  1. 如何将JavaCV导入Android Studio使用?

  2. 可以从 FFMPEG 命令中使用 JavaCV 吗?

要导入 java cv 将其添加到 gradle

 dependencies {
       compile 'org.bytedeco:javacv:+'
compile 'org.bytedeco.javacpp-presets:opencv:3.0.0-1.1:android-x86'
compile 'org.bytedeco.javacpp-presets:ffmpeg:2.8.1-1.1:android-x86'
compile 'org.bytedeco.javacpp-presets:opencv:3.0.0-1.1:android-arm'
compile 'org.bytedeco.javacpp-presets:ffmpeg:2.8.1-1.1:android-arm' 
    }

您也可以使用WritingMindslibrary。很容易实现。

依赖关系

compile 'com.writingminds:FFmpegAndroid:0.3.2'

您可以使用 execute()

进行视频相关处理

示例代码

final FFmpeg ffmpeg = FFmpeg.getInstance(activity);
        try {
            ffmpeg.loadBinary(new LoadBinaryResponseHandler() {

                @Override
                public void onStart() {}
                @Override
                public void onFailure() {}
                @Override
                public void onSuccess() {

                        String cropParams = "720:754:0:172";

                        String[] cmd = {"-i"
                                , originalPath
                                , "-vf"
                                ,cropParams
                                ,"-threads"
                                ,"5"
                                ,"-preset"
                                ,"ultrafast"
                                ,croppedPath};
                        // Execute cropping of video
                        ffmpeg.execute(cmd, new ExecuteBinaryResponseHandler() {
                            @Override
                            public void onStart() {
                            }
                            @Override
                            public void onProgress(String message) {
                                Log.i("Square", "progress : " +message);
                            }
                            @Override
                            public void onFailure(String message) {
                                Log.i("Square", "total fail : " + message);
                            }
                            @Override
                            public void onSuccess(String message) {
                                Log.i("Square", "Cropped video created.");

                            }
                            @Override
                            public void onFinish() {

                            }
                        });
                    } catch (FFmpegCommandAlreadyRunningException e) {
                        // Handle if FFmpeg is already running
                    }
                }
            });
        } catch (FFmpegNotSupportedException e) {
            // Handle if FFmpeg is not supported by device
        }