我想创建一个将视频倒置的应用程序 - 翻转不旋转180.
我使用预览 - 矩阵应用了textureview取得了成功。
但是如何录制视频翻转?
SDK是api-16。
private boolean prepareVideoRecorder(){
mCamera = CameraHelper.getDefaultCameraInstance();
// We need to make sure that our preview and recording video size are supported by the
// camera. Query camera to find all the sizes and choose the optimal size given the
// dimensions of our preview surface.
Camera.Parameters parameters = mCamera.getParameters();
List<Camera.Size> mSupportedPreviewSizes = parameters.getSupportedPreviewSizes();
Camera.Size optimalSize = CameraHelper.getOptimalPreviewSize(mSupportedPreviewSizes,
mPreview.getWidth(), mPreview.getHeight());
// Use the same size for recording profile.
CamcorderProfile profile = CamcorderProfile.get(CamcorderProfile.QUALITY_HIGH);
profile.videoFrameWidth = optimalSize.width;
profile.videoFrameHeight = optimalSize.height;
Log.d("Tag", profile.videoFrameHeight + " : " + profile.videoFrameWidth);
// likewise for the camera object itself.
parameters.setPreviewSize(profile.videoFrameWidth, profile.videoFrameHeight);
mCamera.setParameters(parameters);
try {
// Requires API level 11+, For backward compatibility use {@link setPreviewDisplay}
// with {@link SurfaceView}
Matrix mx = new Matrix();
RectF viewRect = new RectF(0,0, mPreview.getWidth(), 960);
float centerX = viewRect.centerX();
float centerY = viewRect.centerY();
mx.postRotate(90, centerX, centerY);
mx.postScale(1f, -1.5f);
mx.postTranslate(0, 960);
mPreview.setTransform(mx);
mPreview.requestLayout();
mPreview.invalidate();
mCamera.setPreviewTexture(mPreview.getSurfaceTexture());
} catch (IOException e) {
Log.e(TAG, "Surface texture is unavailable or unsuitable" + e.getMessage());
return false;
}
mMediaRecorder = new MediaRecorder();
// Step 1: Unlock and set camera to MediaRecorder
mCamera.unlock();
mMediaRecorder.setCamera(mCamera);
// Step 2: Set sources
mMediaRecorder.setAudioSource(MediaRecorder.AudioSource.DEFAULT );
mMediaRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
mMediaRecorder.setOrientationHint(180);
// Step 3: Set a CamcorderProfile (requires API Level 8 or higher).
mMediaRecorder.setProfile(profile);
// Step 4: Set output file
//mMediaRecorder.setOutputFile(CameraHelper.getOutputMediaFile(
// CameraHelper.MEDIA_TYPE_VIDEO).toString());
mMediaRecorder.setOutputFile("mnt/extSdCard/11.mp4");
// Step 5: 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;
}