如何录制自定义宽高比的视频?

时间:2018-08-14 16:00:30

标签: android android-camera2 android-mediarecorder

在我的项目中,我使用具有自定义预览高度(Camera_VIEW_HEIGHT_PERCENT)的Camera2 api,是通过修改AutoFitTextureView类实现的,您可以在下面看到该修改:

@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    super.onMeasure(widthMeasureSpec, widthMeasureSpec);
    int width = MeasureSpec.getSize(widthMeasureSpec);
    int height = MeasureSpec.getSize(heightMeasureSpec);
    int margin = (height - Math.round(height * CAMERA_VIEW_HEIGHT_PERCENT)) / 2;

    if(!mWithMargin) {
        mWithMargin = true;
        ViewGroup.MarginLayoutParams margins = ViewGroup.MarginLayoutParams.class.cast(getLayoutParams());
        margins.topMargin = -margin;
        margins.bottomMargin = -margin;
        margins.leftMargin = 0;
        margins.rightMargin = 0;
        setLayoutParams(margins);
    }

    if (0 == mRatioWidth || 0 == mRatioHeight) {
        setMeasuredDimension(width, height);
    } else {
        if (width < height) {
            setMeasuredDimension(width, width * mRatioHeight / mRatioWidth);
        } else {
            setMeasuredDimension(height * mRatioWidth / mRatioHeight, height);
        }
    }
}

但是,我还需要以相同的分辨率录制视频,我尝试将mMediaRecorder和缓冲区大小更改为视图大小,但是出了点问题。当我按下“记录”按钮时,它会显示下一条错误消息:

CameraAccessException: CAMERA_ERROR (3): submitRequestList - cannot use a surface that wasn't configured

如果我停止记录,我的应用程序将崩溃。

该怎么做?

0 个答案:

没有答案