使用MediaRecorder录制时,水平“条形”而不是视频

时间:2015-05-21 13:18:46

标签: android camera mediarecorder

主题A:横条

Horizontal Bars on Video

这很奇怪。视频记录和声音很好,但这些条形代表我的手。好像我正在看一个带肋的耐热玻璃碗:

主题B:

Ribbed Pyrex Bowl

我在三星Galaxy Note 10.1上使用前置相机(API 16)进行测试。一些说明:

  • 当我使用背面相机录制时,它记录正​​常。
  • 当我使用标准相机中的前置摄像头录制时 应用程序,它工作正常。
  • 当我在Samsung Galaxy S4(API 21)上运行相同的代码时, 后置和前置摄像头都能正常工作。

我使用CamcorderProfile选择适当的MediaRecorder设置。这是我的代码:

@TargetApi(Build.VERSION_CODES.HONEYCOMB)
private boolean prepareVideoRecorder() {
    // Get screen width and height for supported video sizes
    Display display = getWindowManager().getDefaultDisplay();
    int width, height;

    if (Build.VERSION.SDK_INT < 13) {
        width = display.getWidth();
        height = display.getHeight();
    } else {
        Point size = new Point();
        display.getSize(size);
        width = size.x;
        height = size.y;
    }

    // Check and set the highest quality available recording profile of the camera.
    int frontCamera = Camera.CameraInfo.CAMERA_FACING_FRONT;
    CamcorderProfile profile = null;

    if (CamcorderProfile.hasProfile(frontCamera, CamcorderProfile.QUALITY_1080P))
        profile = CamcorderProfile.get(frontCamera, CamcorderProfile.QUALITY_1080P);
    else if (CamcorderProfile.hasProfile(frontCamera, CamcorderProfile.QUALITY_720P))
        profile = CamcorderProfile.get(frontCamera, CamcorderProfile.QUALITY_720P);
    else if (CamcorderProfile.hasProfile(frontCamera, CamcorderProfile.QUALITY_480P))
        profile = CamcorderProfile.get(frontCamera, CamcorderProfile.QUALITY_480P);
    else if (CamcorderProfile.hasProfile(frontCamera, CamcorderProfile.QUALITY_HIGH))
        profile = CamcorderProfile.get(frontCamera, CamcorderProfile.QUALITY_HIGH);

    mCamera = CameraHelper.getDefaultFrontFacingCameraInstance();

    // Need to make sure that our recording video size is supported by the camera.
    // Query camera to find all sizes and choose the optimal size given the dimensions of screen.
    Camera.Parameters parameters = mCamera.getParameters();
    List<Camera.Size> mSupportedVideoSizes = parameters.getSupportedVideoSizes();
    Camera.Size optimalSize = CameraHelper.getOptimalRecordingSize(mSupportedVideoSizes,
            width, height);

    // link camera to preview surface
    try {
        mCamera.setPreviewDisplay(mPreview.getHolder());
    } catch (IOException e) {
        Log.e(TAG, "Surface text is unavailable or unsuitable for preview" + e.getMessage());
        return false;
    }

    // Unlock the camera to allow the Media Recorder to own it
    mCamera.unlock();

    // Create and assign the Camera to the Media Recorder
    mMediaRecorder = new MediaRecorder();
    mMediaRecorder.setCamera(mCamera);

    // Set Sources
    mMediaRecorder.setAudioSource(MediaRecorder.AudioSource.CAMCORDER);
    mMediaRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);

    if (profile != null) {
        profile.videoFrameWidth = optimalSize.width;
        profile.videoFrameHeight = optimalSize.height;
        mMediaRecorder.setProfile(profile);
    }

    // Specify the output file
    mMediaRecorder.setOutputFile(CameraHelper.getOutputMediaFile(
            CameraHelper.MEDIA_TYPE_VIDEO).toString());

    // Prepare configured MediaRecorder
    try {
        mMediaRecorder.prepare();
    } catch (IllegalStateException e) {
        Log.d(TAG, "IllegalStateException preparing MediaRecorder: " + e.getMessage());
        releaseMediaRecorder();
        return false;
    } catch (IOException e) {
        Log.d(TAG, "IOException preparing MediaRecorder: " + e.getMessage());
        releaseMediaRecorder();
        return false;
    }
    return true;
}

我尝试绕过CamcorderProfile并尝试every MediaRecorder.VideoEncoder encoder available。文件格式为.mp4,我不相信这是问题,因为设备上的标准Camera应用程序输出.mp4。有什么想法吗?

0 个答案:

没有答案