我正在研究社交移动应用.它可以选择录制个人资料视频.我的刻录机的问题是它反映了实际的视频.我知道这是默认行为,但希望它像sanpchat一样工作.
预习
录制和播放后
这是我的代码
// return camera instance when activity open first time private Camera getCameraInstance() { // TODO Auto-generated method stub releaseCamera(); releaseMediaRecorder(); Camera c = null; try { cameraId = findFrontFacingCamera(); if (cameraId < 0) { cameraId = findBackFacingCamera(); } c = Camera.open(cameraId); // setCameraDisplayOrientation(this,cameraId,c); //setCameraDisplayOrientation(this,c); c.setDisplayOrientation(90); } catch (Exception e) { // Camera is not available (in use or does not exist) } return c; // returns null if camera is unavailable } // return __cameraPreview Id 1 to open front camera private int findFrontFacingCamera() { int cameraId = -1; // Search for the front facing camera int numberOfCameras = Camera.getNumberOfCameras(); for (int i = 0; i < numberOfCameras; i++) { Camera.CameraInfo info = new Camera.CameraInfo(); Camera.getCameraInfo(i,info); if (info.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) { cameraId = i; setOrientationHint = 270 ; cameraFront = true; break; } } return cameraId; } // prepare and start recording private boolean prepareMediaRecorder() { mediaRecorder = new MediaRecorder(); try { myCamera.unlock(); } catch (Exception e) { e.printStackTrace(); } mediaRecorder.setCamera(myCamera); mediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC); mediaRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA); //mediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4); if (cameraPreview.getVideoSize() != null) { mediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4); mediaRecorder.setOutputFile(saveUrl); mediaRecorder.setVideoEncodingBitRate(10000000); mediaRecorder.setVideoFrameRate(30); mediaRecorder.setVideoSize(cameraPreview.getVideoSize().width,cameraPreview.getVideoSize().height); mediaRecorder.setVideoEncoder(MediaRecorder.VideoEncoder.H264); mediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AAC); } else { CamcorderProfile cp = CamcorderProfile.get(cameraId,CamcorderProfile.QUALITY_HIGH); mediaRecorder.setProfile(cp); } Log.e(TAG,"Video profile CamcorderProfile.QUALITY_HIGH: " + "cp.quality:" + cp.quality + ",cp.videoFrameWidth:" + cp.videoFrameWidth + ",cp.videoFrameHeight:" + cp.videoFrameHeight); mediaRecorder.setMaxDuration(MAX_VIDEO_LENGTH); mediaRecorder.setOrientationHint(setOrientationHint); try { mediaRecorder.prepare(); } catch (IllegalStateException | IOException e) { e.printStackTrace(); releaseMediaRecorder(); return false; } mediaRecorder.start(); return true; }
我希望它应该与播放中的预览相同. Sanpchat已经做了同样的事情,提前感谢.
解决方法
您已将前置摄像头的方向设置为270,
setOrientationHint = 270 ;
相反,我建议将方向设置为180度,如下所示,
setOrientationHint = (info.orientation - 180 + 360) % 360;
这也将改变整个视频文件.