Media3 Transformer 正在积极开发中,我们期待收到您的反馈意见!欢迎在
问题跟踪器中提供反馈、提交功能请求和错误报告。关注
ExoPlayer 博客,了解最新动态。
自定义
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
如需控制 Transformer 的行为,您可以在 API Surface 中配置选项
或者通过编写自定义实现来完全替换部分功能
并传入这些接口本页面介绍了一些示例。
控制编解码器配置
默认情况下,如果 Transformer
设备的硬件编码器不接受请求的输出分辨率。对于
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。
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):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"]],["最后更新时间 (UTC):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."]]