Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

java.io.IOException: Error running exec() Working Directory: null Environment: null

I am using WritingMinds/ffmpeg-android-java in application.

here is my code

loadFFmpeg();
String cmd="ffmpeg -i /storage/emulated/0/media/audio/a.mp3 -i  /storage/emulated/0/recording.3gp -filter_complex \"[0:a][1:a]amerge=inputs=2[aout]\" -map \"[aout]\" " + outputFile;
executeFFmpeg(cmd.split(" "));

and

private void loadFFmpeg() {
    FFmpeg ffmpeg = FFmpeg.getInstance(MainActivity.this.getApplicationContext());
    try {
        ffmpeg.loadBinary(new LoadBinaryResponseHandler() {

            @Override
            public void onStart() {}

            @Override
            public void onFailure() {}

            @Override
            public void onSuccess() {}

            @Override
            public void onFinish() {}
        });
    } catch (FFmpegNotSupportedException e) {
        // Handle if FFmpeg is not supported by device
    }
}

private void executeFFmpeg(String[] cmd)
{
    /*String workFolder = getApplicationContext().getFilesDir() + "/ffmpeg";
    String environment = Environment.getExternalStorageDirectory().getAbsolutePath();
    Map<String, String> map = new HashMap<String, String>();
    map.put("Working Directory", workFolder);
    map.put("Environment",environment);*/
    FFmpeg ffmpeg = FFmpeg.getInstance(MainActivity.this.getApplicationContext());
    try {
        // to execute "ffmpeg -version" command you just need to pass "-version"
        ffmpeg.execute(cmd, new ExecuteBinaryResponseHandler() {

            @Override
            public void onStart() {}

            @Override
            public void onProgress(String message) {}

            @Override
            public void onFailure(String message) {}

            @Override
            public void onSuccess(String message) {}

            @Override
            public void onFinish() {
                stop.setEnabled(false);
                play.setEnabled(true);
            }
        });
    } catch (FFmpegCommandAlreadyRunningException e) {
        // Handle if FFmpeg is already running
    }
}

but I am getting following error

6784-6962/com.flipartstudio.playandrecord E/FFmpeg: Exception while trying to run: [Ljava.lang.String;@41803270 java.io.IOException: Error running exec(). Command: [/data/data/com.flipartstudio.playandrecord/files/ffmpeg, /system/bin/ls, -l, /data/data/com.example.foo/files/ffmpeg] Working Directory: null Environment: null at java.lang.ProcessManager.exec(ProcessManager.java:211) at java.lang.Runtime.exec(Runtime.java:168) at java.lang.Runtime.exec(Runtime.java:123) at com.github.hiteshsondhi88.libffmpeg.ShellCommand.run(ShellCommand.java:10) at com.github.hiteshsondhi88.libffmpeg.FFmpegExecuteAsyncTask.doInBackground(FFmpegExecuteAsyncTask.java:38) at com.github.hiteshsondhi88.libffmpeg.FFmpegExecuteAsyncTask.doInBackground(FFmpegExecuteAsyncTask.java:10) at android.os.AsyncTask$2.call(AsyncTask.java:287) at java.util.concurrent.FutureTask.run(FutureTask.java:234) at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573) at java.lang.Thread.run(Thread.java:856) Caused by: java.io.IOException: No such file or directory at java.lang.ProcessManager.exec(Native Method) at java.lang.ProcessManager.exec(ProcessManager.java:209) at java.lang.Runtime.exec(Runtime.java:168)  at java.lang.Runtime.exec(Runtime.java:123)  at com.github.hiteshsondhi88.libffmpeg.ShellCommand.run(ShellCommand.java:10)  at com.github.hiteshsondhi88.libffmpeg.FFmpegExecuteAsyncTask.doInBackground(FFmpegExecuteAsyncTask.java:38)  at com.github.hiteshsondhi88.libffmpeg.FFmpegExecuteAsyncTask.doInBackground(FFmpegExecuteAsyncTask.java:10)  at android.os.AsyncTask$2.call(AsyncTask.java:287)  at java.util.concurrent.FutureTask.run(FutureTask.java:234)  at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)  at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)  at java.lang.Thread.run(Thread.java:856) 

I have also added

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.STORAGE" />
like image 841
Muhammad Hamza Shahid Avatar asked May 12 '16 11:05

Muhammad Hamza Shahid


2 Answers

your problem is that you declear FFmpeg once in loadFFmpeg() method and once in executeFFmpeg() . so in executeFFmpeg() your FFmpeg isn't loaded.

Solution :

your code should be like this :

public class Main extends Activity{

FFmpeg ffmpeg;
Context context;

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    context = this;

    loadFFmpeg();
    String cmd="ffmpeg -i /storage/emulated/0/media/audio/a.mp3 -i  /storage    /emulated/0/recording.3gp -filter_complex \"[0:a][1:a]amerge=inputs=2[aout]\" -map \"[aout]\" " + outputFile;
    executeFFmpeg(cmd.split(" "));

}

private void loadFFmpeg() {
    ffmpeg = FFmpeg.getInstance(context);
    try {
        ffmpeg.loadBinary(new LoadBinaryResponseHandler() {

            @Override
            public void onStart() {}

            @Override
            public void onFailure() {}

            @Override
            public void onSuccess() {}

            @Override
            public void onFinish() {}
        });
    } catch (FFmpegNotSupportedException e) {
        // Handle if FFmpeg is not supported by device
    }
}

private void executeFFmpeg(String[] cmd)
{
    try {
        ffmpeg.execute(cmd, new ExecuteBinaryResponseHandler() {

            @Override
            public void onStart() {}

            @Override
            public void onProgress(String message) {}

            @Override
            public void onFailure(String message) {}

            @Override
            public void onSuccess(String message) {}

            @Override
            public void onFinish() {
                stop.setEnabled(false);
                play.setEnabled(true);
            }
        });
    } catch (FFmpegCommandAlreadyRunningException e) {
        // Handle if FFmpeg is already running
    }
}
}
like image 199
FaridFaa Avatar answered Oct 21 '22 06:10

FaridFaa


Try this:

public class MainActivity extends Activity{

FFmpeg ffmpeg;
Context context;

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    context = this;

    loadFFmpeg();
    String cmd="-i /storage/emulated/0/media/audio/a.mp3 -i  /storage    /emulated/0/recording.3gp -filter_complex \"[0:a][1:a]amerge=inputs=2[aout]\" -map \"[aout]\" " + outputFile;
    executeFFmpeg(cmd.split(" "));

}

private void loadFFmpeg() {
    ffmpeg = FFmpeg.getInstance(context);
    try {
        ffmpeg.loadBinary(new LoadBinaryResponseHandler() {

            @Override
            public void onStart() {}

            @Override
            public void onFailure() {}

            @Override
            public void onSuccess() {}

            @Override
            public void onFinish() {}
        });
    } catch (FFmpegNotSupportedException e) {
        // Handle if FFmpeg is not supported by device
    }
}

private void executeFFmpeg(String[] cmd)
{
    try {
        ffmpeg.execute(cmd, new ExecuteBinaryResponseHandler() {

            @Override
            public void onStart() {}

            @Override
            public void onProgress(String message) {}

            @Override
            public void onFailure(String message) {}

            @Override
            public void onSuccess(String message) {}

            @Override
            public void onFinish() {
                stop.setEnabled(false);
                play.setEnabled(true);
            }
        });
    } catch (FFmpegCommandAlreadyRunningException e) {
        // Handle if FFmpeg is already running
    }
}
}
like image 39
Chetan Patel Avatar answered Oct 21 '22 06:10

Chetan Patel