Question

hy everyone i am trying to append two videos in android using mp4parser, but the problem is that the resultant video is of 00:00 duration although it occupies the size of video1 + video2 both the videos are captured from the same back cam of same handset with exactly same encoding so encoding isn't any problem. i've already had a look at the samples referred by the mp4parser official site and it's almost the same code but there seems to be something else thanks in advance here is my code

private void appendVideos() throws IOException
    {
        String f1 = Environment.getExternalStorageDirectory() + "/video1.mp4";
        String f2 = Environment.getExternalStorageDirectory()+ "/video2.mp4";

        Movie[] inMovies;

        inMovies = new Movie[]
                {
                MovieCreator.build(f1),
                MovieCreator.build(f2),
                };


        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);

        RandomAccessFile ram = new RandomAccessFile(String.format(Environment.getExternalStorageDirectory() + "/output.mp4"), "rw");
        FileChannel fc = ram.getChannel();
        out.writeContainer(fc);
        ram.close();
        fc.close();
        Toast.makeText(getApplicationContext(), "success", Toast.LENGTH_SHORT).show();
    }
Was it helpful?

Solution

Its working fine with me.

Just do this one change your code will work fine.

Replace the isoparser-1.0-RC-37.jar With isoparser-1.0-RC-27.jar in your lib folder.

Download isoparser-1.0-RC-27.jar file from below link. http://grepcode.com/snapshot/repo1.maven.org/maven2/com.googlecode.mp4parser/isoparser/1.0-RC-27

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top