Thomas
Thomas

Reputation: 2941

Android: recorded video seems *distorted*

I'm trying to record video from the Camera using the MediaRecorder. Here's a code snippet

snip..


  mr.setAudioSource( MediaRecorder.AudioSource.MIC );
  mr.setVideoSource( MediaRecorder.VideoSource.CAMERA);
  mr.setOutputFormat( MediaRecorder.OutputFormat.THREE_GPP );
  mr.setAudioEncoder( MediaRecorder.AudioEncoder.AMR_NB );
  mr.setVideoEncoder( MediaRecorder.VideoEncoder.MPEG_4_SP );
  mr.setVideoSize( 200, 200 );
  mr.setVideoFrameRate( 15 );
..snap

Code executes on a MileStone/Droid, non-empty output file will be created. But when I try to view the video, it looks like this:

alt text

My first thoughts were about some sort of encoding error, so I tried every possible OutputFormat/VideoEncoder combination, with no effetcs on the result.

LogCat shows the following error CameraInput: Unsupported parameter(x-pvmf/media-input-node/cap-config-interface;valtype=key_specific_value)

But I can't figure out, what I may have set wrong. I used camera.getParameters(), set the preview size with the returned params and then pushed them back using camera.setParameters()...

Worked thru every piece of sample code I could find, but still found no solution.

Does anyone have any ideas ?

Upvotes: 2

Views: 2195

Answers (4)

Mayank Mehta
Mayank Mehta

Reputation: 699

To avoid distortion in recorded video ( I have seen this on Galaxy S3) make sure you set camera parameter preview size and mediarecorder videosize to same height and width.

To get supported camera preview size:

Camera.Parameters parameters = camera.getParameters();

List<Camera.Size> list = parameters.getSupportedPreviewSizes();

parameters.setPreviewSize(list.get(X).width, list.get(X).height); 
// If you set Width and Height not supported by device you will get exception


// MediaRecorder object mMediaRecoder

mMediaRecoder.setVideoSize(list.get(X).width, list.get(X).height);

Upvotes: 1

user963566
user963566

Reputation: 21

you must set the correct setVideoSize( x, y) function. you must call the function which give you the size options , and choose from that list

Upvotes: 2

shaheshang
shaheshang

Reputation: 11

when camera open,

    Camera.Parameters p = mCamera.getParameters();
    p.setPreviewSize(mSur.getWidth(), mSur.getHeight());
    mCamera.setParameters(p);

and when you prepareRecord

            mCamera.unlock();
    if (mRecorder == null) {
        mRecorder = new MediaRecorder();
    } else {
        mRecorder.reset();  
    }
    mNextRecordFileName = getOneFileName();
    mRecorder.setCamera(mCamera);
    mRecorder.setVideoSource(mVideoSource);   
    mRecorder.setAudioSource(mAudioSource);  
    mRecorder.setPreviewDisplay(mSur.getHolder().getSurface());
    mRecorder.setOutputFormat(mVideoFormat);    

    //设置在setEncoder之前才有效,如果不设置,htc会崩溃掉
    mRecorder.setVideoSize(this.mSur.getWidth(), mSur.getHeight());
    Log.i(TAG, this.mSur.getHolder().getSurfaceFrame().height()+"gao");
    Log.i(TAG, this.mSur.getHolder().getSurfaceFrame().width()+"kuan");
    Log.i(TAG, "宽"+this.mSur.getWidth()+"高"+mSur.getHeight());

    mRecorder.setVideoEncoder(mVideoEncoder);   
    mRecorder.setAudioEncoder(mAudioEncoder);
    mRecorder.setOutputFile(mNextRecordFileName);

hope it can help you

Upvotes: 1

vjuliano
vjuliano

Reputation: 1503

Hey, I know you posted this a while ago and I doubt your still looking for an answer but I thought this might help someone else out.

I think your problem is mr.setVideoSize( 200, 200 );

I doubt the phones camera supports a 1X1 capture resolution. It is better to use something like mr.setVideoSize(Camcorder.get(Camcorder.QUALITY_LOW).videoFrameWidth,Camcorder.get(Camcorder.QUALITY_LOW).videoFrameHeight);

That will ensure that the resolution is supported by the camera. Also make sure your preview resolution matches your camera resolution, or that can cause the same problem. I know it happens to me if I have my preview set to QUALITY_HIGH and my camera to QUALITY_LOW

Upvotes: 0

Related Questions