1

I want to create a video from multiple images using mp4parser. And I found answer from this link : https://github.com/sannies/mp4parser/issues/182

I have tried it using below code.

DataSource videoFile = new FileDataSourceImpl(new File(Environment.getExternalStorageDirectory() + File.separator + "myvideo.mp4"));

                Movie sor = MovieCreator.build(videoFile);
                List<Track> videoTracks = sor.getTracks();

                Track referenceTrack = null;
                for (Track candidate : sor.getTracks()) {
                    if (candidate.getSyncSamples() != null && "vide".equals(candidate.getHandler()) && candidate.getSyncSamples().length > 0) {
                        referenceTrack = candidate;

                        OneJpegPerIframe oneJpegPerIframe = null;
                        try {
                            oneJpegPerIframe = new OneJpegPerIframe("eng", arr,referenceTrack);  
                        } catch (IOException e) {
                            e.printStackTrace();
                        }

                        Movie movie = new Movie();
                        movie.addTrack(oneJpegPerIframe);

                        Container out = new DefaultMp4Builder().build(movie);
                        FileOutputStream fos = null;
                        try {
                            fos = new FileOutputStream(new File(Environment.getExternalStorageDirectory() + File.separator + "output.mp4"));
                            out.writeContainer(fos.getChannel());
                            fos.close();
                        } catch (IOException e) {
                            e.printStackTrace();
                        }
                    }
                }

But I got error like "java.lang.RuntimeException: Number of sync samples doesn't match the number of stills (30 vs. 4)" which I have shown below :

E/AndroidRuntime: FATAL EXCEPTION: main
java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=100, result=-1, data=Intent { (has extras) }} to activity {orafox.videomaker/orafox.videomaker.activity.MainActivity}: java.lang.RuntimeException: Number of sync samples doesn't match the number of stills (30 vs. 4)
at android.app.ActivityThread.deliverResults(ActivityThread.java:3367)
at android.app.ActivityThread.handleSendResult(ActivityThread.java:3410)
at android.app.ActivityThread.access$1100(ActivityThread.java:141)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1304)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5103)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.RuntimeException: Number of sync samples doesn't match the number of stills (30 vs. 4)
at com.googlecode.mp4parser.authoring.tracks.mjpeg.OneJpegPerIframe.<init>(OneJpegPerIframe.java:39)
at activity.MainActivity.onActivityResult(MainActivity.java:135)
at android.app.Activity.dispatchActivityResult(Activity.java:5322)
at android.app.ActivityThread.deliverResults(ActivityThread.java:3363)
at android.app.ActivityThread.handleSendResult(ActivityThread.java:3410) 
at android.app.ActivityThread.access$1100(ActivityThread.java:141) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1304) 
at android.os.Handler.dispatchMessage(Handler.java:99) 
at android.os.Looper.loop(Looper.java:137) 
at android.app.ActivityThread.main(ActivityThread.java:5103) 
at java.lang.reflect.Method.invokeNative(Native Method) 
at java.lang.reflect.Method.invoke(Method.java:525) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553) 
at dalvik.system.NativeStart.main(Native Method) 

I do not want to use "ffmpeg" library.

If anybody knew how to solve it please help me. Thanks in advance.

Hims
  • 233
  • 2
  • 13

0 Answers0