hi i really need help in this issue, i'm extracting video frames and with the extracted frames i'm trying to create a video using JAVACV and run it on android version 4.2.1 it create the video but can't play it, when i try a drawable images and convert it to bitmaps it works and play the video , but when i use the extracted frames it doesn't work.
HERE IS MY CODE:
/* this method is responsible for retrieve all the video Frames it's parameters the path of the video and it's duration */
public static void getVideoFrame(String FD, long duration) throws Exception {
FrameRecorder recorder = new FFmpegFrameRecorder("storage/sdcard0/DCIM/video5.mp4", 640, 480);
recorder.setVideoBitrate(1);
recorder.setVideoCodec(AV_CODEC_ID_MPEG4);
recorder.setPixelFormat(AV_PIX_FMT_YUV420P);
recorder.setFrameRate(2);
recorder.start();
MediaMetadataRetriever retriever = new MediaMetadataRetriever();
try {
retriever.setDataSource(FD); // set video source
/* for loop on video duartion in each time w increment(duration/#of frames we should get)*/
for (int i = 0; i <= duration; i += ((duration-1) /100))
{
Bitmap b = retriever.getFrameAtTime(i*1000,retriever.OPTION_CLOSEST); // retrieve a bitmap in (i*1000) position
// Bitmap converted=convert(b,Config.ARGB_8888);
// convert each bitmap to ARGB_8888 configuration
Bitmap maskBitmap = Bitmap.createBitmap( b.getWidth(), b.getHeight(), Bitmap.Config.ARGB_8888 );
Canvas c = new Canvas();
c.setBitmap(maskBitmap);
Paint p = new Paint();
c.drawBitmap(b,0,0,p);
b.recycle();
IplImage imagei = IplImage.create(maskBitmap.getWidth(),maskBitmap.getHeight(),IPL_DEPTH_8U, 4);
Config s= maskBitmap.getConfig();
Log.d("configgggggggggg", s.toString());
maskBitmap.copyPixelsToBuffer(imagei.getByteBuffer());
images.add(imagei);
Frames.add(b);
// image.setImageBitmap(Frames.get(5));
}
for (int i = 0; i <images.size(); i++) {
// cvSetZero(imagei);
// cvPutText(imagei, "#" + i, cvPoint(320, 240), font, CvScalar.WHITE);
recorder.record(images.get(i));
}
recorder.stop();
} catch (IllegalArgumentException ex) {
ex.printStackTrace();
System.out.println("IllegalArgumentException: " + ex.toString());
} catch (RuntimeException ex) {
System.out.println("RunTimeException: " + ex.toString());
ex.printStackTrace();
} finally {
try {
retriever.release();
} catch (RuntimeException ex) {
}
}
}
0 comments:
Post a Comment