Media3 Transformer đang tích cực phát triển nên chúng tôi rất mong nhận được ý kiến đóng góp của bạn! Chúng tôi hoan nghênh ý kiến phản hồi, yêu cầu về tính năng và báo cáo lỗi của bạn trong
công cụ theo dõi lỗi. Theo dõi
blog ExoPlayer để biết những thông tin cập nhật mới nhất.
Chỉnh sửa nhiều thành phần
Sử dụng bộ sưu tập để sắp xếp ngăn nắp các trang
Lưu và phân loại nội dung dựa trên lựa chọn ưu tiên của bạn.
Khi sử dụng Transformer, bạn có thể kết hợp nhiều nội dung nghe nhìn, chẳng hạn như video,
hình ảnh và tệp âm thanh để tạo Composition
.
Xuất một Bản sáng tác
Cách áp dụng quy tắc chuyển đổi
(chẳng hạn như hiệu ứng hoặc chỉnh sửa cắt bỏ) cho MediaItem
, bạn nên tạo một
EditedMediaItem
để biểu thị thành phần đã áp dụng các phép biến đổi.
Sau đó, các đối tượng EditedMediaItem
có thể được nối với nhau để tạo ra một
EditedMediaItemSequence
.
Ví dụ: bạn có thể tạo EditedMediaItemSequence
với hai thành phần
video. Các mục bên trong EditedMediaItemSequence
được sắp xếp theo tuần tự và
không bị trùng lặp về thời gian.
Composition
là sự kết hợp của một hoặc nhiều EditedMediaItemSequence
. Tất cả đối tượng EditedMediaItemSequence
trong Composition
đều kết hợp
giúp bạn kết hợp thành phần video và âm thanh.
Bạn có thể xuất đối tượng Composition
bằng Bộ chuyển đổi.
Dưới đây là ví dụ về cách tạo và xuất một tài sản video bao gồm hai
đoạn video đã chỉnh sửa, phủ bản âm thanh:
Kotlin
val transformer = ... // Set up Transformer instance
val video1 = EditedMediaItem.Builder(
MediaItem.fromUri(video1Uri))
.build()
val video2 = EditedMediaItem.Builder(
MediaItem.fromUri(video2Uri))
.build()
val videoSequence = EditedMediaItemSequence(
video1, video2)
val backgroundAudio = EditedMediaItem.Builder(
MediaItem.fromUri(audioUri))
.build()
val backgroundAudioSequence = EditedMediaItemSequence(
ImmutableList.of(backgroundAudio),
/* isLooping= */ true) // Loop audio track through duration of videoSequence
val composition = Composition.Builder(
videoSequence,
backgroundAudioSequence)
.build()
val filePath = ... // Provide file path to save Composition
transformer.start(composition, filePath)
Java
Transformer transformer = ... // Set up Transformer instance
EditedMediaItem video1 = new EditedMediaItem.Builder(
MediaItem.fromUri(video1Uri))
.build();
EditedMediaItem video2 = new EditedMediaItem.Builder(
MediaItem.fromUri(video2Uri))
.build();
EditedMediaItemSequence videoSequence = new EditedMediaItemSequence(
video1, video2);
EditedMediaItem backgroundAudio = new EditedMediaItem.Builder(
MediaItem.fromUri(audioUri))
.build();
EditedMediaItemSequence backgroundAudioSequence = new EditedMediaItemSequence(
ImmutableList.of(backgroundAudio),
/* isLooping= */ true); // Loop audio track through duration of videoSequence
String filePath = ... // Provide file path to save Composition
Composition composition = new Composition.Builder(
videoSequence,
backgroundAudioSequence)
.build();
transformer.start(composition, filePath);
Ví dụ về trường hợp sử dụng được hỗ trợ
Đây là danh sách chưa đầy đủ gồm các trường hợp sử dụng mà Transformer API
hỗ trợ với Cấu trúc:
- Kết hợp tuần tự các thành phần âm thanh, hình ảnh và video. Tuy nhiên, tất cả các mục
trong một trình tự phải có cùng bản nhạc. Ví dụ: bạn không thể có một trình tự
có chứa tệp chỉ âm thanh, theo sau là tệp video.
- Thêm âm thanh nền vào thành phần video.
- Thêm hiệu ứng vào Thành phần kết hợp.
- Ánh xạ tông màu đầu vào HDR sang SDR để tạo ra đầu ra SDR có chất lượng hình ảnh tốt hơn.
Hạn chế hiện tại
Trình tự trong một Thành phần phải đáp ứng các điều kiện nêu trong
Transformer.start()
.
Ngoài ra, các thao tác sau chưa được hỗ trợ khi làm việc với
Thành phần:
- Bắt đầu phát một
EditedMediaItemSequence
có độ lệch.
- Bản âm thanh hoặc video mờ
Yêu cầu về tính năng
Nếu bạn có yêu cầu về tính năng cho Transformer API, hãy báo cáo vấn đề về
Kho lưu trữ GitHub Media3.
Trừ phi có lưu ý khác, nội dung của trang này được cấp phép theo Giấy phép ghi nhận tác giả 4.0 của Creative Commons và các mẫu mã lập trình được cấp phép theo Giấy phép Apache 2.0. Để biết thông tin chi tiết, vui lòng tham khảo Chính sách trang web của Google Developers. Java là nhãn hiệu đã đăng ký của Oracle và/hoặc các đơn vị liên kết với Oracle.
Cập nhật lần gần đây nhất: 2025-07-27 UTC.
[[["Dễ hiểu","easyToUnderstand","thumb-up"],["Giúp tôi giải quyết được vấn đề","solvedMyProblem","thumb-up"],["Khác","otherUp","thumb-up"]],[["Thiếu thông tin tôi cần","missingTheInformationINeed","thumb-down"],["Quá phức tạp/quá nhiều bước","tooComplicatedTooManySteps","thumb-down"],["Đã lỗi thời","outOfDate","thumb-down"],["Vấn đề về bản dịch","translationIssue","thumb-down"],["Vấn đề về mẫu/mã","samplesCodeIssue","thumb-down"],["Khác","otherDown","thumb-down"]],["Cập nhật lần gần đây nhất: 2025-07-27 UTC."],[],[],null,["# Multi-asset editing\n\nUsing Transformer, you can combine multiple media assets, such as videos,\nimages, and audio files to create a `Composition`.\n\nExporting a Composition\n-----------------------\n\nTo apply [transformations](/media/media3/transformer/transformations)\n(such as effects or trimming edits) to a `MediaItem`, you should create an\n[`EditedMediaItem`](/reference/androidx/media3/transformer/EditedMediaItem)\nto represent the asset that has the transformations applied to it.\n\n`EditedMediaItem` objects can then be concatenated together to create an\n[`EditedMediaItemSequence`](/reference/androidx/media3/transformer/EditedMediaItemSequence).\nFor example, you can create an `EditedMediaItemSequence` with two edited\nvideos. Items inside an `EditedMediaItemSequence` are ordered sequentially and\ndon't overlap in time.\n\nA `Composition` is the combination of one or more `EditedMediaItemSequence`\nobjects. All `EditedMediaItemSequence` objects in the `Composition` are mixed\ntogether, allowing you to combine video and audio assets.\n\n`Composition` objects can be exported using Transformer.\n\nHere is an example of creating and exporting a video asset that consists of two\nedited video clips, overlaid with an audio track: \n\n### Kotlin\n\n```kotlin\nval transformer = ... // Set up Transformer instance\n\nval video1 = EditedMediaItem.Builder(\n MediaItem.fromUri(video1Uri))\n .build()\n\nval video2 = EditedMediaItem.Builder(\n MediaItem.fromUri(video2Uri))\n .build()\n\nval videoSequence = EditedMediaItemSequence(\n video1, video2)\n\nval backgroundAudio = EditedMediaItem.Builder(\n MediaItem.fromUri(audioUri))\n .build()\n\nval backgroundAudioSequence = EditedMediaItemSequence(\n ImmutableList.of(backgroundAudio),\n /* isLooping= */ true) // Loop audio track through duration of videoSequence\n\nval composition = Composition.Builder(\n videoSequence,\n backgroundAudioSequence)\n .build()\n\nval filePath = ... // Provide file path to save Composition\n\ntransformer.start(composition, filePath)\n```\n\n### Java\n\n```java\nTransformer transformer = ... // Set up Transformer instance\n\nEditedMediaItem video1 = new EditedMediaItem.Builder(\n MediaItem.fromUri(video1Uri))\n .build();\n\nEditedMediaItem video2 = new EditedMediaItem.Builder(\n MediaItem.fromUri(video2Uri))\n .build();\n\nEditedMediaItemSequence videoSequence = new EditedMediaItemSequence(\n video1, video2);\n\nEditedMediaItem backgroundAudio = new EditedMediaItem.Builder(\n MediaItem.fromUri(audioUri))\n .build();\n\nEditedMediaItemSequence backgroundAudioSequence = new EditedMediaItemSequence(\n ImmutableList.of(backgroundAudio),\n /* isLooping= */ true); // Loop audio track through duration of videoSequence\n\nString filePath = ... // Provide file path to save Composition\n\nComposition composition = new Composition.Builder(\n videoSequence,\n backgroundAudioSequence)\n .build();\n\ntransformer.start(composition, filePath);\n```\n\n\u003cbr /\u003e\n\nExamples of supported use cases\n-------------------------------\n\nThis is a non-exhaustive list of use cases that the Transformer API\nsupports with Compositions:\n\n- Sequentially combining audio, image, and video assets. However, all items in a sequence must have the same tracks. For example, you cannot have a sequence that contains an audio only file, followed by a video file.\n- Adding background audio to a video asset.\n- Adding effects to a Composition.\n- Tone mapping HDR input to SDR to generate better visual quality SDR output.\n\nCurrent limitations\n-------------------\n\nSequences within a Composition must meet the conditions outlined in\n[`Transformer.start()`](/reference/androidx/media3/transformer/Transformer#start(androidx.media3.transformer.Composition,java.lang.String)).\nFurthermore, the following operations are not yet supported when working with\nCompositions:\n\n- Starting playback of an `EditedMediaItemSequence` with an offset.\n- Crossfading video or audio tracks\n\nFeature requests\n----------------\n\nIf you have any feature requests for the Transformer API, file an issue on the\n[Media3 GitHub repository](https://github.com/androidx/media/issues)."]]