I'm working on social mobile app. It have option to record video for profile. The issue with my recorder is that it mirror the actual video. I know it is default behaviour, but want it work like sanpchat.
Preview
After recording and playback
Here is my code
// 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, cameraId, 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;
}
I want it should be same as preview in playback. Sanpchat is already doing the same, thanks in advance.
If you need to remove the flip effect and start again, click on the little star icon on the video, select the effect, and click Remove.
On Android, go to the Video option. Press the Capture icon to begin recording. Then double-tap anywhere on the screen to flip the camera. Once you are done recording, tap on the Save icon to download the video.
Use Record Video Background App Open the Google Play Store app and search for the Record Video Background app. Install the app and open it. Provide the necessary access privileges to the app. Tap on the Record button in the center to start recording the video in the background even if the screen is turned off.
You have set the orientation for the Front facing camera to 270 here,
setOrientationHint = 270 ;
Instead I would suggest to set the orientation to 180 degree like below,
setOrientationHint = (info.orientation - 180 + 360) % 360;
This will also change the entire video file.
You can use a TextureView, documentation here and apply a transform of -1 scale on the X axis, function here
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With