Reputation: 3131
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.
here is my call
ffmpegController = new FfmpegController(getTempDirectory(), new File(""));
ffmpegController.createSlideshowFromImagesAndAudio(slideFrames, getAudioPath(), getOutPath(), 500, mCallbackResponse);
Here is the source code of the small project. Here is the apk
And here is my Error message
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]
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();
}
any help would be appreciated
Upvotes: 1
Views: 906
Reputation: 270
use below code to initialize ffmpeg
ffmpegController = new FfmpegController(MainActivity.this, getTempDirectory());
Upvotes: 0
Reputation: 6461
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.
Upvotes: 2