在Android中使用FFMPEG合并多个视频时的音轨?

时间:2016-04-23 01:45:11

标签: android c++ video ffmpeg javacv

Android中的视频处理存在问题。

要合并多个视频,我现在正在使用ffmpeg c ++库和JavaCV。

这是我的代码:

protected Void doInBackground(String... params) {
    String firstVideo = params[0];
    String secondVideo = params[1];
    String outPutVideo = params[2];

    try {
        FrameGrabber grabber1 = new FFmpegFrameGrabber(firstVideo);
        grabber1.start();
        FrameGrabber grabber2 = new FFmpegFrameGrabber(secondVideo);
        grabber2.start();
        FrameRecorder recorder2 = new FFmpegFrameRecorder(outPutVideo, grabber2.getImageWidth(),
                grabber2.getImageHeight(), grabber1.getAudioChannels());

        recorder2.setVideoCodec(grabber2.getVideoCodec());
        recorder2.setFrameRate(grabber2.getFrameRate());
        recorder2.setSampleFormat(grabber2.getSampleFormat());
        recorder2.setSampleRate(grabber2.getSampleRate());
        recorder2.setAudioChannels(2);
        recorder2.start();
        Frame frame;
        int j = 0;

        while ((frame = grabber1.grabFrame()) != null) {
            j++;
            recorder2.record(frame);
        }
        while ((frame = grabber2.grabFrame()) != null) {
            recorder2.record(frame);
        }
        recorder2.stop();
        grabber2.stop();
        grabber1.stop();
    } catch (Exception e) {
        e.printStackTrace();
        success = false;
    }
    return null;
} 

第一个视频没有声音,第二个视频有声音。

第二个视频的音频从结果视频的开始开始。

我尝试了几个小时的搜索,但找不到解决方案。如果您有经验,请告诉我!!!

0 个答案:

没有答案