AbedElazizShe / LightCompressor

A powerful and easy-to-use video compression library for android uses MediaCodec API.
Apache License 2.0
491 stars 116 forks source link

MediaCodec configure error #159

Open joelpjy opened 11 months ago

joelpjy commented 11 months ago

Device: Google Pixel 4XL OS: Android 12, API 32 LightCompressor Version used: 1.3.0

Issue: Im getting an error with the MediaCodec when compressing a screen recording on Google Pixel 4XL. When it happens, it creates a corrupted file of size 28B and it calls the onSuccess.

I tried compressing a video taken from the camera and it works fine. I tried on other android devices (Android 10), both screen recordings and video from camera is working.

An error has occurred!
java.lang.IllegalArgumentException
    at android.media.MediaCodec.native_configure(Native Method)
    at android.media.MediaCodec.configure(MediaCodec.java:2176)
    at android.media.MediaCodec.configure(MediaCodec.java:2092)
    at com.abedelazizshe.lightcompressorlibrary.compressor.Compressor.prepareEncoder(Compressor.kt:516)
    at com.abedelazizshe.lightcompressorlibrary.compressor.Compressor.start(Compressor.kt:199)
    at com.abedelazizshe.lightcompressorlibrary.compressor.Compressor.access$start(Compressor.kt:30)
    at com.abedelazizshe.lightcompressorlibrary.compressor.Compressor$compressVideo$2.invokeSuspend(Compressor.kt:134)
    at com.abedelazizshe.lightcompressorlibrary.compressor.Compressor$compressVideo$2.invoke(Unknown Source:8)
    at com.abedelazizshe.lightcompressorlibrary.compressor.Compressor$compressVideo$2.invoke(Unknown Source:4)
    at kotlinx.coroutines.intrinsics.UndispatchedKt.startUndispatchedOrReturn(Undispatched.kt:89)
    at kotlinx.coroutines.BuildersKt__Builders_commonKt.withContext(Builders.common.kt:169)
    at kotlinx.coroutines.BuildersKt.withContext(Unknown Source:1)
    at com.abedelazizshe.lightcompressorlibrary.compressor.Compressor.compressVideo(Compressor.kt:53)
    at com.abedelazizshe.lightcompressorlibrary.VideoCompressor$startCompression$2.invokeSuspend(VideoCompressor.kt:180)
    at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
    at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:106)
    at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:570)
    at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:750)
    at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:677)
    at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:664)
AbedElazizShe commented 11 months ago

Hi @joelpjy, thank you for opening this issue. Could you please share the video with me? I have pixel 2XL and pixel 4A, both are working fine. I could not manage to screen record pixel 4XL.

Thank you.

joelpjy commented 11 months ago

hello @AbedElazizShe , sry for the late reply. Heres the video: https://drive.google.com/file/d/1ZMRqhUtj1mVWM4CXgbU6fMCNiIZp5bey/view?usp=sharing

I tried on Pixel 7a, both screen recording and camera video works too. Not sure why only this Pixel 4XL encounters this error for screen recordings. Tried on 3-4 other samsung devices, all are fine as well.

Currently my workaround is just to check if the output file's size is exactly 28B, if it is, handled as if it failed the compression.

joelpjy commented 11 months ago

Not sure if it will help, but before the crash i saw another error:

Codec reported err 0xffffffea, actionCode 0, while in state 3/CONFIGURING
configure failed with err 0xffffffea, resetting...

The full logs is here:

