MediaRecorder API and Preview Image of Recorded video

Viewed 12

I perfectly record a refreshing bitmap as video file by MediaRecorder API with below code pieces. However when i browse my video file there is no preview image for the file. Is there any method to select a frame or embed an image in order to easily identify the file by preview image?

Initialization of MediaRecorder object

recorder = new MediaRecorder();
recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
recorder.setVideoSource(MediaRecorder.VideoSource.SURFACE);
recorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
recorder.setVideoEncodingBitRate(recordBitrate);
recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AAC);
recorder.setVideoEncoder(MediaRecorder.VideoEncoder.H264);
recorder.setVideoSize(resultRGB.width(), resultRGB.height());

SimpleDateFormat sdf = new SimpleDateFormat("yyMMddHHmmss");
Date d = new Date();
String fileName = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM).getAbsolutePath() + "/face/" + "video_" + sdf.format(d) + ".mp4";
recorder.setOutputFile(fileName);

try
{
   recorder.prepare();
   surface = recorder.getSurface();
   recorder.start();
}
catch (Exception e)
{
   recordStatus = false;
   Log.e("Face", "MediaRecorder start failed");
}

Loop Code piece which constantly change bitmap

if (surface != null)
{
   Canvas canvas = surface.lockCanvas(null);
   canvas.drawBitmap(bm, 0, 0, new Paint());
   surface.unlockCanvasAndPost(canvas);
}
1 Answers

The problem solved after setting video frame rate while constructing MediaRecorder.

recorder.setVideoFrameRate(30);
Related