0

我正在通过 Android MediaRecorder 创建视频..
这是我添加视频的代码,
音频总是比视频长....
视频在最后停留 3 - 5 秒,而音频继续播放。

private void doAppend(String _firstVideox, String _secondVideox,
            String _newName) {
        try {


            FileInputStream fis1 = new FileInputStream(_firstVideox);
            FileInputStream fis2 = new FileInputStream(_secondVideox);

            Movie[] inMovies = new Movie[] {
                    MovieCreator.build(fis1.getChannel()),
                    MovieCreator.build(fis2.getChannel()) };

            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()])));
            }

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

            String filename = _newName;
            lastAppendOut = filename;

            FileOutputStream fos = new FileOutputStream(filename);
            FileChannel fco = fos.getChannel();

            fco.position(0);
            out.getBox(fco);
            fco.close();
            fos.close();
            fis1.close();
            fis2.close();

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

请检查一下并帮助我,我该怎么办。

4

1 回答 1

0

It was not the problem of JavaCpp i suppose,
When we make video using MediaRecorder in android device, the audio and video are not exactly the same...
Audio is bit larger i.e. 0.1s to 0.25s
So when we append the videos using JavaCpp which at the end bring together the audio video stream, first appending them seperately gives a huge difference.
In my case i appended 30 to 40 videos and sometimes video audio difference went to 14 seconds, which was very distrubing...
So another approach i used was to trim every video from the end (approx 0.5s), that makes audio video stream equal.
Here you can find what i did.

I hope i helped you people.

于 2014-10-29T07:37:40.367 回答