public class Extractor extends Object
This class is used together with other classes to implement different functions. Example scenarios:
1. Working with the Muxer class: The Extractor class separates multimedia
audio and video sources, and the Muxer class combines the data sources into a new media
file.
2. Working with the Codec class: The Extractor class separates multimedia
audio and video data sources, and the Codec class decodes
the audio and video data in the data sources, and encodes the decoded data into the required output format.
Example code:
Source source = new Source(...);
Extractor extractor = new Extractor();
extractor.setSource(source);
int trackCount = extractor.getTotalStreams();
for (int i = 0; i < trackCount, i++) {
extractor.specifyStream(i);
Format format = extractor.getStreamFormat();
}
ByteBuffer byteBuffer = ByteBuffer.allocate(size);
while(extractor.readBuffer(byteBuffer, 0) > 0) {
extractor.getFrameTimestamp();
extractor.getFrameType();
extractor.next();
}
extractor.release();
SystemCapability.Multimedia#MEDIA| 限定符和类型 | 字段 | 说明 |
|---|---|---|
static int |
REWIND_TO_CLOSEST_SYNC |
Indicates the closest key frame of a specified frame.
|
static int |
REWIND_TO_NEXT_SYNC |
Indicates the next key frame of a specified frame.
|
static int |
REWIND_TO_PREVIOUS_SYNC |
Indicates the previous key frame of a specified frame.
|
| 构造器 | 说明 |
|---|---|
Extractor() |
Default constructor used to create an
Extractor instance. |
| 限定符和类型 | 方法 | 说明 |
|---|---|---|
protected void |
finalize() |
Called by the garbage collector on an object when garbage collection
determines that there are no more references to the object.
|
long |
getFrameSize() |
Obtains the size of a data source, in bytes.
|
long |
getFrameTimestamp() |
Obtains the time point of a data source, in milliseconds.
|
int |
getFrameType() |
Obtains the type of a data source.
|
Format |
getStreamFormat(int id) |
Obtains the data format of a stream.
|
int |
getStreamId() |
Obtains the ID of the track to which the data source belongs.
|
int |
getTotalStreams() |
Obtains the total number of tracks in a media file.
|
boolean |
next() |
Rewinds to the next frame.
|
int |
readBuffer(ByteBuffer buf,
int offset) |
Reads demultiplexed data.
|
boolean |
release() |
Releases resources.
|
boolean |
rewindTo(long microseconds,
int mode) |
Rewinds to a specified frame based on the time and mode.
|
boolean |
setSource(Source source) |
Sets the media playback source.
|
boolean |
specifyStream(int id) |
Selects a track in a media file.
|
boolean |
unspecifyStream(int id) |
Deselects a track.
|
public static final int REWIND_TO_CLOSEST_SYNC
public static final int REWIND_TO_NEXT_SYNC
public static final int REWIND_TO_PREVIOUS_SYNC
public Extractor()
Extractor instance.public boolean setSource(Source source)
This method must be called prior to other methods of the Extractor class.
source - Indicates the source of the media to demultiplex.true if the setting is successful; returns false otherwise.IllegalArgumentException - Throws this exception if a parameter is invalid.public final Format getStreamFormat(int id)
Format.id - Indicates a stream ID, which is a non-negative number.IllegalArgumentException - Throws this exception if a parameter is invalid.public final int getTotalStreams()
public boolean specifyStream(int id)
id - Indicates a track ID, which is a non-negative number.true if the track is selected; returns false otherwise.IllegalArgumentException - Throws this exception if a parameter is invalid.public boolean unspecifyStream(int id)
To reselect a track that has been selected, you must first deselect it.
id - Indicates a track ID.true if the track is deselected; returns false otherwise.IllegalArgumentException - Throws this exception if a parameter is invalid.public boolean rewindTo(long microseconds,
int mode)
This method can be called before, during, and after a media file is played.
microseconds - Indicates the time point, in microseconds. It is a non-negative number.mode - Indicates the rewinding mode.
true if the rewinding operation is successful; returns false otherwise.public boolean next()
true if the rewinding operation is successful; returns false otherwise.public int readBuffer(ByteBuffer buf, int offset)
Before calling this method, you must call specifyStream() to select a track.
buf - Indicates the buffer from which data is read.offset - Indicates the start position of the data in the buffer, which is a non-negative number.-1 if no data has been read.public int getStreamId()
public long getFrameTimestamp()
-1 if no sample is available.public long getFrameSize()
-1 if no data is available.public int getFrameType()
0 if an exception occurs.
type: SAMPLE_FLAG_SYNC - Indicates that a key frame is read from the buffer.
SAMPLE_FLAG_ENCRYPTED - Indicates that an encrypted frame is read from the buffer.
SAMPLE_FLAG_PARTIAL_FRAME - Indicates that an incomplete frame is read from the buffer.
public boolean release()
true if the resources are released; returns false otherwise.protected void finalize()
throws Throwable
Objectfinalize method to dispose of
system resources or to perform other cleanup.
The general contract of finalize is that it is invoked
if and when the Java™ virtual
machine has determined that there is no longer any
means by which this object can be accessed by any thread that has
not yet died, except as a result of an action taken by the
finalization of some other object or class which is ready to be
finalized. The finalize method may take any action, including
making this object available again to other threads; the usual purpose
of finalize, however, is to perform cleanup actions before
the object is irrevocably discarded. For example, the finalize method
for an object that represents an input/output connection might perform
explicit I/O transactions to break the connection before the object is
permanently discarded.
The finalize method of class Object performs no
special action; it simply returns normally. Subclasses of
Object may override this definition.
The Java programming language does not guarantee which thread will
invoke the finalize method for any given object. It is
guaranteed, however, that the thread that invokes finalize will not
be holding any user-visible synchronization locks when finalize is
invoked. If an uncaught exception is thrown by the finalize method,
the exception is ignored and finalization of that object terminates.
After the finalize method has been invoked for an object, no
further action is taken until the Java virtual machine has again
determined that there is no longer any means by which this object can
be accessed by any thread that has not yet died, including possible
actions by other objects or classes which are ready to be finalized,
at which point the object may be discarded.
The finalize method is never invoked more than once by a Java
virtual machine for any given object.
Any exception thrown by the finalize method causes
the finalization of this object to be halted, but is otherwise
ignored.
finalize 在类中 ObjectThrowable - the Exception raised by this methodWeakReference,
PhantomReference