Android MediaCodec 設定 MediaFormat.KEY_PROFILE 問題

來源:互聯網
上載者:User

標籤:

我在設定 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 問題

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.