IOException异常:错误运行的exec()命令,当调用FFmpeg的方法 [英] IOException: Error running exec() Command, When calling FFmpeg method
问题描述
我试图用,以创建幻灯片MP4这个<一个href=\"https://github.com/guardianproject/android-ffmpeg-java/blob/master/src/org/ffmpeg/android/FfmpegController.java#L332\"相对=nofollow> ffmpeg的方法但我不断收到此IOException异常错误运行EXEC()。命令
当我点击的按钮。
i am trying to create a slide show mp4 using this ffmpeg method but i keep getting this IOException Error running exec(). Command
when i click the button.
这是我的电话
ffmpegController = new FfmpegController(getTempDirectory(), new File(""));
ffmpegController.createSlideshowFromImagesAndAudio(slideFrames, getAudioPath(), getOutPath(), 500, mCallbackResponse);
这是我的错误消息
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]
下面是我的活动code:
Here is my Activity code:
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();
}
任何帮助,将AP preciated
any help would be appreciated
推荐答案
您需要复制的ffmpeg
二进制文件 RES /原料
文件夹这里讨论。
you will need to copy ffmpeg
binaries to res/raw
folder as discussed here.
您还可能需要先建立他们(不要从以上项目只是复制),并确保他们可以为您打算在测试设备上运行。
you may also need to build them first (dont just copy from above project), and make sure they can run on the device you are planning to test.
这篇关于IOException异常:错误运行的exec()命令,当调用FFmpeg的方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!