我阅读了ffmpeg库的教程,将图像合并到音频文件中。
这看起来非常复杂,并且环境值出错也是空的。
我研究了很多,但没有找到任何解决方案。
在Android中有什么方法可以合并图像和音频文件来制作视频吗?
答案 0 :(得分:7)
我没有编译FFMPEG,只是我使用javacv for android并解决了我的问题,将音频和图像结合起来并将其作为视频文件。 脚步: 首先按照here提供的步骤操作,然后将以下代码放在您的活动中,并确保更改输入文件和输出文件的路径。
new AsyncTask<Void, Void, Void>() {
ProgressDialog dialog;
FFmpegFrameRecorder recorder;
protected void onPreExecute() {
dialog = new ProgressDialog(RecordActivity.this);
dialog.setMessage("Genrating video, Please wait.........");
dialog.setCancelable(false);
dialog.show();
};
@Override
protected Void doInBackground(Void... arg0) {
File folder = Environment.getExternalStorageDirectory();
String path = folder.getAbsolutePath() + "/DCIM/Camera";
// ArrayList<String> paths = (ArrayList<String>) getListOfFiles(path, "jpg");
long millis = System.currentTimeMillis();
videoPath = path + "/" + "test_sham_"+millis+".3gp";
try {
//audio grabber
FrameGrabber grabber2 = new FFmpegFrameGrabber(folder.getAbsolutePath()+"/Samsung/Music/Over_the_horizon.mp3");
//video grabber
FrameGrabber grabber1 = new FFmpegFrameGrabber(path+"/20140527_133034.jpg");
grabber1.start();
grabber2.start();
recorder = new FFmpegFrameRecorder(path
+ "/" + "test_sham_"+millis+".3gp", grabber1.getImageWidth(), grabber1.getImageHeight(),2);
//recorder.setVideoCodec(5);
recorder.setVideoCodec(avcodec.AV_CODEC_ID_MPEG4);
// recorder.setVideoCodec(avcodec.AV_CODEC_ID_MP4ALS);
recorder.setFormat("3gp");
// recorder.setFormat("mp4");
recorder.setFrameRate(frameRate);
recorder.setSampleRate(grabber2.getSampleRate());
recorder.setVideoBitrate(30);
startTime = System.currentTimeMillis();
recorder.start();
Frame frame1, frame2 = null;
while ((frame1 = grabber1.grabFrame()) != null ||
(frame2 = grabber2.grabFrame()) != null) {
recorder.record(frame1);
recorder.record(frame2);
}
recorder.stop();
grabber1.stop();
grabber2.stop();
System.out.println("Total Time:- " + recorder.getTimestamp());
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
protected void onPostExecute(Void result) {
dialog.dismiss();
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.parse(videoPath), "video/3gp");
startActivity(intent);
Toast.makeText(RecordActivity.this, "Done:::"+videoPath, Toast.LENGTH_SHORT)
.show();
};
}.execute();
答案 1 :(得分:0)
ffmpeg
未附带Android手机。你需要自己为android编译它并在设备上部署。
似乎有人已经完成了它,但它可能不适合专业用途:
https://play.google.com/store/apps/details?id=com.netcompss.ffmpeg4android