1

我正在做安卓摄像机应用程序。它应该具有使用后置和前置摄像头录制的能力。我完成了后置摄像头,一切都很好。但是当我用前置摄像头录制时,视频播放颠倒了。我必须播放在我的应用程序本身中录制的视频。我正在使用 VideoView,如何设置方向或使其正确播放?在默认媒体播放器中播放的视频也会倒置播放。尝试将视频发送到 iPhone 并检查,但它仍然播放颠倒。我有 setOrientationHint 到 MediaRecorder 但没有解决方案。

All My Code 类似于agargenta 的 Video Capture Demo,我在其中进行了自定义。

问题似乎很奇怪,我很震惊。

this.mediaRecorder = new MediaRecorder();
        this.mediaRecorder.setCamera(this.mCamera);
        this.mediaRecorder.setAudioSource(MediaRecorder.AudioSource.CAMCORDER);
        this.mediaRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
        if (Build.VERSION.SDK_INT <= 10) {
            CamcorderProfile camcorderProfile = CamcorderProfile
                    .get(CamcorderProfile.QUALITY_HIGH);
            camcorderProfile.videoFrameWidth = 320;
            camcorderProfile.videoFrameHeight = 480;
            // camcorderProfile.videoFrameRate = 15;
            camcorderProfile.videoCodec = MediaRecorder.VideoEncoder.H264;
            // camcorderProfile.audioCodec = MediaRecorder.AudioEncoder.DEFAULT;
            camcorderProfile.fileFormat = MediaRecorder.OutputFormat.MPEG_4;
            this.mediaRecorder.setProfile(camcorderProfile);
mediaRecorder.setOrientationHint(90);
        } else {
            if (tgbSwitchCamera.isChecked()) {
                mediaRecorder
                        .setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
                // mediaRecorder.setVideoSize(320, 480);
                mediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AAC);
                mediaRecorder.setVideoEncoder(MediaRecorder.VideoEncoder.H264);
                CameraInfo cameraInfo = new CameraInfo();
                Camera.getCameraInfo(CameraInfo.CAMERA_FACING_FRONT, cameraInfo);
                rotation = (cameraInfo.orientation - 180 + 360) % 360;
                mediaRecorder.setOrientationHint(rotation);

            } else {
                CamcorderProfile camcorderProfile = CamcorderProfile
                        .get(CamcorderProfile.QUALITY_LOW);
                camcorderProfile.videoFrameWidth = 640;
                camcorderProfile.videoFrameHeight = 480;
                camcorderProfile.videoCodec = MediaRecorder.VideoEncoder.H264;
                // camcorderProfile.audioCodec =
                // MediaRecorder.AudioEncoder.DEFAULT;
                camcorderProfile.fileFormat = MediaRecorder.OutputFormat.MPEG_4;
                this.mediaRecorder.setProfile(camcorderProfile);
mediaRecorder.setOrientationHint(90);
            }
        }
        this.mediaRecorder.setOutputFile(this.initFile().getAbsolutePath());
        this.mediaRecorder.setPreviewDisplay(mPreview.getHolder().getSurface());

        try {
            this.mediaRecorder.prepare();

            // start the actual recording
            // throws IllegalStateException if not prepared
            Handler h = new Handler();
            h.postDelayed(new Runnable() {

                @Override
                public void run() {
                    this.mediaRecorder.start();
                    pgv.setStart(true);
                    pgv.invalidate();
                    CountDownTimer cdt = new CountDownTimer(5000, 1000) {

                        @Override
                        public void onTick(long millisUntilFinished) {
                        }

                        @Override
                        public void onFinish() {
                            if (isRecording) {
                                handler.removeMessages(STOP);
                                stopRecording();
                            }
                        }
                    };
                    cdt.start();
                }
            }, 1000);

            // enable the stop button by indicating that we are recording
        } catch (Exception e) {
            Toast.makeText(this, "cannot record", Toast.LENGTH_SHORT).show();
            e.printStackTrace();
            this.releaseMediaRecorder();
        }
4

1 回答 1

8

此行将专门将视频旋转 180 度:

rotation = (cameraInfo.orientation - 180 + 360) % 360;

除非您有我看不到的这样做的理由,否则这就是您的视频颠倒的原因。

于 2013-07-29T15:01:41.617 回答