MasayukiSuda / Mp4Composer-android

This library generate an Mp4 movie using Android MediaCodec API and apply filter, scale, trim, transcode, crop, timeScale, mute and rotate Mp4.
MIT License
956 stars 219 forks source link

Huawei trim issue #74

Closed jackspugna closed 4 years ago

jackspugna commented 4 years ago

Hi, I've just integrated your library in my project, but I have an issue with Huawei devices, probably due to Huawei/Android internal codec. Below, there's the stack trace of the exception thrown when I try to trim a video. I ask you, if you can, to debug your library on a Huawei device (I've tried on a P20 Pro, a Mate 20 Pro and a Nova 5T, and always the same issue) and try to fix it. Thank you.

2020-03-18 15:38:59.809 19773-20513/[package_name] E/ACodec: [OMX.hisi.video.decoder.avc] setPortMode on output to DynamicANWBuffer failed w/ err -2147483648 2020-03-18 15:38:59.809 19773-20513/[package_name] E/libc: Access denied finding property "ro.kirin.product.platform" 2020-03-18 15:38:59.809 19773-20513/[package_name] E/HwExtendedCodec: mime: video/avc matching compontent failed! 2020-03-18 15:38:59.810 19773-20513/[package_name] I/HwExtendedCodec: mime is [video/avc] at setVideoFormat 2020-03-18 15:38:59.810 19773-20513/[package_name] E/libc: Access denied finding property "config.camera.color_encode" 2020-03-18 15:38:59.811 19773-20513/[package_name] E/libc: Access denied finding property "config.camera.color_encode" 2020-03-18 15:38:59.811 19773-20513/[package_name] I/ACodec: [OMX.hisi.video.decoder.avc] got color aspects (R:2(Limited), P:3(BT601_6_625), M:3(BT601_6), T:3(SMPTE170M)) err=0(NO_ERROR) 2020-03-18 15:38:59.811 19773-20513/[package_name] I/ACodec: [OMX.hisi.video.decoder.avc] got color aspects (R:2(Limited), P:3(BT601_6_625), M:3(BT601_6), T:3(SMPTE170M)) err=0(NO_ERROR) 2020-03-18 15:38:59.811 19773-20513/[package_name] I/ACodec: [OMX.hisi.video.decoder.avc] using color aspects (R:2(Limited), P:3(BT601_6_625), M:3(BT601_6), T:3(SMPTE170M)) and dataspace 0x102 2020-03-18 15:38:59.813 19773-20513/[package_name] I/ACodec: onStart 2020-03-18 15:38:59.837 19773-20513/[package_name] D/SurfaceUtils: disconnecting from surface 0x7880340010, reason setNativeWindowSizeFormatAndUsage 2020-03-18 15:38:59.837 19773-20513/[package_name] D/SurfaceUtils: connecting to surface 0x7880340010, reason setNativeWindowSizeFormatAndUsage 2020-03-18 15:38:59.838 19773-20513/[package_name] D/SurfaceUtils: set up nativeWindow 0x7880340010 for 3840x2160, color 0x30d, rotation 0, usage 0x20002900 2020-03-18 15:38:59.841 19773-20513/[package_name] W/MapperHal: buffer descriptor with invalid usage bits 0x2000 2020-03-18 15:38:59.845 19773-20513/[package_name] W/MapperHal: buffer descriptor with invalid usage bits 0x2000 2020-03-18 15:38:59.848 19773-20513/[package_name] W/MapperHal: buffer descriptor with invalid usage bits 0x2000 2020-03-18 15:38:59.852 19773-20513/[package_name] W/MapperHal: buffer descriptor with invalid usage bits 0x2000 2020-03-18 15:38:59.858 19773-20513/[package_name] W/MapperHal: buffer descriptor with invalid usage bits 0x2000 2020-03-18 15:38:59.863 19773-20513/[package_name] W/MapperHal: buffer descriptor with invalid usage bits 0x2000 2020-03-18 15:38:59.878 19773-20504/[package_name] W/mali_winsys: native_window_api_disconnect failed: -19 2020-03-18 15:38:59.879 19773-20513/[package_name] W/ACodec: forcing OMX state to Idle when received shutdown in ExecutingState 2020-03-18 15:38:59.883 19773-20513/[package_name] E/BufferQueueProducer: [SurfaceTexture-1-19773-0] cancelBuffer: BufferQueue has been abandoned 2020-03-18 15:38:59.906 19773-20512/[package_name] D/SurfaceUtils: disconnecting from surface 0x7880340010, reason disconnectFromSurface 2020-03-18 15:38:59.919 19773-20504/[package_name] E/Mp4ComposerEngine: Could not shutdown mediaExtractor, codecs and mediaMuxer pipeline. java.lang.IllegalStateException at android.media.MediaCodec.native_stop(Native Method) at android.media.MediaCodec.stop(MediaCodec.java:2091) at com.daasuu.mp4compose.composer.VideoComposer.release(VideoComposer.java:161) at com.daasuu.mp4compose.composer.Mp4ComposerEngine.compose(Mp4ComposerEngine.java:144) at com.daasuu.mp4compose.composer.Mp4Composer$2.run(Mp4Composer.java:297) at java.util.concurrent.ThreadPoolExecutor.processTask(ThreadPoolExecutor.java:1187) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1152) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641) at java.lang.Thread.run(Thread.java:784) 2020-03-18 15:38:59.920 19773-20504/[package_name] E/Mp4Composer: Unable to compose the engine java.lang.IllegalStateException at android.media.MediaCodec.native_dequeueOutputBuffer(Native Method) at android.media.MediaCodec.dequeueOutputBuffer(MediaCodec.java:2705) at com.daasuu.mp4compose.composer.VideoComposer.drainEncoder(VideoComposer.java:222) at com.daasuu.mp4compose.composer.VideoComposer.stepPipeline(VideoComposer.java:118) at com.daasuu.mp4compose.composer.Mp4ComposerEngine.runPipelines(Mp4ComposerEngine.java:267) at com.daasuu.mp4compose.composer.Mp4ComposerEngine.compose(Mp4ComposerEngine.java:133) at com.daasuu.mp4compose.composer.Mp4Composer$2.run(Mp4Composer.java:297) at java.util.concurrent.ThreadPoolExecutor.processTask(ThreadPoolExecutor.java:1187) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1152) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641) at java.lang.Thread.run(Thread.java:784)

jackspugna commented 4 years ago

I've found a solution. If you change in line 213 of Mp4ComposerEngine.java class "VideoFormatMimeType.H263.getFormat()" to "VideoFormatMimeType.HEVC.getFormat()" it works. This is because for some reasons on Huawei devices the MediaCodecList doesn't contains the codec we need to create the encoder, so I've forced the format. Hope you'll find this useful, I'm waiting for your answer. Thank you.

MasayukiSuda commented 4 years ago

Please try set videoFormatMimeType https://github.com/MasayukiSuda/Mp4Composer-android/blob/master/mp4compose/src/main/java/com/daasuu/mp4compose/composer/Mp4Composer.java#L177-L180