Output file parameters videoFormat: {color-transfer=3, color-format=2130708361, i-frame-interval=1, mime=video/avc, width=1440, bitrate-mode=2, bitrate=2896185, color-range=2, frame-rate=74, color-standard=1, height=3040} CODECS: c2.android.aac.decoder CODECS: OMX.google.aac.decoder CODECS: c2.android.aac.encoder CODECS: OMX.google.aac.encoder CODECS: c2.android.amrnb.decoder CODECS: OMX.google.amrnb.decoder CODECS: c2.android.amrnb.encoder CODECS: OMX.google.amrnb.encoder CODECS: c2.android.amrwb.decoder CODECS: OMX.google.amrwb.decoder CODECS: c2.android.amrwb.encoder CODECS: OMX.google.amrwb.encoder CODECS: c2.android.flac.decoder CODECS: OMX.google.flac.decoder CODECS: c2.android.flac.encoder CODECS: OMX.google.flac.encoder CODECS: c2.android.g711.alaw.decoder CODECS: OMX.google.g711.alaw.decoder CODECS: c2.android.g711.mlaw.decoder CODECS: OMX.google.g711.mlaw.decoder CODECS: c2.android.gsm.decoder CODECS: OMX.google.gsm.decoder CODECS: c2.android.mp3.decoder CODECS: OMX.google.mp3.decoder CODECS: c2.android.opus.decoder CODECS: OMX.google.opus.decoder CODECS: c2.android.opus.encoder CODECS: c2.android.raw.decoder CODECS: OMX.google.raw.decoder CODECS: c2.android.vorbis.decoder CODECS: OMX.google.vorbis.decoder CODECS: c2.qti.avc.decoder CCodec allocate(c2.android.avc.encoder) CCodec setting up 'default' as default (vendor) store CCodec Created component [c2.android.avc.encoder] CCodecConfig read media type: video/avc ReflectedParamUpdater extent() != 1 for single value type: algo.buffers.max-count.values ReflectedParamUpdater extent() != 1 for single value type: output.subscribed-indices.values ReflectedParamUpdater extent() != 1 for single value type: input.buffers.allocator-ids.values ReflectedParamUpdater extent() != 1 for single value type: output.buffers.allocator-ids.values ReflectedParamUpdater extent() != 1 for single value type: algo.buffers.allocator-ids.values ReflectedParamUpdater extent() != 1 for single value type: output.buffers.pool-ids.values ReflectedParamUpdater extent() != 1 for single value type: algo.buffers.pool-ids.values ReflectedParamUpdater ignored struct field coding.gop.values ReflectedParamUpdater ignored struct field coding.qp.values CCodecConfig ignoring local param raw.color (0xc2001809) as it is already supported CCodecConfig query failed after returning 12 values (BAD_INDEX) CCodecConfig c2 config diff is Dict { c2::u32 coded.bitrate.value = 64000 c2::float coded.frame-rate.value = 1 c2::u32 coded.pl.level = 20492 c2::u32 coded.pl.profile = 20481 c2::u32 coded.vui.color.matrix = 0 c2::u32 coded.vui.color.primaries = 0 c2::u32 coded.vui.color.range = 0 c2::u32 coded.vui.color.transfer = 0 c2::u32 coding.intra-refresh.mode = 0 c2::float coding.intra-refresh.period = 0 c2::u32 coding.request-sync-frame.value = 0 c2::i64 coding.sync-frame-interval.value = 1000000 c2::u32 input.delay.value = 0 string input.media-type.value = "video/raw" string output.media-type.value = "video/avc" c2::u32 raw.color.matrix = 0 c2::u32 raw.color.primaries = 0 c2::u32 raw.color.range = 0 c2::u32 raw.color.transfer = 0 c2::u32 raw.size.height = 16 c2::u32 raw.size.width = 16 } ColorUtils expected specified color aspects (0:0:0:0) VQApply minquality: applies only to VBR encoding MediaCodec shapeMediaFormat: deltas(0): AMessage(what = 0x00000000) = { } CCodec [c2.android.avc.encoder] buffers are bound to CCodec for this session CCodecConfig no c2 equivalents for color-format CCodecConfig no c2 equivalents for color-standard CCodecConfig no c2 equivalents for flags CCodecConfig no c2 equivalents for encoder CCodecConfig Bad parameter value CCodecConfig c2 config diff is c2::u32 coded.bitrate.value = 2896185 c2::float coded.frame-rate.value = 74 c2::u32 coded.vui.color.matrix = 1 c2::u32 coded.vui.color.primaries = 1 c2::u32 coded.vui.color.range = 2 c2::u32 coded.vui.color.transfer = 3 c2::u32 raw.color.matrix = 1 c2::u32 raw.color.primaries = 1 c2::u32 raw.color.range = 2 c2::u32 raw.color.transfer = 3 c2::u32 raw.size.width = 1440 CCodec failed to configure c2 params MediaCodec Codec reported err 0xffffffea, actionCode 0, while in state 3/CONFIGURING MediaCodec configure failed with err 0xffffffea, resetting... hw-BpHwBinder onLastStrongRef automatically unlinking death recipients CCodec allocate(c2.android.avc.encoder) CCodec setting up 'default' as default (vendor) store CCodec Created component [c2.android.avc.encoder] CCodecConfig read media type: video/avc ReflectedParamUpdater extent() != 1 for single value type: algo.buffers.max-count.values ReflectedParamUpdater extent() != 1 for single value type: output.subscribed-indices.values ReflectedParamUpdater extent() != 1 for single value type: input.buffers.allocator-ids.values ReflectedParamUpdater extent() != 1 for single value type: output.buffers.allocator-ids.values ReflectedParamUpdater extent() != 1 for single value type: algo.buffers.allocator-ids.values ReflectedParamUpdater extent() != 1 for single value type: output.buffers.pool-ids.values ReflectedParamUpdater extent() != 1 for single value type: algo.buffers.pool-ids.values ReflectedParamUpdater ignored struct field coding.gop.values ReflectedParamUpdater ignored struct field coding.qp.values CCodecConfig ignoring local param raw.color (0xc2001809) as it is already supported CCodecConfig query failed after returning 12 values (BAD_INDEX) CCodecConfig c2 config diff is Dict { c2::u32 coded.bitrate.value = 64000 c2::float coded.frame-rate.value = 1 c2::u32 coded.pl.level = 20492 c2::u32 coded.pl.profile = 20481 c2::u32 coded.vui.color.matrix = 0 c2::u32 coded.vui.color.primaries = 0 c2::u32 coded.vui.color.range = 0 c2::u32 coded.vui.color.transfer = 0 c2::u32 coding.intra-refresh.mode = 0 c2::float coding.intra-refresh.period = 0 c2::u32 coding.request-sync-frame.value = 0 c2::i64 coding.sync-frame-interval.value = 1000000 c2::u32 input.delay.value = 0 string input.media-type.value = "video/raw" string output.media-type.value = "video/avc" c2::u32 raw.color.matrix = 0 c2::u32 raw.color.primaries = 0 c2::u32 raw.color.range = 0 c2::u32 raw.color.transfer = 0 c2::u32 raw.size.height = 16 c2::u32 raw.size.width = 16 } ColorUtils expected specified color aspects (0:0:0:0) Compressor An error has occurred! java.lang.IllegalArgumentException at android.media.MediaCodec.native_configure(Native Method) at android.media.MediaCodec.configure(MediaCodec.java:2176) at android.media.MediaCodec.configure(MediaCodec.java:2092) at com.abedelazizshe.lightcompressorlibrary.compressor.Compressor.prepareEncoder(Compressor.kt:516) at com.abedelazizshe.lightcompressorlibrary.compressor.Compressor.start(Compressor.kt:199) at com.abedelazizshe.lightcompressorlibrary.compressor.Compressor.access$start(Compressor.kt:30) at com.abedelazizshe.lightcompressorlibrary.compressor.Compressor$compressVideo$2.invokeSuspend(Compressor.kt:134) at com.abedelazizshe.lightcompressorlibrary.compressor.Compressor$compressVideo$2.invoke(Unknown Source:8) at com.abedelazizshe.lightcompressorlibrary.compressor.Compressor$compressVideo$2.invoke(Unknown Source:4) at kotlinx.coroutines.intrinsics.UndispatchedKt.startUndispatchedOrReturn(Undispatched.kt:89) at kotlinx.coroutines.BuildersKt__Builders_commonKt.withContext(Builders.common.kt:169) at kotlinx.coroutines.BuildersKt.withContext(Unknown Source:1) at com.abedelazizshe.lightcompressorlibrary.compressor.Compressor.compressVideo(Compressor.kt:53) at com.abedelazizshe.lightcompressorlibrary.VideoCompressor$startCompression$2.invokeSuspend(VideoCompressor.kt:180) at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33) at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:106) at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:570) at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:750) at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:677) at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:664)

AbedElazizShe commented 9 months ago

Hi @joelpjy I believe the issue is fixed in the new release. Will post is shortly.