0

I have one question,

When I use the aurio recording on my program, it works fine, but when i try the video recording, my .3gp file is empty (0 bytes).

Can you please tell me why?

Here is a part of my code for the video recording which does not work:

protected void startRecording() throws IOException 
{
    mrec = new MediaRecorder();  // Works well
    mrec.setVideoSource(MediaRecorder.VideoSource.CAMERA);
    mrec.setAudioSource(MediaRecorder.AudioSource.MIC); //Works well
    mrec.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4); //Works well with OutputFormat.THREE.GPP
    mrec.setVideoSize(100, 100);
    mrec.setVideoFrameRate(5);
    mrec.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB); // Works well
    mrec.setVideoEncoder(MediaRecorder.VideoEncoder.MPEG_4_SP);
    mrec.setOutputFile("/sdcard/test5.3gp");  //Works well with test5.mp4

    mrec.prepare(); // Works well for the audio recording
    mrec.start(); // Works well for the audio recording
}
Milos Cuculovic
  • 19,631
  • 51
  • 159
  • 265

2 Answers2

1

Video recording it turns out is not that simple.

First you will need to unlock the handle to the camera object and then set the camera to the recorder.

mCameraDev.unlock();
mRecorder.setCamera(mCameraDev);

Note: you will need to call the setCamera right after you call unlock and before you call any other recorder API's, else you will end up with a illegal state exception.

Next you will need to setup the preview display surface with the recorder. This basically acts like the video input to the recorder, i.e., any video data in the preview surface it is taken as input to the video recording.

mRecorder.setPreviewDisplay(mSurfaceHolder.getSurface());

If you need help on how to get the preview up on the camera, check this link.

Instead of setting formats individually, use the getProfile and setProfile API's on the recoder.

One last thing, the video resolution that is set to the recorder needs to be in sync with the resolution of the preview surface. If your preview surface is VGA then make sure you performing the recording with a VGA resolution.

bluefalcon
  • 4,225
  • 1
  • 32
  • 41
  • Thank you soooo much for those informations, they are very usefol for me... I have a litle problem with the SurfaceHolder. I am looking on the exemple but I can't do it working... Can you please hemp me? Thank you – Milos Cuculovic Dec 28 '11 at 10:09
  • Hi, ok, done, I am now able to record videos, great..... :-) Is there possibility to record it vithaut previewing? – Milos Cuculovic Dec 28 '11 at 10:57
  • Not sure, never tried it myself. Personally I find it easier to record if I can see what I am recording ;) – bluefalcon Dec 29 '11 at 05:05
0

It seems that for encoding (recording) video only H.263 codec is supported: http://developer.android.com/guide/appendix/media-formats.html

Peter Knego
  • 79,991
  • 11
  • 123
  • 154
  • thank you wor your answer Peter, but this is not resolving my problem... When i choose mrec.setVideoEncoder(MediaRecorder.VideoEncoder.H263); the problem is still there, my .3gp file is still empty. – Milos Cuculovic Dec 27 '11 at 16:22