MediaRecorder setOrientationHint

为什么80%的码农都做不了架构师?>>>   hot3.png

在使用MediaRecorder录制时,发现 setOrientationHint 并不会实际旋转改变视频流。 只是在视频文件中增加旋转参数。视频播放器需要根据这个旋转参数进行旋转播放。 部分视频播放器会选择忽略这个参数,如window media player。

Note that some video players may choose
     to ignore the compostion matrix in a video during playback.

    /**
     * Sets the orientation hint for output video playback.
     * This method should be called before prepare(). This method will not
     * trigger the source video frame to rotate during video recording, but to
     * add a composition matrix containing the rotation angle in the output
     * video if the output format is OutputFormat.THREE_GPP or
     * OutputFormat.MPEG_4 so that a video player can choose the proper
     * orientation for playback. Note that some video players may choose
     * to ignore the compostion matrix in a video during playback.
     *
     * @param degrees the angle to be rotated clockwise in degrees.
     * The supported angles are 0, 90, 180, and 270 degrees.
     * @throws IllegalArgumentException if the angle is not supported.
     *
     */
    public void setOrientationHint(int degrees) {
        if (degrees != 0   &&
            degrees != 90  &&
            degrees != 180 &&
            degrees != 270) {
            throw new IllegalArgumentException("Unsupported angle: " + degrees);
        }
        setParameter("video-param-rotation-angle-degrees=" + degrees);
    }

其他资料 https://blog.csdn.net/veilling/article/details/52421930

横屏角度为0:



Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'D:\hengping_0.mp4':
  Metadata:
    major_brand     : mp42
    minor_version   : 0
    compatible_brands: isommp42
    creation_time   : 2016-08-29 02:57:07
  Duration: 00:00:21.50, start: 0.000000, bitrate: 14198 kb/s
    Stream #0:0(eng): Video: h264 (Baseline) (avc1 / 0x31637661), yuv420p, 1280x
720, 13987 kb/s, SAR 1:1 DAR 16:9, 29.89 fps, 29.92 tbr, 90k tbn, 180k tbc (defa
ult)
    Metadata:
      creation_time   : 2016-08-29 02:57:07
      handler_name    : VideoHandle
    Stream #0:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, flt
p, 96 kb/s (default)
    Metadata:
      creation_time   : 2016-08-29 02:57:07
      handler_name    : SoundHandle

竖屏角度为90:



Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'D:\shuping_90.mp4':
  Metadata:
    major_brand     : mp42
    minor_version   : 0
    compatible_brands: isommp42
    creation_time   : 2016-09-01 08:21:46
  Duration: 00:00:16.32, start: 0.000000, bitrate: 2045 kb/s
    Stream #0:0(eng): Video: h264 (Baseline) (avc1 / 0x31637661), yuv420p, 720x4
80, 1954 kb/s, SAR 1:1 DAR 3:2, 20.57 fps, 29.97 tbr, 90k tbn, 180k tbc (default
)
    Metadata:
      rotate          : 90
      creation_time   : 2016-09-01 08:21:46
      handler_name    : VideoHandle
    Side data:
      displaymatrix: rotation of -90.00 degrees
    Stream #0:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, flt
p, 95 kb/s (default)
    Metadata:
      creation_time   : 2016-09-01 08:21:46
      handler_name    : SoundHandle

转载于:https://my.oschina.net/zdglf/blog/3057875

你可能感兴趣的:(MediaRecorder setOrientationHint)