Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
719 views
in Technique[技术] by (71.8m points)

android - How to convert GIF to Mp4 is it possible?

I have search on internet and i found this library called "ffmpeg" that saying it is able to convert GIF TO MP4. I have tried but no success and getting exception.

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

If anybody know how to convert GIF to MP4 in android platform please help me. thanks

EDIT

this is i am doing using above 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();
        }

getting following exception

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)
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

This is the syntax for ffmpeg to convert a gif to mp4:

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

The android command line version of ffmpeg will be very similar.

This javadoc explains how to use the android-ffmpeg library to run commands on ffmpeg.

Hope that helps


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...