Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

关于Android MediaCodec硬编码16位对齐的问题 #29

Open
MarkMjw opened this issue Aug 29, 2017 · 4 comments
Open

关于Android MediaCodec硬编码16位对齐的问题 #29

MarkMjw opened this issue Aug 29, 2017 · 4 comments

Comments

@MarkMjw
Copy link

MarkMjw commented Aug 29, 2017

前段时间我也遇到这个问题了,参考:https://stackoverflow.com/questions/28291204/something-about-stagefright-codec-input-format-in-android 解决了。

但现在遇到一个新问题:视频能正常编码出来,但是部分手机在视频右侧或底部出现一条绿纹,应该就是对齐增加的几个像素导致,不知道如何解决。

不知道是不是对齐的方式有问题,我的方式:
if (w % 16 > 0) {
w = (w / 16) * 16 + 16;
}
if (h % 16 > 0) {
h = (h / 16) * 16 + 16;
}

有遇到相同的情况吗?

@ragnraok
Copy link
Contributor

对齐之后,有没有在多出来的边缘补齐像素点?留白的话就会出现绿边了

@MarkMjw
Copy link
Author

MarkMjw commented Sep 1, 2017

@ragnraok 感谢回复!
又看了下官方文档,提到使用strideslice-height来确定buffer中的编码切片,我在MOTO X Pro(5.0.2)上试了下解码一段720p的视频MediaCodec解码输出的MediaFormat如下:

{mime=video/raw, crop-top=0, crop-right=719, slice-height=1280, color-format=2141391876, height=1280, width=720, what=1869968451, crop-bottom=1279, crop-left=0, stride=768}

因此,得到的对齐宽高应该是768x1280,而不是720x1280。我按照768x1280重新编码,视频图像正确,但是右边出现绿边,如果用720x1280编码,结果是花屏。说明我之前的对齐方式有问题,但是在其他设备上面遇到一个新的问题:这种方式拿到的分辨率有可能仍然不是16位对齐的,所以某些奇怪的机型又有问题,我又不得不再增加一层判断(PS:做Android遇到设备兼容性问题真特么累)。

最后:请教下关于绿边填充像素的实现原理,我的流程是:解码成YUV数据,然后重新编码。这个过程中如何实现补齐像素,烦请指教,多谢!

@ragnraok
Copy link
Contributor

ragnraok commented Sep 1, 2017

建议还是不要使用这个stride来作为宽高的标准,而是以你设定的宽高为基准,寻找最近的16位对齐的整数,然后在多出来的边缘补齐像素点之后,再送入编码器

@chongbo2013
Copy link

woca 这个问题,怎么来解决呢。贼麻烦

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants