从Android的前摄像头录制视频时颠倒淡化 [英] Video plays upside down when recorded from Front Camera in Android

查看:980
本文介绍了从Android的前摄像头录制视频时颠倒淡化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在做Android的视频摄像头应用程序。它应该有背部和前置摄像头记录的能力。我与后置摄像头完成,一切都很好。但是,当我有前置摄像头录制,视频播放倒挂。我必须发挥记录在我的应用程序本身的视频。我使用VideoView,如何设置方向,或使其正常播放?在默认媒体播放器还打倒挂播放时视频。试图发送视频到iPhone和检查,但仍然发挥着倒挂。我已经向setOrientationHint但MediaRecorder无解的。

我的所有code是类似于<一个href=\"https://github.com/marakana/VideoCaptureDemo/tree/master/src/com/marakana/android/videocapturedemo\"相对=nofollow>中,我已经做了定制agargenta的视频捕捉演示。

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

  this.mediaRecorder =新MediaRecorder();
        this.mediaRecorder.setCamera(this.mCamera);
        this.mediaRecorder.setAudioSource(MediaRecorder.AudioSource.CAMCORDER);
        this.mediaRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
        如果(Build.VERSION.SDK_INT&下; = 10){
            CamcorderProfile camcorderProfile = CamcorderProfile
                    获得(CamcorderProfile.QUALITY_HIGH);
            camcorderProfile.videoFrameWidth = 320;
            camcorderProfile.videoFrameHeight = 480;
            // camcorderProfile.videoFrameRate = 15;
            camcorderProfile.video codeC = MediaRecorder.VideoEn coder.H264;
            // camcorderProfile.audio codeC = MediaRecorder.AudioEn coder.DEFAULT;
            camcorderProfile.fileFormat = MediaRecorder.OutputFormat.MPEG_4;
            this.mediaRecorder.setProfile(camcorderProfile);
mediaRecorder.setOrientationHint(90);
        }其他{
            如果(tgbSwitchCamera.isChecked()){
                mediaRecorder
                        .setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
                // mediaRecorder.setVideoSize(320,480);
                mediaRecorder.setAudioEn codeR(MediaRecorder.AudioEn coder.AAC);
                mediaRecorder.setVideoEn codeR(MediaRecorder.VideoEn coder.H264);
                CameraInfo cameraInfo =新CameraInfo();
                Camera.getCameraInfo(CameraInfo.CAMERA_FACING_FRONT,cameraInfo);
                旋转=(cameraInfo.orientation - 180 + 360)%360;
                mediaRecorder.setOrientationHint(旋转);            }其他{
                CamcorderProfile camcorderProfile = CamcorderProfile
                        获得(CamcorderProfile.QUALITY_LOW);
                camcorderProfile.videoFrameWidth = 640;
                camcorderProfile.videoFrameHeight = 480;
                camcorderProfile.video codeC = MediaRecorder.VideoEn coder.H264;
                // camcorderProfile.audio codeC =
                // MediaRecorder.AudioEn coder.DEFAULT;
                camcorderProfile.fileFormat = MediaRecorder.OutputFormat.MPEG_4;
                this.mediaRecorder.setProfile(camcorderProfile);
mediaRecorder.setOrientationHint(90);
            }
        }
        this.mediaRecorder.setOutputFile(this.initFile()getAbsolutePath());
        this.mediaRecorder.set previewDisplay(M preview.getHolder()getSurface());        尝试{
            this.mediaRecorder prepare()。            //开始实际拍摄
            //抛出IllegalStateException异常如果不是prepared
            处理程序H =新的处理程序();
            h.postDelayed(新的Runnable(){                @覆盖
                公共无效的run(){
                    this.mediaRecorder.start();
                    pgv.setStart(真);
                    pgv.invalidate();
                    CountDownTimer CDT =新CountDownTimer(5000,1000){                        @覆盖
                        公共无效onTick(长millisUntilFinished){
                        }                        @覆盖
                        公共无效onFinish(){
                            如果(isRecording){
                                handler.removeMessages(停止);
                                STO precording();
                            }
                        }
                    };
                    cdt.start();
                }
            },1000);            //将表明我们正在录制启用停止按钮
        }赶上(例外五){
            Toast.makeText(这一点,不能录,Toast.LENGTH_SHORT).show();
            e.printStackTrace();
            this.releaseMediaRecorder();
        }


解决方案

这条线将专门旋转视频180度:

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

除非你有这样做的,我不是看到一个原因,这就是为什么你的视频是上下颠倒。

I am doing android Video Camera Application. It should have capability of recording with back and front camera. I am done with back camera and everything is fine. But when I record with front camera, video plays upside down. I have to play the videos recorded in my application itself. I am using VideoView, How to set orientation or make it play correctly?. Video when played in default media player also playing upside down. Tried sending the video to iPhone and checked but still it plays upside down. I have setOrientationHint to MediaRecorder but no solution.

All My Code is similar to agargenta's Video Capture Demo in which I have done customization.

Issues seems to be strange and I am struck.

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();
        }

解决方案

This line will specifically rotate the video 180 degrees:

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

Unless you have a reason for doing this that I'm not seeing, that's why your video is upside-down.

这篇关于从Android的前摄像头录制视频时颠倒淡化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