尽管我是纵向录制的,但横向视频播放

Posted

技术标签:

【中文标题】尽管我是纵向录制的,但横向视频播放【英文标题】:Video play in landscape although i recorded in portrait 【发布时间】:2013-04-29 17:23:40 【问题描述】:

正如标题所说,我有这个代码来准备我的录音机:

private boolean prepareMediaRecorder()
    myCamera = getCameraInstance();

    Camera.Parameters p = myCamera.getParameters();

    p.set("orientation", "landscape");
    p.set("rotation", 90);
    myCamera.setParameters(p);

    myCamera.setDisplayOrientation(90);

    myCamera.unlock();
    mediaRecorder = new MediaRecorder();
    mediaRecorder.setCamera(myCamera);

    mediaRecorder.setAudiosource(MediaRecorder.AudioSource.CAMCORDER);
    mediaRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);

    mediaRecorder.setProfile(CamcorderProfile.get(CamcorderProfile.QUALITY_HIGH));

    File tempFile = new File(Environment.getExternalStorageDirectory(), "/rec/temp/video_" + String.valueOf(videoCount) + ".mp4");
    mediaRecorder.setOutputFile(tempFile.getPath());
    mediaRecorder.setMaxDuration(12500); // Set max duration 11 sec.
    mediaRecorder.setMaxFileSize(7000000); // Set max file size 7M

    mediaRecorder.setPreviewDisplay(myCameraSurfaceView.getHolder().getSurface());


    try 
        mediaRecorder.prepare();
     catch (IllegalStateException e) 
        releaseMediaRecorder();
        return false;
     catch (IOException e) 
        releaseMediaRecorder();
        return false;
    
    return true;


我在我的表面视图中有:

@Override
    public void surfaceChanged(SurfaceHolder holder, int format, int weight,
            int height) 
        // If your preview can change or rotate, take care of those events here.
        // Make sure to stop the preview before resizing or reformatting it.

        if (mHolder.getSurface() == null)
          // preview surface does not exist
          return;
        

        // stop preview before making changes
        try 
            mCamera.stopPreview();
         catch (Exception e)
          // ignore: tried to stop a non-existent preview
        

        // make any resize, rotate or reformatting changes here

        // start preview with new settings
        try 

            myCamera.setDisplayOrientation(90);

            mCamera.startPreview();

         catch (Exception e)
        
    

这是唯一使用相机的两个地方(旋转)... 录制时一切都很好,但是当我播放该视频时,它是横向的。谁能告诉我为什么以及如何解决这个问题?

【问题讨论】:

您是否尝试过将相机设置为纵向而不是像您在此处所做的那样横向"p.set("orientation", "landscape");" 【参考方案1】:

使用 setOrientationHint(int degree) http://developer.android.com/reference/android/media/MediaRecorder.html#setOrientationHint(int)

mediaRecorder.setOrientationHint(90); (后置摄像头 90,前置摄像头 270) 在 mediaRecorder.prepare() 之前调用它;

【讨论】:

但这只是将合成矩阵设置为选定的值,大多数玩家会忽略该值。

以上是关于尽管我是纵向录制的,但横向视频播放的主要内容,如果未能解决你的问题,请参考以下文章

Android TV 中的 ExoPlayer 以纵向模式而不是横向模式播放视频

iphone - 强制 MPMoviePlayerController 以横向模式播放视频

横向和纵向播放视频

检测以纵向或横向全屏播放的视频

如何在仅纵向应用程序中使用 MPMovieViewController 播放横向视频

Android 视频横向播放