这是我使用的代码:
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);
}
效果很好,它设法合并视频,我唯一的问题是它没有第二个视频的声音。我怎样才能将音频通道放在第二个视频上?
答案 0 :(得分:4)
runAudioThread = false;
这行是将audiothread设为false,这就是为什么第二个视频没有声音。