自訂
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
如要控管 Transformer 的行為,您可以在 API 介面中設定選項
也可以藉由編寫自訂導入方式完全取代功能
並傳入介面本頁會提供一些範例。
控制轉碼器設定
根據預設,如果
裝置的硬體編碼器不接受要求的輸出解析度。適用對象
例如,Transformer 可將輸出寬度和高度對齊為 2 的倍數
或 16。您可以關閉這項行為
,如果 Transformer 無法產生必要的
輸出解析度:
Kotlin
transformerBuilder
.setEncoderFactory(
DefaultEncoderFactory.Builder(context)
.setEnableFallback(false)
.build())
Java
transformerBuilder
.setEncoderFactory(
new DefaultEncoderFactory.Builder(context)
.setEnableFallback(false)
.build());
同樣地,DefaultEncoderFactory
也支援使用自訂編碼
以及 setRequestedVideoEncoderSettings
選項的設定
您也能完全取代編碼器和解碼器的工廠
可完全掌控轉碼器的設定方式。
客製化多工器
您可以藉由呼叫
Transformer.setMuxerFactory
。舉例來說,假設您在
在應用程式層級,您可以編寫包裝函式來實作 Muxer
介面,然後使用 setMuxerFactory
將其插入 Transformer。
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權,程式碼範例則為阿帕契 2.0 授權。詳情請參閱《Google Developers 網站政策》。Java 是 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,["# Customization\n\nTo control Transformer's behavior, you can configure options in the API surface\nor replace pieces of functionality completely by writing custom implementations\nof interfaces and passing those in. This page describes some examples.\n\nControl codec configuration\n---------------------------\n\nBy default, Transformer will fall back to a supported resolution if the\ndevice's hardware encoder doesn't accept the requested output resolution. For\nexample, Transformer can align the output width and height to be a multiple of 2\nor 16 as is often required by hardware encoders. You can turn off this behavior\nso that Transformer instead throws an error if it can't produce the required\noutput resolution: \n\n### Kotlin\n\n```kotlin\ntransformerBuilder\n .setEncoderFactory(\n DefaultEncoderFactory.Builder(context)\n .setEnableFallback(false)\n .build())\n```\n\n### Java\n\n```java\ntransformerBuilder\n .setEncoderFactory(\n new DefaultEncoderFactory.Builder(context)\n .setEnableFallback(false)\n .build());\n```\n\n\u003cbr /\u003e\n\nSimilarly, the `DefaultEncoderFactory` also supports using custom encoding\nsettings with the `setRequestedVideoEncoderSettings` option.\n\nYou can also completely replace the factories for encoders and decoders to get\nfull control over how the codecs are set up.\n\nCustom muxers\n-------------\n\nYou can set a custom muxer for writing media containers by calling\n`Transformer.setMuxerFactory`. For example, if you implement your own muxer at\nthe application level, you can write a wrapper that implements the `Muxer`\ninterface and then use `setMuxerFactory` to inject it into Transformer."]]