我使用ffmpeg,javacv成功将图像转换为android中的视频 现在我想在视频上添加背景音乐。 下面的代码将图像转换为视频但无法找到音频
public void imagevideo(ArrayList<String> links)
{
Log.d("Received",""+links);
iplimage = new opencv_core.IplImage[links.size()];
for (int j = 0; j < links.size(); j++)
{
System.out.println(" j " + "Inise Loop"+links.get(j).toString());
iplimage[j]=cvLoadImage(links.get(j));
}
这里是获取图像数组的长度 Log.d(&#34;长度&#34;&#34;&#34 + iplimage.length); 框架框架; File videopath = new File(Environment.getExternalStorageDirectory()。toString()+&#34; / test&#34;); videopath.mkdirs();
String audioFile = Environment.getExternalStorageDirectory().getAbsolutePath()+"/susic.mp3";
try {
FFmpegFrameGrabber audioFrames = FFmpegFrameGrabber.createDefault(audioFile);
FFmpegFrameRecorder recorder = new FFmpegFrameRecorder(Environment.getExternalStorageDirectory().toString()+"/test/video.mp4",400,400,audioFrames.getAudioChannels());
Log.d("Enter in Try","FF");
Log.d("Start Recorder","");
Log.d("Length","Sound Grab");
audioFrames.start();
recorder.setFrameRate(30);
recorder.setVideoCodec(avcodec.AV_CODEC_ID_MPEG4);
recorder.setVideoBitrate(9000);
recorder.setFormat("mp4");
recorder.setAudioChannels(2);
recorder.setSampleRate(44100);
recorder.setVideoQuality(0); // maximum quality
recorder.start();
Frame frame=null;
Log.d("Length",""+iplimage.length);
for (int i=0;i< iplimage.length;i++)
{
frame=audioFrames.grabFrame();
long t = 9000 * (System.currentTimeMillis());
if (t > recorder.getTimestamp()) {
recorder.setTimestamp(t);
recorder.record(iplimage[i]);
recorder.record(frame);
}
}
recorder.stop();
}