首页 > 其他 > 详细

MediaCodec.configure Picture Width(1080) or Height(2163) invalid, should N*2

时间:2021-05-06 15:14:35      阅读:29      评论:0      收藏:0      [点我收藏+]

异常如下:

 Picture Width(1080) or Height(2163) invalid, should N*2

报错的地方是MediaCodec.configure

mMediaCodec.configure(mMediaFormat, null, null, MediaCodec.CONFIGURE_FLAG_ENCODE);

引起这个崩溃的原因正如错误描述的那样,意思是:视频的宽和高必须是2的证书倍,及width=N*2,height=N*2

所以解决办法也非常简单,只需要重新设置视频的宽高,并做一下变形使其成为2的整数倍就OK了。

可以进行如下设置:

 int formatWidth = width;
        int formatHeight = height;
        if ((formatWidth & 1) == 1) {
            formatWidth--;
        }
        if ((formatHeight & 1) == 1) {
            formatHeight--;
        }

使用的时候直接使用formatWidth和formatHeight,然后你就会发现以上的异常就会被修复。

MediaCodec.configure Picture Width(1080) or Height(2163) invalid, should N*2

原文:https://www.cnblogs.com/tony-yang-flutter/p/14734737.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!