0

My question is much like the one described in this post: Cant append to video in Android, only have been unable to use an updated jar to fix my problem (I am currently using is isoviewer-1.0-RC-26). The following is my code:

 private Uri concatenateMP4() {
        try {

            FileChannel fc1 = new FileInputStream(myVid1).getChannel();
            FileChannel fc2 = new FileInputStream(myVid2).getChannel();
            FileChannel fc3 = new FileInputStream(myVid3).getChannel();

            try {

                Movie[] inMovies = new Movie[]{
                    MovieCreator.build(fc1),
                    MovieCreator.build(fc2),
                    MovieCreator.build(fc3)
                };

                List<Track> videoTracks = new LinkedList<Track>();
                List<Track> audioTracks = new LinkedList<Track>();

                for (Movie m : inMovies) {
                    for (Track t : m.getTracks()) {
                        if (t.getHandler().equals("soun")) {
                            audioTracks.add(t);
                        }
                        if (t.getHandler().equals("vide")) {
                            videoTracks.add(t);
                        }
                    }
                }

                Movie result = new Movie();

                if (audioTracks.size() > 0) {
                    result.addTrack(new AppendTrack(audioTracks.toArray(new Track[audioTracks.size()])));
                }
                if (videoTracks.size() > 0) {
                    result.addTrack(new AppendTrack(videoTracks.toArray(new Track[videoTracks.size()])));
                }

                Container out = new DefaultMp4Builder().build(result);

                String fileNameString = fName+"_"+lName"_"org+System.currentTimeMillis()+".mp4";
                File aFile = new File(vidDir,fileNameString);

                FileChannel fc = new RandomAccessFile(aFile,"rw").getChannel();
                out.writeContainer(fc);
                fc.close();

                combinedVidUri = addVideo(aFile);

                return combinedVidUri;

            } catch (IOException e) {
                e.printStackTrace();
            }
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
        return null;
    }

I am running this code in an asyncTask so that when the vids are a little bit larger they do not tie up the UI thread. The following is the error that I am getting:

10-01 19:07:01.367  11805-12202/com.myapp.myappProject E/AndroidRuntime﹕ FATAL EXCEPTION: AsyncTask #1
        java.lang.RuntimeException: An error occured while executing doInBackground()
        at android.os.AsyncTask$3.done(AsyncTask.java:299)
        at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:273)
        at java.util.concurrent.FutureTask.setException(FutureTask.java:124)
        at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:307)
        at java.util.concurrent.FutureTask.run(FutureTask.java:137)
        at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
        at java.lang.Thread.run(Thread.java:856)
        Caused by: java.nio.BufferUnderflowException
        at java.nio.Buffer.checkGetBounds(Buffer.java:177)
        at java.nio.DirectByteBuffer.get(DirectByteBuffer.java:41)
        at java.nio.MappedByteBufferAdapter.get(MappedByteBufferAdapter.java:144)
        at java.nio.ByteBuffer.get(ByteBuffer.java:384)
        at java.nio.channels.Channels$OutputStreamChannel.write(Channels.java:345)
        at com.googlecode.mp4parser.AbstractBox.getBox(AbstractBox.java:163)
        at com.googlecode.mp4parser.authoring.tracks.AppendTrack.<init>(AppendTrack.java:52)
        at com.myapp.myappProject.Submit.concatenateMP4(Submit.java:142)
        at com.myapp.myappProject.Submit.access$000(Submit.java:71)
        at com.myapp.myappProject.Submit$StartUploadChain.doInBackground(Submit.java:245)
        at com.myapp.myappProject.Submit$StartUploadChain.doInBackground(Submit.java:236)
        at android.os.AsyncTask$2.call(AsyncTask.java:287)
        at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
        ... 5 more

I know the videos I am attempting to concatenate actually exist and I am fairly certain (both through the above output and through the use of Log statements) that it breaks as it goes to add a new track to the result variable. What am I doing wrong? The worst part is that I am testing on both a google nexus and a samsung galaxy tab. The nexus works, the galaxy throws the error.

Community
  • 1
  • 1
user2766642
  • 51
  • 1
  • 4
  • Never mind, I got things working! Will update as to how later. – user2766642 Oct 02 '13 at 14:14
  • Using this code example: [click me](https://code.google.com/p/mp4parser/source/browse/trunk/examples/src/main/java/com/googlecode/mp4parser/AppendExample.java) I implemented the class as in the example (using isoviewer-1.0-RC-26.jar) and it worked! – user2766642 Oct 03 '13 at 02:56

0 Answers0