3

I want to merge IMAGE + AUDIO and convert them into video using FFMPEG library,i compiled the library successfully,and got libfmpeg.so.but getting problem to execute the ffmpeg command through java code.This is command which i am using... "ffmpeg -i image8.jpg -i file.m4a -acodec copy test.mp4" if i execute this ffmpeg command through CMD,my video.mp4 file is successfully created,but if exceute same command through my Activity,it doesnot create any file.

MY CODE IS:

public class Mpeg extends Activity {

static {

    System.loadLibrary("ffmpeg");

}

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_mpeg);

File mf = Environment.getExternalStorageDirectory();

    String livestream = mf.getAbsoluteFile()+"smile.png";

    String folderpth = mf.getAbsoluteFile()+"RABBA.MP3";

    //String output="/home/saicomputer/game.mp4";

    String output = new File(Environment.getExternalStorageDirectory(), "video.mp4").getAbsolutePath();
    Log.i("Test", "Let's set output to " + output);

    String cmd="ffmpeg -i "+ livestream +" -i "+ folderpth +" -acodec copy "+ output;

     Log.e("chck plzzzzz", "after "+ cmd);

    //String jaiho="ffmpeg -i image8.jpg -i file.m4a -acodec copy test.mp4";

    try{

    Process p = Runtime.getRuntime().exec(cmd);

    }
catch(Exception e)
{
    System.out.println("exception"+e);
}

}

enter code here
CONSOLE OUTPUT-
06-05 17:58:11.466: E/image(1189): imageeeeeeeee /mnt/sdcard/smile.png
06-05 17:58:11.466: E/Test(1189): songggggggggg /mnt/sdcard/RABBA.MP3
06-05 17:58:11.476: E/Test(1189): outputttttt /mnt/sdcard/video.mp4
06-05 17:58:11.476: E/chck plzzzzz(1189): after ffmpeg -i /mnt/sdcard/smile.png -i      /mnt/sdcard/RABBA.MP3 -acodec copy /mnt/sdcard/video.mp4

enter code here
06-05 17:58:10.686: D/dalvikvm(1189): Trying to load lib /data/data/com.example.myfmpeg /lib/libffmpeg.so 0x412a5cf0
06-05 17:58:10.756: I/dalvikvm(1189): threadid=3: reacting to signal 3
06-05 17:58:10.955: D/dalvikvm(1189): Added shared lib /data/data/com.example.myfmpeg/lib/libffmpeg.so 0x412a5cf0
06-05 17:58:10.955: D/dalvikvm(1189): No JNI_OnLoad found in /data/data/com.example.myfmpeg/lib/libffmpeg.so 0x412a5cf0, skipping init
06-05 17:58:11.024: I/dalvikvm(1189): Wrote stack traces to '/data/anr/traces.txt'
06-05 17:58:11.215: I/dalvikvm(1189): threadid=3: reacting to signal 3
06-05 17:58:11.326: I/dalvikvm(1189): Wrote stack traces to '/data/anr/traces.txt'
06-05 17:58:11.466: E/image(1189): imageeeeeeeee /mnt/sdcard/smile.png
06-05 17:58:11.466: E/Test(1189): songggggggggg /mnt/sdcard/RABBA.MP3
06-05 17:58:11.476: E/Test(1189): outputttttt /mnt/sdcard/video.mp4
06-05 17:58:11.476: E/chck plzzzzz(1189): after ffmpeg -i /mnt/sdcard/smile.png -i /mnt/sdcard/RABBA.MP3 -acodec copy /mnt/sdcard/video.mp4
0 6-05 17:58:11.896: E/AndroidRuntime(1189): FATAL EXCEPTION: main
06-05 17:58:11.896: E/AndroidRuntime(1189): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.myfmpeg/com.example.myfmpeg.Mpeg}: java.lang.RuntimeException: java.io.IOException: Error running exec(). Command: [ffmpeg, -i, /mnt/sdcard/smile.png, -i, /mnt/sdcard/RABBA.MP3, -acodec, copy, /mnt/sdcard/video.mp4] Working Directory: null Environment: null
06-05 17:58:11.896: E/AndroidRuntime(1189):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1956)
06-05 17:58:11.896: E/AndroidRuntime(1189):     at 
06-05 17:58:11.896: E/AndroidRuntime(1189): Caused by: java.lang.RuntimeException: java.io.IOException: Error running exec(). Command: [ffmpeg, -i, /mnt/sdcard/smile.png, -i, /mnt/sdcard/RABBA.MP3, -acodec, copy, /mnt/sdcard/video.mp4] Working Directory: null       Environment: null
Nitish Singla
  • 171
  • 1
  • 8
  • 1
    Are you getting any ffmpeg log messages on console? That will help in debugging. – praks411 Jun 05 '13 at 12:10
  • 06-05 17:58:11.466: E/image(1189): imageeeeeeeee /mnt/sdcard/smile.png 06-05 17:58:11.466: E/Test(1189): songggggggggg /mnt/sdcard/RABBA.MP3 06-05 17:58:11.476: E/Test(1189): outputttttt /mnt/sdcard/video.mp4 06-05 17:58:11.476: E/chck plzzzzz(1189): after ffmpeg -i /mnt/sdcard/smile.png -i /mnt/sdcard/RABBA.MP3 -acodec copy /mnt/sdcard/video.mp4 – Nitish Singla Jun 05 '13 at 12:35
  • hii praks411,Console and LogCAT is above added – Nitish Singla Jun 05 '13 at 12:55
  • Are you able to run just ffmpeg -i input_file from you JAVA code. From log it seems to me as if you are not able to execute the ffmpeg command. I would suggest before going for actual encoding just confirm that you are able to execture ffmpeg -i from your java code. 6-05 17:58:11.896 Log – praks411 Jun 05 '13 at 14:59
  • no,i an unable to run this command-GOT ERROR-jav.run.time.Exception:- java.io.IOException: Error running exec(). Command: – Nitish Singla Jun 06 '13 at 06:00
  • i thing: this is problem of EXECUTING PERMISSION FROM ADB SHELL,we have to take permission before running these commands,plzz tell me if you know about it..... – Nitish Singla Jun 06 '13 at 07:24
  • I've worked with ffmpeg but never worked with JAVA, but I guess this link may help. http://stackoverflow.com/questions/7782007/how-to-write-adb-shell-commend-in-java-lang-runtime-getruntime. – praks411 Jun 06 '13 at 08:00
  • praks411,no good one link,i tried got same error.....can you ask from someone more experience,i mean in java/android,plzz help me... – Nitish Singla Jun 06 '13 at 10:47
  • I think you should re-post this as JAVA question, you may find better answers, as first you should be able to run ffmpeg from you app. Have you tried running any other application from you java app, other than ffmpeg – praks411 Jun 06 '13 at 12:27

0 Answers0