gpt4 book ai didi

android - 从没有镜像的相机录制视频,就像 snapchat

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:53:40 27 4
gpt4 key购买 nike

我正在开发社交移动应用程序。它可以选择为个人资料录制视频。我的录像机的问题是它反射(reflect)了实际的视频。我知道这是默认行为,但希望它像 sanpchat 一样工作。

预览

Video when preview

录制回放后

After recording and playback

这是我的代码

// 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;
}

我希望它应该与播放中的预览相同。 Sanpchat 已经在做同样的事情,在此先感谢。

最佳答案

您已在此处将前置摄像头的方向设置为 270,

setOrientationHint = 270 ;

相反,我建议将方向设置为 180 度,如下所示,

setOrientationHint = (info.orientation - 180 + 360) % 360;

这也会改变整个视频文件。

关于android - 从没有镜像的相机录制视频,就像 snapchat,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38931761/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com