Class TranscodingTransformer
- java.lang.Object
-
- com.google.android.exoplayer2.transformer.TranscodingTransformer
-
@RequiresApi(18) public final class TranscodingTransformer extends Object
A transcoding transformer to transform media inputs.Temporary copy of the
Transformerclass, which transforms by transcoding rather than by muxing. This class is intended to replace the Transformer class.TODO(http://b/202131097): Replace the Transformer class with TranscodingTransformer, and rename this class to Transformer.
The same TranscodingTransformer instance can be used to transform multiple inputs (sequentially, not concurrently).
TranscodingTransformer instances must be accessed from a single application thread. For the vast majority of cases this should be the application's main thread. The thread on which a TranscodingTransformer instance must be accessed can be explicitly specified by passing a
Looperwhen creating the transcoding transformer. If no Looper is specified, then the Looper of the thread that theTranscodingTransformer.Builderis created on is used, or if that thread does not have a Looper, the Looper of the application's main thread is used. In all cases the Looper of the thread from which the transcoding transformer must be accessed can be queried usinggetApplicationLooper().
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classTranscodingTransformer.BuilderA builder forTranscodingTransformerinstances.static interfaceTranscodingTransformer.ListenerA listener for the transformation events.static interfaceTranscodingTransformer.ProgressStateProgress state.
-
Field Summary
Fields Modifier and Type Field Description static intPROGRESS_STATE_AVAILABLEIndicates that the progress is available.static intPROGRESS_STATE_NO_TRANSFORMATIONIndicates that there is no current transformation.static intPROGRESS_STATE_UNAVAILABLEIndicates that the progress is permanently unavailable for the current transformation.static intPROGRESS_STATE_WAITING_FOR_AVAILABILITYIndicates that the progress is unavailable for the current transformation, but might become available.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description TranscodingTransformer.BuilderbuildUpon()Returns aTranscodingTransformer.Builderinitialized with the values of this instance.voidcancel()Cancels the transformation that is currently in progress, if any.LoopergetApplicationLooper()Returns theLooperassociated with the application thread that's used to access the transcoding transformer and on which transcoding transformer events are received.intgetProgress(ProgressHolder progressHolder)Returns the currentTranscodingTransformer.ProgressStateand updatesprogressHolderwith the current progress if it isavailable.voidsetListener(TranscodingTransformer.Listener listener)Sets theTranscodingTransformer.Listenerto listen to the transformation events.voidstartTransformation(MediaItem mediaItem, ParcelFileDescriptor parcelFileDescriptor)Starts an asynchronous operation to transform the givenMediaItem.voidstartTransformation(MediaItem mediaItem, String path)Starts an asynchronous operation to transform the givenMediaItem.
-
-
-
Field Detail
-
PROGRESS_STATE_WAITING_FOR_AVAILABILITY
public static final int PROGRESS_STATE_WAITING_FOR_AVAILABILITY
Indicates that the progress is unavailable for the current transformation, but might become available.- See Also:
- Constant Field Values
-
PROGRESS_STATE_AVAILABLE
public static final int PROGRESS_STATE_AVAILABLE
Indicates that the progress is available.- See Also:
- Constant Field Values
-
PROGRESS_STATE_UNAVAILABLE
public static final int PROGRESS_STATE_UNAVAILABLE
Indicates that the progress is permanently unavailable for the current transformation.- See Also:
- Constant Field Values
-
PROGRESS_STATE_NO_TRANSFORMATION
public static final int PROGRESS_STATE_NO_TRANSFORMATION
Indicates that there is no current transformation.- See Also:
- Constant Field Values
-
-
Method Detail
-
buildUpon
public TranscodingTransformer.Builder buildUpon()
Returns aTranscodingTransformer.Builderinitialized with the values of this instance.
-
setListener
public void setListener(TranscodingTransformer.Listener listener)
Sets theTranscodingTransformer.Listenerto listen to the transformation events.- Parameters:
listener- ATranscodingTransformer.Listener.- Throws:
IllegalStateException- If this method is called from the wrong thread.
-
startTransformation
public void startTransformation(MediaItem mediaItem, String path) throws IOException
Starts an asynchronous operation to transform the givenMediaItem.The transformation state is notified through the
listener.Concurrent transformations on the same TranscodingTransformer object are not allowed.
The output can contain at most one video track and one audio track. Other track types are ignored. For adaptive bitrate
media sources, the highest bitrate video and audio streams are selected.- Parameters:
mediaItem- TheMediaItemto transform. The supported sample formats depend on theMuxerand on the output container format. For theFrameworkMuxer, they are described inMediaMuxer.addTrack(MediaFormat).path- The path to the output file.- Throws:
IllegalArgumentException- If the path is invalid.IllegalStateException- If this method is called from the wrong thread.IllegalStateException- If a transformation is already in progress.IOException- If an error occurs opening the output file for writing.
-
startTransformation
@RequiresApi(26) public void startTransformation(MediaItem mediaItem, ParcelFileDescriptor parcelFileDescriptor) throws IOException
Starts an asynchronous operation to transform the givenMediaItem.The transformation state is notified through the
listener.Concurrent transformations on the same TranscodingTransformer object are not allowed.
The output can contain at most one video track and one audio track. Other track types are ignored. For adaptive bitrate
media sources, the highest bitrate video and audio streams are selected.- Parameters:
mediaItem- TheMediaItemto transform. The supported sample formats depend on theMuxerand on the output container format. For theFrameworkMuxer, they are described inMediaMuxer.addTrack(MediaFormat).parcelFileDescriptor- A readable and writableParcelFileDescriptorof the output. The file referenced by this ParcelFileDescriptor should not be used before the transformation is completed. It is the responsibility of the caller to close the ParcelFileDescriptor. This can be done after this method returns.- Throws:
IllegalArgumentException- If the file descriptor is invalid.IllegalStateException- If this method is called from the wrong thread.IllegalStateException- If a transformation is already in progress.IOException- If an error occurs opening the output file for writing.
-
getApplicationLooper
public Looper getApplicationLooper()
Returns theLooperassociated with the application thread that's used to access the transcoding transformer and on which transcoding transformer events are received.
-
getProgress
@ProgressState public int getProgress(ProgressHolder progressHolder)
Returns the currentTranscodingTransformer.ProgressStateand updatesprogressHolderwith the current progress if it isavailable.After a transformation
completes, this method returnsPROGRESS_STATE_NO_TRANSFORMATION.- Parameters:
progressHolder- AProgressHolder, updated to hold the percentage progress ifavailable.- Returns:
- The
TranscodingTransformer.ProgressState. - Throws:
IllegalStateException- If this method is called from the wrong thread.
-
cancel
public void cancel()
Cancels the transformation that is currently in progress, if any.- Throws:
IllegalStateException- If this method is called from the wrong thread.
-
-