如何将GIF转换为Mp4有可能吗?

时间:2014-10-07 10:00:23

标签: android converter mp4 gif

我在互联网上搜索,我发现这个名为" ffmpeg"说它能够将GIF转换为MP4。我已经尝试但没有成功并获得例外。

https://github.com/guardianproject/android-ffmpeg-java

如果有人知道如何在Android平台上将GIF转换为MP4,请帮助我。感谢

修改

这是我正在使用上面的ffmpeg lib

String path = Environment.getExternalStorageDirectory()
                + "/gif/wall.jpg";
        String tmp = Environment.getExternalStorageDirectory() + "/gif/tmp";
        System.out.println(path);
        Clip clip = new Clip(path);
        File f = new File(tmp);
        try {
            f.createNewFile();
        } catch (IOException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        }
        try {
            FfmpegController controller = new FfmpegController(this, f);
            controller.convertImageToMP4(clip, 5,
                    Environment.getExternalStorageDirectory()
                            + "/gif/mynew.mp4", new ShellCallback() {

                        @Override
                        public void shellOut(String shellLine) {
                            // TODO Auto-generated method stub

                        }

                        @Override
                        public void processComplete(int exitValue) {
                            // TODO Auto-generated method stub

                        }
                    });

        } catch (FileNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

获得以下异常

10-09 14:39:59.638: W/System.err(19460): java.lang.NullPointerException: taintedCommand[7] == null
10-09 14:39:59.638: W/System.err(19460):    at java.lang.ProcessManager.exec(ProcessManager.java:184)
10-09 14:39:59.638: W/System.err(19460):    at java.lang.ProcessBuilder.start(ProcessBuilder.java:195)
10-09 14:39:59.638: W/System.err(19460):    at org.ffmpeg.android.FfmpegController.execProcess(FfmpegController.java:138)
10-09 14:39:59.638: W/System.err(19460):    at org.ffmpeg.android.FfmpegController.execFFMPEG(FfmpegController.java:102)
10-09 14:39:59.638: W/System.err(19460):    at org.ffmpeg.android.FfmpegController.execFFMPEG(FfmpegController.java:112)
10-09 14:39:59.638: W/System.err(19460):    at org.ffmpeg.android.FfmpegController.convertImageToMP4(FfmpegController.java:620)
10-09 14:39:59.638: W/System.err(19460):    at com.example.demo.MainActivity.onCreate(MainActivity.java:36)
10-09 14:39:59.638: W/System.err(19460):    at android.app.Activity.performCreate(Activity.java:5231)
10-09 14:39:59.638: W/System.err(19460):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
10-09 14:39:59.638: W/System.err(19460):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2148)
10-09 14:39:59.638: W/System.err(19460):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2233)
10-09 14:39:59.638: W/System.err(19460):    at android.app.ActivityThread.access$800(ActivityThread.java:135)
10-09 14:39:59.638: W/System.err(19460):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
10-09 14:39:59.638: W/System.err(19460):    at android.os.Handler.dispatchMessage(Handler.java:102)
10-09 14:39:59.638: W/System.err(19460):    at android.os.Looper.loop(Looper.java:136)
10-09 14:39:59.638: W/System.err(19460):    at android.app.ActivityThread.main(ActivityThread.java:5001)
10-09 14:39:59.638: W/System.err(19460):    at java.lang.reflect.Method.invokeNative(Native Method)
10-09 14:39:59.638: W/System.err(19460):    at java.lang.reflect.Method.invoke(Method.java:515)
10-09 14:39:59.638: W/System.err(19460):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
10-09 14:39:59.638: W/System.err(19460):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
10-09 14:39:59.638: W/System.err(19460):    at dalvik.system.NativeStart.main(Native Method)

1 个答案:

答案 0 :(得分:3)

这是ffmpeg将gif转换为mp4的语法:

ffmpeg -f gif -i infile.gif outfile.mp4

ffmpeg的android命令行版本将非常相似。

This javadoc解释了如何使用android-ffmpeg库在ffmpeg上运行命令。

希望有所帮助