FFmpeg在处理命令时抛出异常

时间:2014-06-02 07:31:47

标签: android process ffmpeg ioexception

我正在通过进程执行命令,但它总是抛出任何人帮助我的错误?

FFMPEGCommand:

    String[] ffmpegCommand = {"/data/data/com.example.app/ffmpeg", "-r", ""+VIDEO_FRAME_RATE, "-b", "1000", "-vcodec", "mjpeg", "-i", Environment.getExternalStorageDirectory().getPath() + "/com.example.app/frame_%05d.jpg", Environment.getExternalStorageDirectory().getPath() + "/video.mov"};

    ffmpegProcess = new ProcessBuilder(ffmpegCommand).redirectErrorStream(true).start();            

W/System.err(29844): java.io.IOException: Error running exec(). Command: [/data/data/com.example.app/ffmpeg, -r, 18, -b, 1000, -vcodec, mjpeg, -i, /storage/emulated/0/com.example.app/frame_%05d.jpg, /storage/emulated/0/video.mov] Working Directory: null Environment: [ANDROID_ROOT=/system, EMULATED_STORAGE_SOURCE=/mnt/shell/emulated, LOOP_MOUNTPOINT=/mnt/obb, EMULATED_STORAGE_TARGET=/storage/emulated, ANDROID_BOOTLOGO=1, LD_LIBRARY_PATH=/vendor/lib:/system/lib, EXTERNAL_STORAGE=/storage/emulated/legacy, ANDROID_SOCKET_zygote=11, ANDROID_DATA=/data, PATH=/sbin:/vendor/bin:/system/sbin:/system/bin:/system/xbin, ANDROID_ASSETS=/system/app, ASEC_MOUNTPOINT=/mnt/asec, BOOTCLASSPATH=/system/framework/core.jar:/system/framework/conscrypt.jar:/system/framework/okhttp.jar:/system/framework/core-junit.jar:/system/framework/bouncycastle.jar:/system/framework/ext.jar:/system/framework/framework.jar:/system/framework/framework2.jar:/system/framework/telephony-common.jar:/system/framework/voip-common.jar:/system/framework/mms-common.jar:/system/framework/android.policy.jar:/system/framework/services.jar:/system/framework/apache-xml.jar:/system/framework/webviewchromium.jar:/system/framework/oem-services.jar:/system/framework/qcmediaplayer.jar, ANDROID_PROPERTY_WORKSPACE=9,0, ANDROID_STORAGE=/storage]
06-02 12:21:36.660: W/System.err(29844):    at java.lang.ProcessManager.exec(ProcessManager.java:211)
06-02 12:21:36.660: W/System.err(29844):    at java.lang.ProcessBuilder.start(ProcessBuilder.java:195)
06-02 12:21:36.662: W/System.err(29844):    at com.example.app.FFMPEGRecorderActivity$ProcessVideo.doInBackground(FFMPEGRecorderActivity.java:1448)
06-02 12:21:36.662: W/System.err(29844):    at com.example.app.FFMPEGRecorderActivity$ProcessVideo.doInBackground(FFMPEGRecorderActivity.java:1)
06-02 12:21:36.662: W/System.err(29844):    at android.os.AsyncTask$2.call(AsyncTask.java:288)
06-02 12:21:36.663: W/System.err(29844):    at java.util.concurrent.FutureTask.run(FutureTask.java:237)
06-02 12:21:36.663: W/System.err(29844):    at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
06-02 12:21:36.663: W/System.err(29844):    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
06-02 12:21:36.663: W/System.err(29844):    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
06-02 12:21:36.663: W/System.err(29844):    at java.lang.Thread.run(Thread.java:841)
06-02 12:21:36.664: W/System.err(29844): Caused by: java.io.IOException: No such file or directory
06-02 12:21:36.665: W/System.err(29844):    at java.lang.ProcessManager.exec(Native Method)
06-02 12:21:36.666: W/System.err(29844):    at java.lang.ProcessManager.exec(ProcessManager.java:209)
06-02 12:21:36.667: W/System.err(29844):    ... 9 more

2 个答案:

答案 0 :(得分:1)

通过快速查看错误,ffmpeg的输入文件为null而不是完整路径。

所以,替换

 Environment.getExternalStorageDirectory().getPath() + "/com.example.app/frame_%05d.jpg"

跟随伪代码。

在输入jpg上获取一个File实例。

  myInputJpg.getAbsolutePath()

可以为输入提供非null的ffmpeg文件句柄...

答案 1 :(得分:0)

当我重新执行.so文件并修改这样的路径时,它已得到修复:

String[] ffmpegCommand = {"/data/data/com.example.app/ffmpeg", "-r", ""+VIDEO_FRAME_RATE, "-vcodec", "mjpeg", "-i", Environment.getExternalStorageDirectory().getPath() + "/com.example.app/frame_%105d.jpg",  Environment.getExternalStorageDirectory().getPath() + "/com.example.app/video.mov"};

ProcessBuilder builder = new ProcessBuilder(ffmpegCommand);  
        Map<String, String> env = builder.environment();
        env.put("LD_LIBRARY_PATH", "/data/data/com.example.app:$LD_LIBRARY_PATH");

        ffmpegProcess = builder.redirectErrorStream(true).start();  

            OutputStream ffmpegOutStream = ffmpegProcess.getOutputStream();
            BufferedReader reader = new BufferedReader(new InputStreamReader(ffmpegProcess.getInputStream()));

            String line;

            Log.v("ss","***Starting FFMPEG***");
            while ((line = reader.readLine()) != null)
            {
                Log.v("asd","***"+line+"***");
            }
            Log.v("asdas","***Ending FFMPEG***");