[英]IllegalStateExcpetion when calling MediaCodec.configure()
[英]Phone crashes when calling mediaCodec.configure with error MediaCodec$CodecException: Error 0x80001001
我正在開發的應用程序通過 Surface 從相機獲取視頻並將其編碼為視頻/avc (H264) 我正在成功地做到這一點並且它在 galaxy Note 10+ 等手機上運行良好但在小米 note 10s 等手機上運行良好一部新手機 我遇到了這個問題。 這是我在做什么:
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)
}```
val encoderName = MediaCodecList(
MediaCodecList.ALL_CODECS
).findEncoderForFormat(format) //using the format I shared in the first step
codec = MediaCodec.createByCodecName(encoderName)
Then.setCallback(callback) //不重要,因為我們不會做到這一點,它會在此之前崩潰。
4. 這是它崩潰的地方。 codec.configure(format, null, null, MediaCodec.CONFIGURE_FLAG_ENCODE) //CRASH => MediaCodec$CodecException: Error 0x80001001
codec.setInputSurface(surface)
codec.start()
我懷疑
setInteger(
MediaFormat.KEY_COLOR_FORMAT,
CodecCapabilities.COLOR_FormatSurface
) //I tried changing the value and completely removing this setInteger, no luck :/
錯誤0x80001001
也稱為OMX_ErrorUndefined
表示:“出現錯誤,但無法確定錯誤原因”。
此錯誤的最可能原因是資源不足。 例如,如果您嘗試配置硬件編解碼器但目前沒有足夠的圖形 memory 可用,就會發生這種情況。
建議 1:確保在使用完編解碼器后釋放它們。 您需要檢查所有代碼路徑。
建議 2:知道這可能發生,您可以過濾MediaCodecList
,保留所有支持給定格式的編碼器。 然后將configure()
調用包裝在try
/ catch
塊中。 並且,如果調用失敗,請嘗試編解碼器列表中的下一個選項。
請注意,在大多數設備上,至少有兩種H264
編解碼器:硬件編解碼器和軟件編解碼器。 前者性能更好,后者更具彈性。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.