【发布时间】:2022-12-01 19:10:10
【问题描述】:
The app I am working on gets the video from the camera through Surface and encodes it to video/avc (H264) I am doing that successfully and it is working great on phones like galaxy Note 10+ but on phones like Xiaomi note 10s which is a new phone I am having this issue. Here is what I am doing:
- create format:
format = MediaFormat.createVideoFormat( H264, videoWidth, videoHeight ).apply { setInteger(MediaFormat.KEY_MAX_INPUT_SIZE, 0) setInteger(MediaFormat.KEY_BIT_RATE, bitrate) setInteger(MediaFormat.KEY_FRAME_RATE, videoFrameRate) setInteger( MediaFormat.KEY_COLOR_FORMAT, CodecCapabilities.COLOR_FormatSurface ) setFloat(MediaFormat.KEY_I_FRAME_INTERVAL, 1f) }```- Then create encoderName:
val encoderName = MediaCodecList( MediaCodecList.ALL_CODECS ).findEncoderForFormat(format) //using the format I shared in the first step- Then create:
codec = MediaCodec.createByCodecName(encoderName)Then .setCallback(callback) //not important since we won't make it till this point, it will crash before that.
4. And this is the line where it crashes.
codec.configure(format, null, null, MediaCodec.CONFIGURE_FLAG_ENCODE) //CRASH => MediaCodec$CodecException: Error 0x80001001- The rest
codec.setInputSurface(surface) codec.start()I am suspecting the
setInteger( MediaFormat.KEY_COLOR_FORMAT, CodecCapabilities.COLOR_FormatSurface ) //I tried changing the value and completely removing this setInteger, no luck :/
【问题讨论】:
标签: android android-camera2 android-mediacodec