Friday, 31 May 2019

CamcorderProfile.videoCodec returning wrong value

According to the docs, you can use CamcorderProfile to get the devices default video codec format, then set it to MediaRecorder, like this:

CamcorderProfile mProfile = CamcorderProfile.get(cameraId, CamcorderProfile.QUALITY_HIGH);

//

mMediaRecorder.setVideoEncoder(mProfile.videoCodec);

But for some reason it is returning the wrong format.

I'm using the CameraView library and in the FullVideoRecorder class the following is defined:

switch (mResult.getVideoCodec()) {
    case H_263: mMediaRecorder.setVideoEncoder(MediaRecorder.VideoEncoder.H263); break;
    case H_264: mMediaRecorder.setVideoEncoder(MediaRecorder.VideoEncoder.H264); break;
    case DEVICE_DEFAULT: mMediaRecorder.setVideoEncoder(mProfile.videoCodec); break;
} 

The device I'm experiencing the issue with works perfectly fine when I set the video encoder to H_263, but for some reason, when I set it to default it crashes - In this case default means that CamcorderProfile should select the devices default video codec format.


My question:

Is there any reason why CamcorderProfile.videoCodec would return the wrong value and how can this be resolved?


Edit - adding more information

I implemented the following to make sure if CamcoderProfile is returning the wrong value:

//In onCreate
CamcorderProfile camcorderProfile = CamcorderProfile.get(CamcorderProfile.QUALITY_HIGH);

//getVideoCodec method below
String profileCodec = getVideoCodec(camcorderProfile.videoCodec);    

//Log the result I get
Log.e("Video Codec =", profileCodec);


private String getVideoCodec(int videoCodec){
    switch(videoCodec){
        case MediaRecorder.VideoEncoder.H263:
            return "H263";
        case MediaRecorder.VideoEncoder.H264:
            return "H264";
        case MediaRecorder.VideoEncoder.MPEG_4_SP:
            return "MPEG_4_SP";
        case MediaRecorder.VideoEncoder.DEFAULT:
            return "DEFAULT";
        default:
            return "unknown";
    }
}

In my log I get Video Codec = H264, but this is incorrect, it should return Video Codec = H263.


If I pass the following to MediaRecorder, it works perfectly:

mMediaRecorder.setVideoEncoder(MediaRecorder.VideoEncoder.H263);

but not when I set any of the following:

mMediaRecorder.setVideoEncoder(MediaRecorder.VideoEncoder.H264);
mMediaRecorder.setVideoEncoder(MediaRecorder.VideoEncoder.DEFAULT);
mMediaRecorder.setVideoEncoder(mProfile.videoCodec);



from CamcorderProfile.videoCodec returning wrong value

No comments:

Post a Comment