IOException:运行exec()命令时出错,调用FFmpeg方法时

时间:2014-09-01 03:14:08

标签: java android eclipse ffmpeg

我正在尝试使用此ffmpeg method创建幻灯片放映mp4,但是当我单击按钮时,我不断收到此IOException Error running exec(). Command

这是我的电话

ffmpegController = new FfmpegController(getTempDirectory(), new File(""));
ffmpegController.createSlideshowFromImagesAndAudio(slideFrames, getAudioPath(), getOutPath(), 500, mCallbackResponse);

这是小项目的source code。 这是the apk

这是我的错误消息

   Error running exec(). Command: [ffmpeg, -y, -i, /storage/emulated/0/TestFFmpeg/frame1.png, /storage/emulated/0/TestFFmpeg/temp/image-000.jpg]

 Working Directory: lib Environment: [VIBE_PIPE_PATH=/dev/pipes, 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=9, 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/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/sec_edm.jar:/system/framework/seccamera.jar:/system/framework/secocsp.jar:/system/framework/sc.jar:/system/framework/scrollpause.jar:/system/framework/stayrotation.jar:/system/framework/smartfaceservice.jar:/system/framework/sws.jar:/system/framework/WfdCommon.jar, ANDROID_PROPERTY_WORKSPACE=8,66560, SECONDARY_STORAGE=/storage/extSdCard:/storage/UsbDriveA:/storage/UsbDriveB:/storage/UsbDriveC:/storage/UsbDriveD:/storage/UsbDriveE:/storage/UsbDriveF, ANDROID_STORAGE=/storage]

这是我的活动代码:

public class MainActivity extends Activity {

Button testButton;
EditText errorLogView;

TinyDB tinydb;// sharedPreference Wrapper
static Context context;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    context = getApplicationContext();
    tinydb = new TinyDB(context); // sharedPreference Wrapper
    testButton = (Button) findViewById(R.id.test_Image_View);
    errorLogView = (EditText) findViewById(R.id.errorlog);
    setListeners();
}

public void setListeners(){
    testButton.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            Bitmap frame1Bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher);
            //Saves the image to the file system an returns the path
            String firstFrame = tinydb.putImagePNG("TestFFmpeg", "frame1.png", frame1Bitmap);
            String secondFrame = tinydb.putImagePNG("TestFFmpeg", "frame2.png", frame1Bitmap);
            String thirdFrame = tinydb.putImagePNG("TestFFmpeg", "frame3.png", frame1Bitmap);


            ArrayList<Clip> slideFrames = new ArrayList<Clip>();
            slideFrames.add(new Clip(firstFrame));
            slideFrames.add(new Clip(secondFrame));
            slideFrames.add(new Clip(thirdFrame));

            copyResourceSoundToSDCard();

            FfmpegController ffmpegController = null;
            try {

                ffmpegController = new FfmpegController(getTempDirectory(), new File(""));
                ffmpegController.createSlideshowFromImagesAndAudio(slideFrames, getAudioPath(), getOutPath(), 500, mCallbackResponse);

            } catch (FileNotFoundException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
                toast("FileNotFoundException");
                toast(e.getLocalizedMessage());
            } catch (IOException e) {
                // TODO Auto-generated catch block
                toast("IOException");
                toast(e.getLocalizedMessage());
                errorLogView.setText(e.getLocalizedMessage());
                e.printStackTrace();
            } catch (Exception e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
                toast("Exception ");
                toast(e.getLocalizedMessage());
            }           
        }
    });


}

public Clip getAudioPath(){
    Clip mAudPath = null;
    try {
        mAudPath = new Clip(new File(tinydb.getString("audpath")).getCanonicalPath());
    } catch (IOException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    }
    return mAudPath;
}

public Clip getOutPath(){
    String videoName = ("myTestVideo.mp4");
    String saveFolder = ("TestFFmpeg/videos");
    String movieFullPath = setupAudioFolder(saveFolder, videoName);

    Clip outPath = null;
    try {
        outPath = new Clip(new File(movieFullPath).getCanonicalPath());
    } catch (IOException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    }
    tinydb.putString("outhPath", outPath.path);

    return outPath;
}

public void copyResourceSoundToSDCard(){
    try {
        copyRawFile(context, R.raw.screens_shot_sound, getResaveDirectory(), "755");
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (InterruptedException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}

 private File getResaveDirectory(){

    String audioName = ("ShotSound.wav");
    String saveFolder = ("TestFFmpeg");
    File appRootFile;
    String path = setupAudioFolder(saveFolder, audioName);
    tinydb.putString("audpath",  path);
    appRootFile = new File(path);
    return appRootFile;
  }

public String setupAudioFolder(String theFolder, String theImageName){
    File sdcard_path = Environment.getExternalStorageDirectory();
    File mFolder = new File(sdcard_path, theFolder);
    if (!mFolder.exists()) {
        if (!mFolder.mkdirs()) {
            Log.e("While creatingsave path",
                    "Default Save Path Creation Error");
            // Toast("Default Save Path Creation Error");
        }
    }
    String mFullPath = mFolder.getPath() + '/' + theImageName;

    return mFullPath;
}
private static void copyRawFile(Context ctx, int resid, File file, String mode) throws IOException, InterruptedException
{
    final String abspath = file.getAbsolutePath();
    // Write the iptables binary
    final FileOutputStream out = new FileOutputStream(file);
    final InputStream is = ctx.getResources().openRawResource(resid);
    byte buf[] = new byte[1024];
    int len;
    while ((len = is.read(buf)) > 0) {
        out.write(buf, 0, len);
    }
    out.close();
    is.close();
    // Change the permissions
    Runtime.getRuntime().exec("chmod "+mode+" "+abspath).waitFor();
}       
ShellCallback mCallbackResponse = new ShellUtils.ShellCallback() {

    @Override
    public void shellOut(String shellLine) {
        // TODO Auto-generated method stub

    }

    @Override
    public void processComplete(int exitValue) {
        // TODO Auto-generated method stub
        toast("process done");

    }
};

public File getTempDirectory(){
    String saveFolder = ("TestFFmpeg/temp");
    File appRootFile = setupCustomFile(saveFolder);


    return appRootFile;
 }

public File setupCustomFile(String theFolder){
    File sdcard_path = Environment.getExternalStorageDirectory();
    File mFolder = new File(sdcard_path, theFolder);
    if (!mFolder.exists()) {
        if (!mFolder.mkdirs()) {
            Log.e("While creatingsave path",
                    "Default Save Path Creation Error");
            // Toast("Default Save Path Creation Error");
        }
    }

    return mFolder;
}



public static void toast(String thetext) {
    Toast.makeText(context, thetext, Toast.LENGTH_LONG).show();
}

任何帮助将不胜感激

2 个答案:

答案 0 :(得分:2)

您需要copy ffmpeg binaries to res/raw folder as discussed here

您可能还需要先构建它们(不要只是从上面的项目中复制),并确保它们可以在您计划测试的设备上运行。

答案 1 :(得分:0)

使用下面的代码初始化ffmpeg

ffmpegController = new FfmpegController(MainActivity.this, getTempDirectory());