以纵向模式预览捕获视频作为横向

时间:2017-02-14 10:27:43

标签: android camera surfaceview video-recording

我正在开发自定义录像机,我以纵向模式录制视频,录制视频后视频预览为横向视图。 Initialy i record video in portrait

After record video preview as landscape

我的代码

这里我使用表面视图。当我点击相机记录开始时第一次有按钮for caputure第二次当我开始点击它停止并继续下一个包含预览录制视频的活动

 public void startVideoRecord() {
    initrecorder();
    try {
        Thread.sleep(1000);
        mMediaRecorder.start();
        isRecordStart = true;

    } catch (Exception e) {
        e.printStackTrace();
    }
    flashmode.setEnabled(false);

}

public void stopVideoRecord() {
    try {
        if (mMediaRecorder != null) {
            mMediaRecorder.stop();
            mMediaRecorder.reset();
            mMediaRecorder.release();
            mMediaRecorder = null;
        }
        if (mCamera != null) {
            mCamera.stopPreview();
            mCamera.lock();
            mCamera.startPreview();
        }
        flashmode.setEnabled(true);
        params.setFlashMode(Camera.Parameters.FLASH_MODE_OFF);
        isRecordStart = false;
        lightson = false;
        startlayout.setVisibility(View.GONE);

        savelayout.setVisibility(View.GONE);


    } catch (RuntimeException stopException) {
    }

    Intent intent = new Intent(UnlVideoActivity.this, PreviewVideo.class);
    intent.putExtra("Video_Path", filepath);
    intent.putStringArrayListExtra("Term", terms);
    intent.putStringArrayListExtra("Term_Id", termId);
    startActivity(intent);
}

public void initrecorder() {
    try {
 mCamera.setParameters(parameters);
 CamcorderProfile cp = CamcorderProfile.
 get(CamcorderProfile.QUALITY_HIGH);
        Video_Size_Max_Width = cp.videoFrameWidth;
        Video_Size_Max_Height = cp.videoFrameHeight;
        int vframerate = cp.videoFrameRate;
        startcameraservice();
        mCamera.stopPreview();
        mCamera.unlock();
        if (mMediaRecorder == null)
            mMediaRecorder = new MediaRecorder();
        mMediaRecorder.setPreviewDisplay(mHolder.getSurface());

        mMediaRecorder.setCamera(mCamera);
            mMediaRecorder.setVideoSource
       (MediaRecorder.VideoSource.DEFAULT);
        mMediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
         mMediaRecorder.setOutputFormat
       (MediaRecorder.OutputFormat.MPEG_4);
        enviromentState = Environment.getExternalStorageState();
        File file = new   File(Environment.getExternalStoragePublicDirectory(unl_videos), VIDEO_PATH_NAME);
        if ((enviromentState == Environment.MEDIA_REMOVED) || (enviromentState == Environment.MEDIA_UNMOUNTED)) {
            Toast.makeText(getApplicationContext(), enviromentState, Toast.LENGTH_LONG).show();
        } else {
            Toast.makeText(getApplicationContext(), enviromentState, Toast.LENGTH_LONG).show();

            // "touch" the file
            if (!file.exists()) {
                File parent = file.getParentFile();
                if (parent != null)
                    if (!parent.exists())
                        if (!parent.mkdirs())
                            throw new IOException("Cannot create " + "parent directories for file: " + file);

                file.createNewFile();
            }
        }
  mMediaRecorder.setVideoSize(Video_Size_Max_Width, Video_Size_Max_Height);
        mMediaRecorder.setAudioEncodingBitRate(131072);
        mMediaRecorder.setAudioSamplingRate(44100);
        mMediaRecorder.setVideoEncodingBitRate(3567616);
        mMediaRecorder.setVideoEncoder(MediaRecorder.VideoEncoder.H264);
        mMediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AAC);
        mMediaRecorder.setVideoFrameRate(vframerate);
 mMediaRecorder.setOutputFile(file.getAbsolutePath());
        Toast.makeText(getApplicationContext(), "file location " + file.getAbsolutePath(), Toast.LENGTH_LONG)
                .show();
        filename = file.getName();
        filepath = file.getAbsolutePath();
    } catch (Exception e) {
        e.printStackTrace();
    }

    try {
        mMediaRecorder.prepare();
    } catch (Exception e) {
      e.printStackTrace();
    }
}

     private void startcameraservice() {
    PackageManager pm = getApplicationContext().getPackageManager();
    CameraInfo cinfo = new CameraInfo();
    if (mCamera == null) {
        if (pm.hasSystemFeature(PackageManager.FEATURE_CAMERA)) {
            mCamera = Camera.open(cinfo.CAMERA_FACING_BACK);
        }   
 elseif(pm.hasSystemFeature(PackageManager.FEATURE_CAMERA_FRONT)) {
            mCamera = Camera.open(cinfo.CAMERA_FACING_FRONT);
        } else {
        }
    }
}

0 个答案:

没有答案