本文转自:http://blog.csdn.net/holo_easydarwin/article/details/51147379java
最初在作EasyPusher手机直播的时候遇到过一个问题:手机竖屏推送直播画面到EasyDarwin而后经过播放器播放视频画面就会逆时针旋转90度,如图:git

手机横屏的时候不会旋转,这个问题思路其实很简单,在推送给服务器以前把图片数据旋转90度以后就能够了,而后就作了一次顺时针旋转的,结果画面变成以下样子:github

很明显图片顺时针旋转了90度,可是还不如不旋转!我就想固然的觉得旋转的算法出错了,而后开始寻求谷歌度娘,然并卵,而后就本身开始了解学习YUV420SP、YUV420P,而且本身写旋转算法,结果仍是这样。其实着就有个结论了,旋转算法没问题!那是哪儿除了问题了呢?一次聊天提到宽和高是否是有问题,一语点醒梦中人。我在编码的时候使用MediaCodec,编码的时候设置宽为640高480:算法
<code class="language-java hljs has-numbering" style="display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: 'Source Code Pro', monospace;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;">mediaFormat = MediaFormat.createVideoFormat(<span class="hljs-string" style="margin: 0px; padding: 0px; color: rgb(0, 136, 0); box-sizing: border-box;">"video/avc"</span>, width,height);</code><ul class="pre-numbering" style="margin: 0px; padding: 6px 0px 40px; box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="margin: 0px; padding: 0px 5px; box-sizing: border-box;">1</li></ul>
而旋转90度以后宽和高就颠倒了啊,再这样编码确定有问题,因而在将编码器的宽和高颠倒:服务器
<code class="language-java hljs has-numbering" style="display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: 'Source Code Pro', monospace;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;">mediaFormat = MediaFormat.createVideoFormat(<span class="hljs-string" style="margin: 0px; padding: 0px; color: rgb(0, 136, 0); box-sizing: border-box;">"video/avc"</span>, height, width);</code><ul class="pre-numbering" style="margin: 0px; padding: 6px 0px 40px; box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="margin: 0px; padding: 0px 5px; box-sizing: border-box;">1</li></ul>
此次果真出现奇迹了,画面终于正常了:ide

其实就是简单的颠倒一下width和height的位置,这个问题困扰了好几天,终于解决了学习
关于代码可见:https://github.com/EasyDarwin/EasyPusher编码
获取更多信息
邮件:support@easydarwin.orgspa
WEB:www.EasyDarwin.org.net
Copyright © EasyDarwin.org 2012-2016
