自 2025 年 3 月 27 日起,我們建議您使用 android-latest-release
而非 aosp-main
建構及貢獻 AOSP。詳情請參閱「Android 開放原始碼計畫變更」。
媒體
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
Android 包含 Stagefright,這是原生層級的媒體播放引擎,內建了適用於熱門媒體格式的軟體編碼器。
Stagefright 音訊和影片播放功能包括與 OpenMAX 轉碼器整合、工作階段管理、時間同步轉譯、傳輸控制和 DRM。
Stagefright 也支援與您提供的自訂硬體編解碼整合。如要設定硬體路徑來編碼及解碼媒體,您必須將以硬體為基礎的編碼器設為 OpenMax IL (整合層) 元件。
注意:Stagefright 更新可透過 Android 每月安全性更新程序,以及 Android 作業系統版本發布。
建築
媒體應用程式會根據下列架構與 Android 原生多媒體架構互動。

圖 1. 媒體架構
- 應用程式架構
- 應用程式架構層級是應用程式程式碼,可利用 android.media API 與多媒體硬體互動。
- Binder IPC
- Binder IPC 代理程式可協助處理序間通訊。這些檔案位於
frameworks/av/media/libmedia
目錄,並以字母「I」開頭。
- 原生多媒體架構
- 在原生層級,Android 提供多媒體架構,可利用 Stagefright 引擎錄製及播放音訊和視訊。Stagefright 提供支援的軟體編碼器預設清單,您可以使用 OpenMax 整合層標準實作自己的硬體編碼器。如需更多實作詳細資訊,請參閱
frameworks/av/media
中的 MediaPlayer 和 Stagefright 元件。
- OpenMAX 整合層 (IL)
- OpenMAX IL 提供標準化方式,讓 Stagefright 辨識及使用稱為元件的自訂硬體多媒體編解碼器。您必須以名為
libstagefrighthw.so
的共用程式庫形式提供 OpenMAX 外掛程式。這個外掛程式會將 Stagefright 連結至自訂編解碼元件,而這些元件必須根據 OpenMAX IL 元件標準實作。
實作自訂編解碼器
Stagefright 內建適用於常見媒體格式的軟體編碼器,但您也可以新增自訂硬體編碼器做為 OpenMAX 元件。為此,您必須建立 OMX 元件和 OMX 外掛程式,以便將自訂編解碼器與 Stagefright 架構連結在一起。如需元件的範例,請參閱 hardware/ti/omap4xxx/domx/
;如需 Galaxy Nexus 的範例外掛程式,請參閱 hardware/ti/omap4xx/libstagefrighthw
。
如要新增自己的編解碼:
- 請根據 OpenMAX IL 元件標準建立元件。元件介面位於
frameworks/native/include/media/OpenMAX/OMX_Component.h
檔案中。如要進一步瞭解 OpenMAX IL 規格,請參閱 OpenMAX 網站。
- 建立 OpenMAX 外掛程式,將元件連結至 Stagefright 服務。如要瞭解建立外掛程式的介面,請參閱
frameworks/native/include/media/hardware/OMXPluginBase.h
和 HardwareAPI.h
標頭檔案。
- 在產品 Makefile 中,將外掛程式建構為名為
libstagefrighthw.so
的共用程式庫。例如:
LOCAL_MODULE := libstagefrighthw
在裝置的 Makefile 中,請務必將模組宣告為產品套件:
PRODUCT_PACKAGES += \
libstagefrighthw \
...
將編解碼公開給架構
Stagefright 服務會剖析 system/etc/media_codecs.xml
和 system/etc/media_profiles.xml
,透過 android.media.MediaCodecList
和 android.media.CamcorderProfile
類別,向應用程式開發人員公開裝置上支援的編解碼和設定檔。您必須在 device/<company>/<device>/
目錄中建立這兩個檔案,並將其複製到裝置 Makefile 中的系統映像檔 system/etc
目錄。例如:
PRODUCT_COPY_FILES += \
device/samsung/tuna/media_profiles.xml:system/etc/media_profiles.xml \
device/samsung/tuna/media_codecs.xml:system/etc/media_codecs.xml \
如需完整範例,請參閱 device/samsung/tuna/media_codecs.xml
和 device/samsung/tuna/media_profiles.xml
。
注意:自 Android 4.1 起,系統不再支援媒體編解碼器的 <Quirk>
元素。
這個頁面中的內容和程式碼範例均受《內容授權》中的授權所規範。Java 與 OpenJDK 是 Oracle 和/或其關係企業的商標或註冊商標。
上次更新時間:2025-07-27 (世界標準時間)。
[[["容易理解","easyToUnderstand","thumb-up"],["確實解決了我的問題","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["缺少我需要的資訊","missingTheInformationINeed","thumb-down"],["過於複雜/步驟過多","tooComplicatedTooManySteps","thumb-down"],["過時","outOfDate","thumb-down"],["翻譯問題","translationIssue","thumb-down"],["示例/程式碼問題","samplesCodeIssue","thumb-down"],["其他","otherDown","thumb-down"]],["上次更新時間:2025-07-27 (世界標準時間)。"],[],[],null,["# Media\n\nAndroid includes Stagefright, a media playback engine at the native level\nthat has built-in software-based codecs for popular media formats.\n\nStagefright audio and video playback features include integration with\nOpenMAX codecs, session management, time-synchronized rendering, transport\ncontrol, and DRM.\n\nStagefright also supports integration with custom hardware codecs provided by\nyou. To set a hardware path to encode and decode media, you must implement a\nhardware-based codec as an OpenMax IL (Integration Layer) component.\n\n**Note:** Stagefright updates can occur through the\nAndroid [monthly security\nupdate](/docs/security/bulletin) process and as part of an Android OS release.\n\nArchitecture\n------------\n\nMedia applications interact with the Android native multimedia framework\naccording to the following architecture.\n\n**Figure 1.** Media\narchitecture\n\nApplication Framework\n: At the application framework level is application code that utilizes\n [android.media](http://developer.android.com/reference/android/media/package-summary.html)\n APIs to interact with the multimedia hardware.\n\nBinder IPC\n: The Binder IPC proxies facilitate communication over process boundaries.\n They are located in the `frameworks/av/media/libmedia` directory and\n begin with the letter \"I\".\n\nNative Multimedia Framework\n: At the native level, Android provides a multimedia framework that utilizes\n the Stagefright engine for audio and video recording and playback. Stagefright\n comes with a default list of supported software codecs and you can implement\n your own hardware codec by using the OpenMax integration layer standard. For\n more implementation details, see the MediaPlayer and Stagefright components\n located in `frameworks/av/media`.\n\nOpenMAX Integration Layer (IL)\n: The OpenMAX IL provides a standardized way for Stagefright to recognize and\n use custom hardware-based multimedia codecs called components. You must provide\n an OpenMAX plugin in the form of a shared library named\n `libstagefrighthw.so`. This plugin links Stagefright with your custom\n codec components, which must be implemented according to the OpenMAX IL\n component standard.\n\nImplement custom codecs\n-----------------------\n\nStagefright comes with built-in software codecs for common media formats, but\nyou can also add your own custom hardware codecs as OpenMAX components. To do\nthis, you must create the OMX components and an OMX plugin that hooks together\nyour custom codecs with the Stagefright framework. For example components, see\nthe `hardware/ti/omap4xxx/domx/`; for an example plugin for the\nGalaxy Nexus, see `hardware/ti/omap4xx/libstagefrighthw`.\n\nTo add your own codecs:\n\n1. Create your components according to the OpenMAX IL component standard. The component interface is located in the `frameworks/native/include/media/OpenMAX/OMX_Component.h` file. To learn more about the OpenMAX IL specification, refer to the [OpenMAX website](http://www.khronos.org/openmax/).\n2. Create a OpenMAX plugin that links your components with the Stagefright service. For the interfaces to create the plugin, see `frameworks/native/include/media/hardware/OMXPluginBase.h` and `HardwareAPI.h` header files.\n3. Build your plugin as a shared library with the name `libstagefrighthw.so` in your product Makefile. For example: \n\n ```\n LOCAL_MODULE := libstagefrighthw\n ```\n\n In your device's Makefile, ensure you declare the module as a product\n package: \n\n ```\n PRODUCT_PACKAGES += \\\n libstagefrighthw \\\n ...\n ```\n\nExpose codecs to the framework\n------------------------------\n\nThe Stagefright service parses the `system/etc/media_codecs.xml`\nand `system/etc/media_profiles.xml` to expose the supported codecs\nand profiles on the device to app developers via the\n`android.media.MediaCodecList` and\n`android.media.CamcorderProfile` classes. You must create both files\nin the `device/\u003ccompany\u003e/\u003cdevice\u003e/` directory\nand copy this over to the system image's `system/etc` directory in\nyour device's Makefile. For example: \n\n```\nPRODUCT_COPY_FILES += \\\n device/samsung/tuna/media_profiles.xml:system/etc/media_profiles.xml \\\n device/samsung/tuna/media_codecs.xml:system/etc/media_codecs.xml \\\n```\n\nFor complete examples, see `device/samsung/tuna/media_codecs.xml`\nand `device/samsung/tuna/media_profiles.xml` .\n\n**Note:** As of Android 4.1, the\n`\u003cQuirk\u003e` element for media codecs is no longer supported."]]