我想合并 IMAGE + AUDIO 并使用 FFMPEG 库将它们转换为视频,我成功编译了库,并获得了 libfmpeg.so。但是通过 java 代码执行 ffmpeg 命令时遇到问题。这是我正在使用的命令... “ffmpeg -i image8.jpg -i file.m4a -acodec copy test.mp4” 如果我通过 CMD 执行此 ffmpeg 命令,我的 video.mp4 文件已成功创建,但如果通过我的 Activity 执行相同的命令,它不会创建任何文件。
我的代码是:
公共类 Mpeg 扩展 Activity {
static {
System.loadLibrary("ffmpeg");
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_mpeg);
文件 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