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

Record video by from camera without mirror it like snap chat

我正在开发社交移动应用程序。它可以选择为个人资料录制视频。我的录像机的问题是它反映了实际的视频。我知道这是默认行为,但希望它像 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, 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 已经在做同样的事情了,在此先感谢。

您可以使用 TextureView,文档 here and apply a transform of -1 scale on the X axis, function here

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

setOrientationHint = 270 ;

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

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

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

最后我需要在 api 提交视频的那一边做这件事对我来说毫无用处。上传视频后,我使用 ffmpeg 垂直翻转它并在元数据中设置角度。这是这个的命令。

ffmpeg -i VIDEO_PATH -vf "vflip" -metadata:s:v rotate=180 DEST_PATH