视频创作的图片和音频的安卓 [英] Video Creation with Images and Audio in Android
问题描述
我想创建于Android的视频与一些图像和音频文件。 我搜索了这一点,发现有用的库是 OpenCV的,javacv和ffmpeg的。 我使用的库和随后的过程中给的链接 - https://github.com/bytedeco/javacv
我想知道这个过程
- 是本机开发套件是必要的任务。是否有必要即使我们有 。所以我们的文件,因为我使用我说上面的资源达到任务 通过简单地把.so文件在 armeabi 在库目录下的文件夹中。
- 我创建的视频,但要求是该视频应与声音加入
- 声音已经被用户和图像被记录在运行时必须被来自位图 其也以在运行时被创建。
1)。请下载的驱动这个zip文件: https://drive.google.com/file/d/0B71R0Zw0m1zQM3RVOWNWM2poVHc/edit ?USP =共享
2)解压缩下载的zip,并把所有文件下同
赋予相同的给定库/ armeabi文件夹
3)在activty使用下面code
请输入follwing文件。
进口静态com.google code.javacv.cpp.opencv_highgui.cvLoadImage;
进口com.google code.javacv.cpp.av codeC;
进口com.google code.javacv.cpp.opencv_core.IplImage;
和实际code此处
新的AsyncTask<虚空,虚空,虚空>(){
ProgressDialog对话框;
在preExecute保护无效(){
对话框=新ProgressDialog(MainActivity.this);
dialog.setMessage(Genrating视频,请等待.........);
dialog.setCancelable(假);
dialog.show();
};
@覆盖
保护无效doInBackground(虚空......为arg0){
文件夹=环境
.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM);
字符串路径= folder.getAbsolutePath()+/摄像头;
ArrayList的<字符串>路径=(ArrayList的<字符串>)getListOfFiles(
路径,JPG);
FFmpegFrameRecorder记录=新FFmpegFrameRecorder(路径
+/+test.mp4,400,400);
将videoPath =路径+/+test.mp4;
尝试 {
//recorder.setVideo$c$cc(5);
recorder.setVideo codeC(AV codec.AV_ codeC_ID_MPEG4);
//recorder.setFormat("3gp);
recorder.setFormat(MP4);
recorder.setFrameRate(帧率);
recorder.setVideoBitrate(30);
的startTime = System.currentTimeMillis的();
recorder.start();
的for(int i = 0; I< paths.size();我++){
IplImage的形象= cvLoadImage(路径+/+ paths.get(一));
长T = 3000 *(System.currentTimeMillis的() - startTime时);
如果(T> recorder.getTimestamp()){
recorder.setTimestamp(T);
recorder.record(图像);
}
}
的System.out.println(总时间: - + recorder.getTimestamp());
recorder.stop();
}赶上(例外五){
e.printStackTrace();
}
返回null;
}
保护无效onPostExecute(无效的结果){
dialog.dismiss();
意向意图=新的意图(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.parse(将videoPath),视频/ MP4);
startActivity(意向);
Toast.makeText(MainActivity.this,完成,Toast.LENGTH_SHORT)
。显示();
};
}。执行();
请自由地问,如果您有任何疑问。
I want to create a video in Android with some images and an audio file. I searched for that and found useful libraries for that are opencv, javacv and ffmpeg. I used that libraries and followed the process give on the link - https://github.com/bytedeco/javacv
I want to know for the process
- Is Native Development Kit is necessary for the task. Is it necessary even if we have .so files with us, Since I achieved the task with using the resources I stated above by simply putting the .so files in the armeabi folder of the libs directory.
- I created the video but the requirement is that the video should be added with the sound
- Sound has to be recorded at run-time by the user and images has to be come from bitmaps which are also to be created at run-time.
1). Please download this zip file from drive: https://drive.google.com/file/d/0B71R0Zw0m1zQM3RVOWNWM2poVHc/edit?usp=sharing
2) unzip the downloaded zip and put all file same like given libs/armeabi folder given below
3) use below code in your activty
please import follwing file.
import static com.googlecode.javacv.cpp.opencv_highgui.cvLoadImage;
import com.googlecode.javacv.cpp.avcodec;
import com.googlecode.javacv.cpp.opencv_core.IplImage;
and actual code here
new AsyncTask<Void, Void, Void>() {
ProgressDialog dialog;
protected void onPreExecute() {
dialog = new ProgressDialog(MainActivity.this);
dialog.setMessage("Genrating video, Please wait.........");
dialog.setCancelable(false);
dialog.show();
};
@Override
protected Void doInBackground(Void... arg0) {
File folder = Environment
.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM);
String path = folder.getAbsolutePath() + "/Camera";
ArrayList<String> paths = (ArrayList<String>) getListOfFiles(
path, "jpg");
FFmpegFrameRecorder recorder = new FFmpegFrameRecorder(path
+ "/" + "test.mp4", 400, 400);
videoPath = path + "/" + "test.mp4";
try {
//recorder.setVideoCodec(5);
recorder.setVideoCodec(avcodec.AV_CODEC_ID_MPEG4);
//recorder.setFormat("3gp");
recorder.setFormat("mp4");
recorder.setFrameRate(frameRate);
recorder.setVideoBitrate(30);
startTime = System.currentTimeMillis();
recorder.start();
for (int i = 0; i <paths.size(); i++) {
IplImage image = cvLoadImage(path + "/" + paths.get(i));
long t = 3000 * (System.currentTimeMillis() - startTime);
if (t > recorder.getTimestamp()) {
recorder.setTimestamp(t);
recorder.record(image);
}
}
System.out.println("Total Time:- " + recorder.getTimestamp());
recorder.stop();
} 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/mp4");
startActivity(intent);
Toast.makeText(MainActivity.this, "Done", Toast.LENGTH_SHORT)
.show();
};
}.execute();
please free to asked if you have any query.
这篇关于视频创作的图片和音频的安卓的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!