MediaRecorder video capturing in portrait mode

后端 未结 2 1205
你的背包
你的背包 2021-02-08 23:33

I\'m try to make custom video app. Iwork using settings in manifest 2.2 only (API 8).

All goes well but I don\'t understand why portrait mode video does

2条回答
  •  囚心锁ツ
    2021-02-09 00:24

    Found it ! Indeed, you can change the preview, you can tag the video, but there's no way to actually change the video... (maybe a speed issue or something)

    camera.setDisplayOrientation(90);
    

    To rotate the preview, then

    recorder.setOrientationHint(90);
    

    To tag the video as having a 90° rotation, then the phone will automatically rotate it when reading.

    So all you have to do is

                camera = Camera.open();
            //Set preview with a 90° ortientation
            camera.setDisplayOrientation(90);
            camera.unlock();
    
            holder = getHolder();
            holder.addCallback(this);
            holder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
    
            recorder = new MediaRecorder();
            recorder.setCamera(camera);
            recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
            recorder.setVideoSource(MediaRecorder.VideoSource.DEFAULT);
            recorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
            recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
            recorder.setVideoEncoder(MediaRecorder.VideoEncoder.MPEG_4_SP);
            recorder.setOutputFile(getVideoFolder()+rnd.nextString()+".mp4");
            recorder.setPreviewDisplay(holder.getSurface());
            //Tags the video with a 90° angle in order to tell the phone how to display it
            recorder.setOrientationHint(90);
    
            if (recorder != null) {
                try {
                    recorder.prepare();
                } catch (IllegalStateException e) {
                    Log.e("IllegalStateException", e.toString());
                } catch (IOException e) {
                    Log.e("IOException", e.toString());
                }
            }
    
            recorder.start();
    

    Hope it helps ;-)

提交回复
热议问题