Android 从javacv图像序列创建视频
为了从android中的图像序列创建视频,我使用了javacv 0.6库,但我遇到了以下问题: 它通常适用于htc Sensation(安卓4.0.1,处理器类型armv7)和htc Desire(安卓2.3.3,处理器类型arm7)手机,但不适用于htc Wildfire (安卓2.3.5,处理器类型armv6)手机,尤其是在这部分代码中出现故障Android 从javacv图像序列创建视频,android,ffmpeg,javacv,Android,Ffmpeg,Javacv,为了从android中的图像序列创建视频,我使用了javacv 0.6库,但我遇到了以下问题: 它通常适用于htc Sensation(安卓4.0.1,处理器类型armv7)和htc Desire(安卓2.3.3,处理器类型arm7)手机,但不适用于htc Wildfire (安卓2.3.5,处理器类型armv6)手机,尤其是在这部分代码中出现故障 FFmpegFrameRecorder recorder = new FFmpegFrameRecorder(videoFilePath,
FFmpegFrameRecorder recorder = new FFmpegFrameRecorder(videoFilePath,
TalkingPhotoConstants.VIDEO_FRAME_WIDTH,TalkingPhotoConstants.VIDEO_FRAME_HEIGHT);
在所附的代码中
public class MovieCreator extends AsyncTask<String, Void, Boolean> {
private opencv_core.IplImage[] iplimage;
private String audioFilePath;
private ProgressDialog progressDialog;
private Context context;
private List<TalkFrame> frames;
public MovieCreator(Context context, opencv_core.IplImage[] images, String audioFilePath,
List<TalkFrame> frames) {
this.context = context;
this.iplimage = images;
this.audioFilePath = audioFilePath;
this.frames = frames;
}
private String createMovie() {
String videoName = TalkingPhotoConstants.TMP_VIDEO_NAME;
String path = TalkingPhotoConstants.RESOURCES_TMP_FOLDER;
String videoFilePath = path + videoName;
String finalVideoName = TalkingPhotoConstants.FINAL_VIDEO_NAME +
System.currentTimeMillis() + ".mp4";
String finalVideoPath = TalkingPhotoConstants.RESOURCES_FOLDER + finalVideoName;
try {
FFmpegFrameRecorder recorder = new FFmpegFrameRecorder(videoFilePath,
TalkingPhotoConstants.VIDEO_FRAME_WIDTH,TalkingPhotoConstants.VIDEO_FRAME_HEIGHT);
//int frameCount = iplimage.length;
int frameCount = frames.size();
recorder.setAudioCodec(AV_CODEC_ID_AMR_NB);
recorder.setVideoCodec(AV_CODEC_ID_MPEG4);
recorder.setVideoBitrate(120000);
recorder.setFrameRate(TalkingPhotoConstants.VIDEO_FRAME_RATE);
recorder.setPixelFormat(AV_PIX_FMT_YUV420P);
recorder.setFormat("mp4");
recorder.start();
for (int i = 0; i < frameCount; i++) {
TalkFrame currentFrame = frames.get(i);
long duration = currentFrame.getDuration();
opencv_core.IplImage iplImage = cvLoadImage(currentFrame.getImageName());
for (int j = 0; j < TalkingPhotoConstants.VIDEO_FRAME_RATE * duration; j++) {
recorder.record(iplImage);
}
}
recorder.stop();
mergeAudioAndVideo(videoFilePath, audioFilePath, finalVideoPath);
} catch (Exception e) {
Log.e("problem", "problem", e);
finalVideoName = "";
}
return finalVideoName;
}
private boolean mergeAudioAndVideo(String videoPath, String audioPath, String outPut)
throws Exception {
boolean isCreated = true;
File file = new File(videoPath);
if (!file.exists()) {
return false;
}
FrameGrabber videoGrabber = new FFmpegFrameGrabber(videoPath);
FrameGrabber audioGrabber = new FFmpegFrameGrabber(audioPath);
videoGrabber.start();
audioGrabber.start();
FrameRecorder recorder = new FFmpegFrameRecorder(outPut,
videoGrabber.getImageWidth(), videoGrabber.getImageHeight(),
audioGrabber.getAudioChannels());
recorder.setFrameRate(videoGrabber.getFrameRate());
recorder.start();
Frame videoFrame = null, audioFrame = null;
while ((audioFrame = audioGrabber.grabFrame()) != null) {
videoFrame = videoGrabber.grabFrame();
if (videoFrame != null) {
recorder.record(videoFrame);
}
recorder.record(audioFrame);
}
recorder.stop();
videoGrabber.stop();
audioGrabber.stop();
return isCreated;
}
@Override
protected Boolean doInBackground(String... params) {
String fileName = createMovie();
boolean result = fileName.isEmpty();
if (!result) {
VideoDAO videoDAO = new VideoDAO(context);
videoDAO.open();
videoDAO.createVideo(fileName);
videoDAO.close();
}
//Utils.cleanTmpDir();
return result;
}
@Override
protected void onPreExecute() {
progressDialog = new ProgressDialog(context);
progressDialog.setTitle("Processing...");
progressDialog.setMessage("Please wait.");
progressDialog.setCancelable(false);
progressDialog.setIndeterminate(true);
progressDialog.show();
}
@Override
protected void onPostExecute(Boolean result) {
if (progressDialog != null) {
progressDialog.dismiss();
}
}
公共类MovieCreator扩展异步任务{
私有opencv_core.IplImage[]IplImage;
私有字符串音频文件路径;
私有进程对话;
私人语境;
私有列表框架;
公共MovieCreator(上下文,opencv_core.IplImage[]图像,字符串音频文件路径,
列表框){
this.context=上下文;
this.iplimage=图像;
this.audioFilePath=audioFilePath;
这个。帧=帧;
}
私有字符串createMovie(){
字符串videoName=TalkingPhotoConstants.TMP\u视频\u名称;
字符串路径=TalkingPhotoConstants.RESOURCES\u TMP\u文件夹;
字符串videoFilePath=路径+视频名称;
String finalVideoName=talking photoconstants.FINAL\u VIDEO\u NAME+
System.currentTimeMillis()+“.mp4”;
字符串finalVideoPath=talkingpotoconstants.RESOURCES\u FOLDER+finalVideoName;
试一试{
FFmpegFrameRecorder=新的FFmpegFrameRecorder(视频文件路径,
通话光电转换。视频帧宽度,通话光电转换。视频帧高度);
//int frameCount=iplimage.length;
int frameCount=frames.size();
录音机。设置音频编解码器(AV_编解码器_ID_AMR_NB);
录像机。设置视频编解码器(AV_编解码器_ID_MPEG4);
记录器。设置视频比特率(120000);
录像机.设置帧速率(通话光电转换.视频帧速率);
recorder.setPixelFormat(AV_PIX_FMT_YUV420P);
记录器.setFormat(“mp4”);
recorder.start();
对于(int i=0;i
}
也不例外
1.我怎样才能修好它
2.我有一个版本的问题与设备的处理器类型有关
如果我是对的,我该怎么解决呢
提前感谢。JavaCV包含一些由Java调用的本机C代码。看起来您的版本是为ARMv7编译的,而不是为ARMv6编译的 为了让它正常工作,您需要重新编译JavaCV本机位,用于您想要定位的处理器(本例中为ARMv6)。一旦你这样做了,你会发现它工作正常 本机代码是一个难题,但对于这样的应用程序来说,它非常重要,因为它需要执行一些非常CPU密集的任务