報錯代碼:
final MediaFormat format = MediaFormat.createVideoFormat(MIME_TYPE, mWidth, mHeight);
mMediaCodec.configure(format, null, null,MediaCodec.CONFIGURE_FLAG_ENCODE);
原因:傳入放入寬高中高不是2的倍數,換言之,是個單數。
解決:
int formatWidth = mWidth;
int formatHeight = mHeight;
if ((formatWidth & 1) == 1) {
formatWidth--;
}
if ((formatHeight & 1) == 1) {
formatHeight--;
}
final MediaFormat format = MediaFormat.createVideoFormat(MIME_TYPE, formatWidth, formatHeight);