java.io.IOException:运行exec()时出错工作目录:null环境:null FFmpeg Android合并mp3和mp4

时间:2017-04-23 05:15:54

标签: java android video ffmpeg

java.io.IOException:运行exec()时出错工作目录:null环境:null FFmpeg Android合并mp3和mp4

我正在尝试关注代码

public class Minact1 extends Activity{
    String  videoFilePath,audioFilePath,outputFilePath;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.mainact);
        videoFilePath = Environment.getExternalStorageDirectory()
                .getAbsolutePath() + "/sample2.mp4";
        audioFilePath = Environment.getExternalStorageDirectory()
                .getAbsolutePath() + "/abc.mp3";
        outputFilePath = Environment.getExternalStorageDirectory()
                .getAbsolutePath() + "/output.mp4";

        try {


            FFmpeg ffmpeg = FFmpeg.getInstance(this);
            String[] cmd =
                    {"-i " + videoFilePath + " -i " + audioFilePath +
                            " -shortest -threads 0 -preset ultrafast -strict -2 " + outputFilePath};

            ffmpeg.execute(cmd, mergeListener);
        } catch (FFmpegCommandAlreadyRunningException e) {
            e.printStackTrace();

            Toast.makeText(Minact1.this, "" +  e, Toast.LENGTH_SHORT).show();
        }
    }

    ExecuteBinaryResponseHandler mergeListener = new ExecuteBinaryResponseHandler() {
        @Override
        public void onStart() {
            //started
            Toast.makeText(Minact1.this, "started", Toast.LENGTH_SHORT).show();
        }

        @Override
        public void onFailure(String message) {
            //failed
            Toast.makeText(Minact1.this, "failed", Toast.LENGTH_SHORT).show();
        }

        @Override
        public void onFinish() {
            File output = new File(outputFilePath);
            //Do whatever with your muxed file

            Toast.makeText(Minact1.this, "onFinish", Toast.LENGTH_SHORT).show();
        }
    };
}

我在FFmpeg

中使用了以下库
dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:23.1.1'

    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })

    compile 'com.android.support:design:23.1.1'
    compile 'com.writingminds:FFmpegAndroid:0.3.2'

    compile 'com.android.support:cardview-v7:23.1.1'
    compile 'commons-io:commons-io:2.5'
}

并在清单

中添加了以下权限
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />

文件出现在使用的路径中,但未创建output.mp4

日志说

04-23 10:43:39.278 27191-27216/com.ffmpegtryer E/FFmpeg: Exception while trying to run: [Ljava.lang.String;@3fe418b2
04-23 10:43:39.278 27191-27216/com.ffmpegtryer E/FFmpeg: java.io.IOException: Error running exec(). Command: [/data/data/com.ffmpegtryer/files/ffmpeg, -i /storage/sdcard0/sample2.mp4 -i /storage/sdcard0/abc.mp3 -shortest -threads 0 -preset ultrafast -strict -2 /storage/sdcard0/output.mp4] Working Directory: null Environment: null
04-23 10:43:39.278 27191-27216/com.ffmpegtryer E/FFmpeg:     at java.lang.ProcessManager.exec(ProcessManager.java:211)
04-23 10:43:39.278 27191-27216/com.ffmpegtryer E/FFmpeg:     at java.lang.Runtime.exec(Runtime.java:173)
04-23 10:43:39.278 27191-27216/com.ffmpegtryer E/FFmpeg:     at java.lang.Runtime.exec(Runtime.java:128)
04-23 10:43:39.278 27191-27216/com.ffmpegtryer E/FFmpeg:     at com.github.hiteshsondhi88.libffmpeg.ShellCommand.run(ShellCommand.java:10)
04-23 10:43:39.278 27191-27216/com.ffmpegtryer E/FFmpeg:     at com.github.hiteshsondhi88.libffmpeg.FFmpegExecuteAsyncTask.doInBackground(FFmpegExecuteAsyncTask.java:38)
04-23 10:43:39.278 27191-27216/com.ffmpegtryer E/FFmpeg:     at com.github.hiteshsondhi88.libffmpeg.FFmpegExecuteAsyncTask.doInBackground(FFmpegExecuteAsyncTask.java:10)
04-23 10:43:39.278 27191-27216/com.ffmpegtryer E/FFmpeg:     at android.os.AsyncTask$2.call(AsyncTask.java:288)
04-23 10:43:39.278 27191-27216/com.ffmpegtryer E/FFmpeg:     at java.util.concurrent.FutureTask.run(FutureTask.java:237)
04-23 10:43:39.278 27191-27216/com.ffmpegtryer E/FFmpeg:     at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
04-23 10:43:39.278 27191-27216/com.ffmpegtryer E/FFmpeg:     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
04-23 10:43:39.278 27191-27216/com.ffmpegtryer E/FFmpeg:     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
04-23 10:43:39.278 27191-27216/com.ffmpegtryer E/FFmpeg:     at java.lang.Thread.run(Thread.java:818)
04-23 10:43:39.278 27191-27216/com.ffmpegtryer E/FFmpeg:  Caused by: java.io.IOException: No such file or directory
04-23 10:43:39.278 27191-27216/com.ffmpegtryer E/FFmpeg:     at java.lang.ProcessManager.exec(Native Method)
04-23 10:43:39.278 27191-27216/com.ffmpegtryer E/FFmpeg:     at java.lang.ProcessManager.exec(ProcessManager.java:209)

任何帮助都会有用

0 个答案:

没有答案