0

I'm trying to write video stream from my Galaxy Tab to server. according to this manual i should do something like this:

        frontCamera = getFrontCamera();
        if((socket!= null)&&(frontCamera!=null))
        {
            try {
                frontCamera.setPreviewDisplay(cameraPreview.getHolder());
            } catch (IOException e1) {
                // TODO Auto-generated catch block
                Log.e("","",e1);

            }
            frontCamera.startPreview();
            recorder =  new MediaRecorder();
            frontCamera.unlock();
            recorder.setCamera(frontCamera);
            recorder.setAudioSource(MediaRecorder.AudioSource.CAMCORDER);
            recorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
            recorder.setProfile(CamcorderProfile.get( CamcorderProfile.QUALITY_HIGH));
            pfd = ParcelFileDescriptor.fromSocket(socket);
            recorder.setOutputFile(pfd.getFileDescriptor());
            recorder.setPreviewDisplay(cameraPreview.getHolder().getSurface());
            try {
                recorder.prepare();
                recorder.start();
} catch (IllegalStateException e) {
                // TODO Auto-generated catch block
                Log.e("","",e);
            } catch (IOException e) {
                // TODO Auto-generated catch block
                Log.e("","",e);
            }

but all fails on step recorder.start(); with strange error

02-01 19:03:39.265: E/MediaRecorder(11922): start failed: -19

what does that mean and what should I do to start recorder?

UPD: Trouble happens because of my getFrontCamera method. when I replace it with camera.open() all works correct.

protected Camera getFrontCamera()
{
    Camera.CameraInfo inf = new Camera.CameraInfo();
    for(int i = 0; i< Camera.getNumberOfCameras(); i++)
    {

        Camera.getCameraInfo(i, inf);
        if(inf.facing==Camera.CameraInfo.CAMERA_FACING_FRONT)
        {
            return Camera.open(i);
        }
    }
    return null;
}

Upd2 - yes, explicit setting of format and encoders solved the trouble -

        recorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
        recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
        recorder.setVideoEncoder(MediaRecorder.VideoEncoder.MPEG_4_SP);

Maybe because of pre-build formats are for back camera... But strange anyway.

Raiv
  • 5,731
  • 1
  • 33
  • 51

4 Answers4

0

Have a look

And though it is streaming video, so that set -

recorder.setOutputFormat(8);
recorder.setOutputFile(socketFd);

Have fun.

Community
  • 1
  • 1
Suvam Roy
  • 1,282
  • 2
  • 11
  • 21
0

I've a hack here, extending media recorder class and removing super.setVideoFrameRate(rate) solves the problem for me.

Atul Kaushik
  • 5,181
  • 3
  • 29
  • 36
0

If you still want to use CamcorderProfile.QUALITY_HIGH with the front camera, you can use the following:

CamcorderProfile camcorderProfile = CamcorderProfile.get(currentCameraId, CamcorderProfile.QUALITY_HIGH);
recorder.setProfile(camcorderProfile);

where int currentCameraId is Camera.CameraInfo.CAMERA_FACING_BACK or ...FRONT

So the profile is indeed dependent on the camera (for high-end phones it appears to work fine without the distinction, since they all support 1080p by now, but low-end phones may crash otherwise)

Matthias
  • 808
  • 6
  • 10
0

I don't see output format setup, so try adding to recorder set up:

 recorder.setOutputFormat(MediaRecorder.OutputFormat.DEFAULT);
pmod
  • 10,450
  • 1
  • 37
  • 50
  • this is being done with recorder.setProfile(...) as far as I understand. – Raiv Feb 01 '12 at 15:40
  • Oh, I tracked down to that -19 is the value of NO_INIT and most probably returned from setupCameraSource when (*cameraSource)->initCheck() is not OK. – pmod Feb 01 '12 at 15:53
  • I had exactly the same problem with that mysterious error -19 on Nexus S on IC 4.0.4. So, what it worked for me was explicitly setting the frame rate to <15 FPS and video size to 320x240. – nifo Jun 09 '12 at 11:07
  • @nifo Were you ever able to record at higher than 15fps? I am using the galaxy nexus which claims to be able to record at 24fps, but it crashes in the same way when I try to go higher than 15. See http://stackoverflow.com/questions/11156509/can-i-record-android-video-at-more-than-15fps – Max Ehrlich Jul 05 '12 at 13:17