android - Android:由于配置时的 IllegalArgumentException,无法实例化 MediaCodec
问题描述
我正在学习如何使用,MediaCodec
所以我正在做一个实验来了解它是如何工作的,现在我正在尝试创建一个编解码器,它将从设备的相机接收数据并将素材转码为不同的分辨率/比特率。
我正在尝试使用 设置一个MediaCodec
实例Surface
,但我未能对其进行配置。这些是我在Logcat
点击配置代码行时看到的错误:
2020-01-03 11:22:01.769 25735-25735/com.oscar.vtech.multistreamtest E/libc: Access denied finding property "ro.kirin.product.platform"
2020-01-03 11:22:01.769 25735-25735/com.oscar.vtech.multistreamtest E/HwExtendedCodec: mime: video/avc matching compontent failed!
2020-01-03 11:22:01.782 25735-25918/com.oscar.vtech.multistreamtest E/ACodec: [OMX.hisi.video.encoder.avc] failed to set output port definition parameters.
2020-01-03 11:22:01.782 25735-25918/com.oscar.vtech.multistreamtest E/ACodec: [OMX.hisi.video.encoder.avc] configureCodec returning error -22
2020-01-03 11:22:01.782 25735-25918/com.oscar.vtech.multistreamtest E/ACodec: signalError(omxError 0x80001001, internalError -22)
2020-01-03 11:22:01.782 25735-25917/com.oscar.vtech.multistreamtest E/MediaCodec: Codec reported err 0xffffffea, actionCode 0, while in state 3
2020-01-03 11:22:01.785 25735-25735/com.oscar.vtech.multistreamtest E/MediaCodec: configure failed with err 0xffffffea, resetting...
2020-01-03 11:22:01.802 25735-25735/com.oscar.vtech.multistreamtest E/MainActivity: Unable to start recording: java.lang.IllegalArgumentException
实例化MediaCodec
和配置它的代码是这样的:
public class VideoEncoder {
private static final String TAG = VideoEncoder.class.getSimpleName();
private static final String DEFAULT_MIME_TYPE = MediaFormat.MIMETYPE_VIDEO_AVC; // H.264 Advanced Video Coding
private static final int DEFAULT_COLOR_FORMAT = MediaCodecInfo.CodecCapabilities.COLOR_FormatYUV420Planar;
private static final int DEFAULT_FRAME_RATE = 30;
private static final int DEFAULT_FRAME_INTERVAL = 3;
private MediaCodec mediaCodec;
private Surface inputSurface;
public VideoEncoder(int width, int height, int bitrate) throws IOException {
MediaFormat mediaFormat = MediaFormat.createVideoFormat(DEFAULT_MIME_TYPE, width, height);
mediaFormat.setInteger(MediaFormat.KEY_COLOR_FORMAT, DEFAULT_COLOR_FORMAT);
mediaFormat.setInteger(MediaFormat.KEY_BIT_RATE, bitrate);
mediaFormat.setInteger(MediaFormat.KEY_FRAME_RATE, DEFAULT_FRAME_RATE);
mediaFormat.setInteger(MediaFormat.KEY_I_FRAME_INTERVAL, DEFAULT_FRAME_INTERVAL);
Log.d(TAG, String.format("mediaFormat: %s", mediaFormat));
this.mediaCodec = MediaCodec.createEncoderByType(DEFAULT_MIME_TYPE);
this.mediaCodec.configure(mediaFormat, null, null, MediaCodec.CONFIGURE_FLAG_ENCODE);
this.inputSurface = this.mediaCodec.createInputSurface();
this.mediaCodec.start();
}
public Surface getInputSurface() {
return inputSurface;
}
}
这是设置的值的调试日志mediaFormat
:
color-format=19, i-frame-interval=3, mime=video/avc, width=842, bitrate=2000, frame-rate=30, height=480
如果有任何地方我可以了解有关如何使用编解码器的更多信息,以便我可以了解如何正确使用MediaCodec
,请分享,我将非常感激。
解决方案
推荐阅读
- azure-ad-b2c - Azure B2C 刷新令牌用户旅程不会更改 id_token 中的声明
- javascript - 如何在指定时区获得一周中的哪一天?
- python - 如何创建用户可以调整以更改 3D 绘图颜色的滑块?
- python - Python如何在发送电子邮件时删除标题?
- pandas - 如何在保存 csv 时保存特定的日期时间格式?
- r - 如何使五大湖与R中的海洋颜色相同?
- typescript - 如何从单独的文件中导出打字稿谷歌云函数?
- amazon-web-services - 为什么像 S3 (arn:aws:s3:::) 这样的 IAM 角色语句不适用于 SQS 等其他 AWS 资源?
- selenium - 如何通过“场景大纲示例”传递双引号
- flask - 我想比较数据库中的信息但出错