如何顺序执行两个ffmpeg命令

时间:2018-01-09 20:49:05

标签: java android ffmpeg event-handling

我正在使用此库FFmpeg-Android在我的Android项目中运行FFmpeg。

我有这个代码,我想同时运行两个不同的命令:

private void FFmpegExecuteTask() {
    try {

        String[] command1 = {
                "-i",
                mInputFile.getAbsolutePath(),
                "-c",
                "copy",
                "-bsf:v",
                "h264_mp4toannexb",
                "-f",
                "mpegts",
                "-y",
                Environment.getExternalStorageDirectory() + "temp1.ts",
                "-i",
                mIntro.getAbsolutePath(),
                "-c",
                "copy",
                "-bsf:v",
                "h264_mp4toannexb",
                "-f",
                "mpegts",
                "-y",
                Environment.getExternalStorageDirectory() + "temp2.ts"
        };

        String[] command2 = {
                "-i",
                "concat:" + Environment.getExternalStorageDirectory() + "temp1.ts|" + Environment.getExternalStorageDirectory() + "temp2.ts",
                "-c",
                "copy",
                "-bsf:a",
                "aac_adtstoasc",
                "-y",
                mOutputFile.getAbsolutePath()
        };

        final FFtask task = mFFmpeg.execute(command1, new ExecuteBinaryResponseHandler() {
            @Override
            public void onStart() {
                Log.d(TAG, "on start");
                progressDialog.setMessage("Processing...");
                progressDialog.show();
            }

            @Override
            public void onFinish() {
                Log.d(TAG, "on finish");
                progressDialog.dismiss();
            }

            @Override
            public void onSuccess(String message) {
                Log.d(TAG, message);
                progressDialog.dismiss();

                showVideoPreview();
            }

            @Override
            public void onProgress(String message) {
                Log.d(TAG, message);
                progressDialog.setMessage("Processing\n" + message);
            }

            @Override
            public void onFailure(String message) {
                Log.e(TAG, message);
                progressDialog.dismiss();
            }
        });
    } catch (FFmpegCommandAlreadyRunningException e) {
        Log.d(TAG, "command already running");
    }
}

我想首先执行command1然后执行command2。

Command1执行得很好但是在onSuccess和onFinish command1之后我想在那之后运行command2。

是否有可能按顺序执行多个FFmpeg命令并且一旦所有命令都成功完成调用处理结果的方法?

0 个答案:

没有答案