標籤:
我在設定 MediaCodec profile 的時候,一直沒有成功,看了源碼之後才發現問題之所在:
https://android.googlesource.com/platform/frameworks/av/+/437ced8a14944bf5450df50c5e7e7a6dfe20ea40/media/libstagefright/ACodec.cpp
設定了 profile 之後,你還要設定一個 Level 屬性,但是目前最新的 SDK 裡面並沒有提供這個 Key。
即使你手動的設定 level ,比如像這樣:
MediaCodec codec = createEncoderByType(MediaFormat.MIMETYPE_VIDEO_AVC);MediaFormat format = = MediaFormat.createVideoFormat(MediaFormat.MIMETYPE_VIDEO_AVC, 1920, 1080);format.setInteger(MediaFormat.KEY_PROFILE, MediaCodecInfo.CodecProfileLevel.AVCProfileHigh);format.setInteger("level", Level_xxx);codec.configure(format, null, null, MediaCodec.CONFIGURE_FLAG_ENCODE); 還是不行的,因為 Android 強制將 profile 設定為 Baseline 了。
// XXX if (h264type.eProfile != OMX_VIDEO_AVCProfileBaseline) { ALOGW("Use baseline profile instead of %d for AVC recording", h264type.eProfile); h264type.eProfile = OMX_VIDEO_AVCProfileBaseline; }
總之,Android 在使用 MediaCodc 進行 encode 的時候,只能使用 Baseline 的 profile。
Google 之後,發現也有其他的朋友發現了類似的問題,
https://code.google.com/p/android/issues/detail?id=163580
看來這個問題確實存在,不過不清楚為什麼 Android 要強制使用 Baseline 的 profile。
Android MediaCodec 設定 MediaFormat.KEY_PROFILE 問題