2

これは私が使用するコードです:

public void stopRecording() throws Exception, com.googlecode.javacv.FrameRecorder.Exception {

    runAudioThread = false;

    if (recorder != null && recording) {
        recording = false;
        Log.v(LOG_TAG, "Finishing recording, calling stop and release on recorder");
        try {
            recorder.stop();
            recorder.release();
        } catch (FFmpegFrameRecorder.Exception e) {
            e.printStackTrace();
        }

    }
    Log.i(LOG_TAG, "filename = " + ffmpeg_link);
    if (i > 0) {
        Log.i(LOG_TAG, "!!!!!!!!!WILL CONCATENATE");
        FrameGrabber grabber1 = new FFmpegFrameGrabber(pathStart + "/JavaCV/stream0.mp4");
        grabber1.start();
        Log.i(LOG_TAG, "graber1.start");
        FrameGrabber grabber2 = new FFmpegFrameGrabber(pathStart + "/JavaCV/stream1.mp4");
        grabber2.start();
        Log.i(LOG_TAG, "graber2.start");
        FrameRecorder recorder2 = new FFmpegFrameRecorder(pathStart + "/JavaCV/output.mp4", grabber1.getImageWidth(), grabber1.getImageHeight(), grabber1.getAudioChannels());
        recorder2.setFrameRate(grabber1.getFrameRate());
        recorder2.setSampleFormat(grabber1.getSampleFormat());
        recorder2.setSampleRate(grabber1.getSampleRate());
        Log.i(LOG_TAG, "Recorder.start");
        recorder2.start();
        Frame frame;
        int j = 0;
        while ((frame = grabber1.grabFrame()) != null) {
            j++;
            recorder2.record(frame);
            Log.i(LOG_TAG, "while1 nr:" + j + "Frame number: " + grabber1.getFrameNumber());
        }
        Log.i(LOG_TAG, "after while1");
        while ((frame = grabber2.grabFrame()) != null) {
            recorder2.record(frame);
            Log.i(LOG_TAG, "while2");
        }
        Log.i(LOG_TAG, "Recorder.stop");
        recorder2.stop();
        grabber2.stop();
        grabber1.stop();
        Log.i(LOG_TAG, "end concatenate");
    }
    i++;
    ffmpeg_link = pathStart + "/JavaCV/stream" + i + ".mp4";
    Log.i(LOG_TAG, "next filename = " + ffmpeg_link);
}

それはうまく機能し、ビデオをマージすることができます.私が持っている唯一の問題は、2番目のビデオの音が聞こえないことです. 2番目のビデオにもオーディオチャンネルを配置するにはどうすればよいですか?

4

1 に答える 1