2014-09-01 125 views
1

我試圖創建一個使用此ffmpeg method幻燈片放映mp4,但我不斷收到此IOException Error running exec(). Command當我單擊按鈕。IOException:運行exec()命令錯誤,當調用FFmpeg方法

這裏是我的電話

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(); 
} 

任何幫助,將不勝感激

回答

0

使用下面的代碼初始化的ffmpeg

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

感謝,您的輸入。 但我通過在我的原始文件夾中包含正確的二進制文件解決了這個問題。 我曾經和原來的文件夾,這是問題的原因過時的二進制文件 – 2016-04-24 03:56:30

相關問題