Class IContainer
- java.lang.Object
-
- com.avpkit.ferry.RefCounted
-
- com.avpkit.core.IContainer
-
- All Implemented Interfaces:
IConfigurable
public class IContainer extends RefCounted implements IConfigurable
A file (or network data source) that contains one or more {IStream}
objects of
audio and video data.
Typical usage for reading looks like this:
IContainer container = IContainer.make();
if (container.open("myfile.flv", IContainer.Type.READ, null) <0)
throw new RuntimeException("failed to open");
int numStreams = container.getNumStreams();
for(i = 0; i < numStreams; i++) {
IStream stream = container.getStream(i);
...query IStream for stream information...
}
IPacket packet = IPacket.make();
while(container.readNextPacket(packet) >= 0)
{
... Do something with the packet...
}
container.close();
Typical usage for writing looks like this (makes an FLV file
with one audio track encoded as mp3 data):
IContainer container = IContainer.make();
if (container.open("myfile.flv", IContainer.Type.WRITE, null) <0)
throw new RuntimeException("failed to open");
IStream stream = container.addNewStream(0);
IStreamCoder coder = stream.getStreamCoder();
coder.setCodec(ICodec.ID.AV_CODEC_ID_MP3);
coder.setSampleRate(22050);
coder.setChannels(2);
coder.setBitRate(64000);
if (coder.open()<0) throw new RuntimeException("could not open coder");
if (container.writeHeader() < 0) throw new RuntimeException();
IPacket packet = IPacket.make();
while( ... have more data to process ... ) {
... Use the coder to encode audio data into packets
then assuming it generated an IPacket for you...
if (container.writePacket(packet)<0)
throw new RuntimeException("could not write packet");
}
if (container.writeTrailer() <0) throw new RuntimeException();
container.close();
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classIContainer.Flagsstatic classIContainer.TypeThe different types of Containers AVPKit supports.
-
Field Summary
Fields Modifier and Type Field Description static intSEEK_FLAG_ANYFlag; Seek to any frame, even non-keyframesstatic intSEEK_FLAG_BACKWARDSFlag; Seek backwardsstatic intSEEK_FLAG_BYTEFlag; Use bytes instead of time stamps for seekingstatic intSEEK_FLAG_FRAMEFlag; Seek based on frame number instead of time stamps-
Fields inherited from class com.avpkit.ferry.RefCounted
swigCMemOwn
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedIContainer(long cPtr, boolean cMemoryOwn)Internal Only.protectedIContainer(long cPtr, boolean cMemoryOwn, java.util.concurrent.atomic.AtomicLong ref)Internal Only.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description IStreamaddNewStream(int id)Deprecated.Use {#addNewStream(ICodec.ID)} instead.
Creates a new stream in this container and returns it.
IStreamaddNewStream(ICodec codec)Add a new stream that will use the given codec.
IStreamaddNewStream(ICodec.ID id)Add a new stream that will use the given codec.
IStreamaddNewStream(IStreamCoder coder)Add a new stream that will use the given StreamCoder.booleancanStreamsBeAddedDynamically()Can streams be added dynamically to this container?
intclose()Close the container.intclose(boolean dangling)Close the container.IContainercopyReference()Create a new IContainer object that is actually referring to the exact same underlying native object.java.lang.StringcreateSDPData()Gets the SDP data as a Java string.intcreateSDPData(IBuffer buffer)Fills the given buffer with a null-terminated ASCII
set of bytes representing SDP data that
is suitable for use with an RTSP-based system.booleanequals(java.lang.Object obj)Compares two values, returning true if the underlying objects in native code are the same object.intflushPackets()Flush all packets to output.intgetBitRate()Get the calculated overall bit rate of this file.IContainerFormatgetContainerFormat()Returns the IContainerFormat object being used for this IContainer,
or null if the {IContainer} doesn't yet know.
static longgetCPtr(IContainer obj)Internal Only.longgetDuration()Gets the duration, if known, of this container.
This will only work for non-streamable containers where IContainer
can calculate the container size.
longgetFileSize()Get the file size in bytes of this container.
This will only return a valid value if the container is non-streamed and supports seek.
booleangetFlag(IContainer.Flags flag)Get the setting for the specified flag
intgetFlags()Get the flags associated with this object.
IContainerFormatgetFormat()Get the {IContainerFormat} that is used by this {IContainer}.
intgetInputBufferLength()Return the input buffer length.
intgetMaxDelay()Gets the AVFormatContext.max_delay property if possible.IMetaDatagetMetaData()Get the {IMetaData} for this object,
or null if none.longgetMyCPtr()Internal Only.intgetNumProperties()Returns the total number of settable properties on this object
intgetNumStreams()The number of streams in this container.intgetPreload()Deprecated.use {#getPropertyAsLong} instead.
The amount container will attemtp to preload.
booleangetPropertyAsBoolean(java.lang.String name)Gets the value of this property, and returns as a boolean
doublegetPropertyAsDouble(java.lang.String name)Gets the value of this property, and returns as a double;
longgetPropertyAsLong(java.lang.String name)Gets the value of this property, and returns as an long;
IRationalgetPropertyAsRational(java.lang.String name)Gets the value of this property, and returns as an IRational;
java.lang.StringgetPropertyAsString(java.lang.String name)Gets a property on this Object.
IPropertygetPropertyMetaData(int propertyNo)Returns the name of the numbered property.
IPropertygetPropertyMetaData(java.lang.String name)Returns the name of the numbered property.
java.util.Collection<java.lang.String>getPropertyNames()Gets a collection of all properties settable on this object.intgetReadRetryCount()Get the number of times {IContainer#readNextPacket(IPacket)}
will retry a read if it gets a {IError.Type#ERROR_AGAIN}
value back.
Defaults to 1 times.IStreamCoder.CodecStandardsCompliancegetStandardsCompliance()Gets the current level of standards compliance.longgetStartTime()Get the starting timestamp in microseconds of the first packet of the earliest stream in this container.IStreamgetStream(int streamIndex)Get the stream at the given position.
IContainer.TypegetType()Find out the type of this container.
java.lang.StringgetURL()Get the URL the IContainer was opened with.
May return null if unknown.inthashCode()Get a hashable value for this object.booleanisHeaderWritten()Has a header been successfully written?booleanisOpened()Is this container opened?static IContainermake()Create a new container object.
static IContainermake(IContainerFormat format)Create a new {IContainer} and call {#setFormat(IContainerFormat)} on it immediately.intopen(IURLProtocolHandler handler, IContainer.Type type, IContainerFormat format)Open this container and make it ready for reading or writing.intopen(IURLProtocolHandler handler, IContainer.Type type, IContainerFormat format, boolean streamsCanBeAddedDynamically, boolean queryStreamMetaData)Open this container and make it ready for reading or writing, optionally reading as far into the container as necessary to find all streams.intopen(java.io.DataInput input, IContainerFormat format)Open this container and make it ready for reading.intopen(java.io.DataInput input, IContainerFormat format, boolean streamsCanBeAddedDynamically, boolean queryStreamMetaData)Open this container and make it ready for reading.intopen(java.io.DataInputStream input, IContainerFormat format)Open this container and make it ready for reading.intopen(java.io.DataInputStream input, IContainerFormat format, boolean streamsCanBeAddedDynamically, boolean queryStreamMetaData)Open this container and make it ready for reading.intopen(java.io.DataOutput output, IContainerFormat format)Open this container and make it ready for writing.intopen(java.io.DataOutput output, IContainerFormat format, boolean streamsCanBeAddedDynamically, boolean queryStreamMetaData)Open this container and make it ready for writing.intopen(java.io.DataOutputStream output, IContainerFormat format)Open this container and make it ready for writing.intopen(java.io.DataOutputStream output, IContainerFormat format, boolean streamsCanBeAddedDynamically, boolean queryStreamMetaData)Open this container and make it ready for writing.intopen(java.io.InputStream input, IContainerFormat format)Open this container and make it ready for reading.intopen(java.io.InputStream input, IContainerFormat format, boolean streamsCanBeAddedDynamically, boolean queryStreamMetaData)Open this container and make it ready for reading.intopen(java.io.OutputStream output, IContainerFormat format)Open this container and make it ready for writing.intopen(java.io.OutputStream output, IContainerFormat format, boolean streamsCanBeAddedDynamically, boolean queryStreamMetaData)Open this container and make it ready for writing.intopen(java.io.RandomAccessFile file, IContainer.Type type, IContainerFormat format)Open this container and make it ready for reading or writing.intopen(java.io.RandomAccessFile file, IContainer.Type type, IContainerFormat format, boolean streamsCanBeAddedDynamically, boolean queryStreamMetaData)Open this container and make it ready for reading or writing.intopen(java.lang.String url, IContainer.Type type, IContainerFormat pContainerFormat)Open this container and make it ready for reading or writing.intopen(java.lang.String url, IContainer.Type type, IContainerFormat pContainerFormat, boolean aStreamsCanBeAddedDynamically, boolean aQueryStreamMetaData)Open this container and make it ready for reading or writing, optionally
reading as far into the container as necessary to find all streams.intopen(java.lang.String url, IContainer.Type type, IContainerFormat containerFormat, boolean streamsCanBeAddedDynamically, boolean queryStreamMetaData, IMetaData options, IMetaData optionsNotSet)Open this container and make it ready for reading or writing, optionally
reading as far into the container as necessary to find all streams.intopen(java.nio.channels.ByteChannel channel, IContainer.Type type, IContainerFormat format)Open this container and make it ready for reading or writing.intopen(java.nio.channels.ByteChannel channel, IContainer.Type type, IContainerFormat format, boolean streamsCanBeAddedDynamically, boolean queryStreamMetaData)Open this container and make it ready for reading or writing.intopen(java.nio.channels.ReadableByteChannel input, IContainerFormat format)Open this container and make it ready for reading.intopen(java.nio.channels.ReadableByteChannel input, IContainerFormat format, boolean streamsCanBeAddedDynamically, boolean queryStreamMetaData)Open this container and make it ready for reading.intopen(java.nio.channels.WritableByteChannel output, IContainerFormat format)Open this container and make it ready for writing.intopen(java.nio.channels.WritableByteChannel output, IContainerFormat format, boolean streamsCanBeAddedDynamically, boolean queryStreamMetaData)Open this container and make it ready for writing.intqueryStreamMetaData()Attempts to read all the meta data in this stream, potentially by reading ahead
and decoding packets.intreadNextPacket(IPacket packet)Reads the next packet into the IPacket.intseekKeyFrame(int streamIndex, long timestamp, int flags)Seeks to the key frame at (or the first one after) the given timestamp.intseekKeyFrame(int streamIndex, long minTimeStamp, long targetTimeStamp, long maxTimeStamp, int flags)EXPERIMENTAL - Seeks to timestamp in the container.intsetCustomURLHandlerFactory(IURLProtocolHandlerFactory factory)voidsetFlag(IContainer.Flags flag, boolean value)Set the flag.
voidsetFlags(int newFlags)Set the flags to use with this object.intsetForcedAudioCodec(ICodec.ID id)Forces the {IContainer} to assume all audio streams are
encoded with the given audio codec when demuxing.intsetForcedSubtitleCodec(ICodec.ID id)Forces the {IContainer} to assume all subtitle streams are
encoded with the given subtitle codec when demuxing.intsetForcedVideoCodec(ICodec.ID id)Forces the {IContainer} to assume all video streams are
encoded with the given video codec when demuxing.intsetFormat(IContainerFormat format)Set the {IContainerFormat} to use with this {IContainer}.intsetInputBufferLength(int size)Set the buffer length AVPKit will suggest to FFMPEG for reading inputs.
If called when a IContainer is open, the call is ignored and -1 is returned.
intsetMaxDelay(int maxdelay)Sets the max delay for the AVFormatContext.max_delay property.
voidsetMetaData(IMetaData data)Set the {IMetaData} on this object, overriding
any previous meta data.intsetPreload(int preload)Deprecated.use {#setProperty} instead.
If the container has not already been opened, sets the AVFormatContext.preload property
which can be useful in some circumstances such as when dealing with mpeg formats.
intsetProperty(IMetaData valuesToSet, IMetaData valuesNotFound){intsetProperty(java.lang.String name, boolean value)Looks up the property 'name' and sets the
value of the property to 'value'.
intsetProperty(java.lang.String name, double value)Looks up the property 'name' and sets the
value of the property to 'value'.
intsetProperty(java.lang.String name, long value)Looks up the property 'name' and sets the
value of the property to 'value'.
intsetProperty(java.lang.String name, IRational value)Looks up the property 'name' and sets the
value of the property to 'value'.
intsetProperty(java.lang.String name, java.lang.String value)Sets a property on this Object.
All AVOptions supported by the underlying AVClass are supported.
voidsetReadRetryCount(int count)Sets the read retry count.
intsetStandardsCompliance(IStreamCoder.CodecStandardsCompliance compliance)Set the level of standards compliance.java.lang.StringtoString()info about this container.intwriteHeader()Adds a header, if needed, for this container.intwritePacket(IPacket packet)Writes the contents of the packet to the container, but make sure the
packets are interleaved.intwritePacket(IPacket packet, boolean forceInterleave)Writes the contents of the packet to the container.intwriteTrailer()Adds a trailer, if needed, for this container.
Call this AFTER you've written all data you're going to write
to this container but BEFORE you call
{IStreamCoder#close()} on your {IStreamCoder}
objects.-
Methods inherited from class com.avpkit.ferry.RefCounted
acquire, delete, getCPtr, getCurrentRefCount, getJavaRefCount, release
-
-
-
-
Field Detail
-
SEEK_FLAG_BACKWARDS
public static final int SEEK_FLAG_BACKWARDS
Flag; Seek backwards
-
SEEK_FLAG_BYTE
public static final int SEEK_FLAG_BYTE
Flag; Use bytes instead of time stamps for seeking
-
SEEK_FLAG_ANY
public static final int SEEK_FLAG_ANY
Flag; Seek to any frame, even non-keyframes
-
SEEK_FLAG_FRAME
public static final int SEEK_FLAG_FRAME
Flag; Seek based on frame number instead of time stamps
-
-
Constructor Detail
-
IContainer
protected IContainer(long cPtr, boolean cMemoryOwn)
Internal Only.
-
IContainer
protected IContainer(long cPtr, boolean cMemoryOwn, java.util.concurrent.atomic.AtomicLong ref)
Internal Only.
-
-
Method Detail
-
getCPtr
public static long getCPtr(IContainer obj)
Internal Only. Not part of public API. Get the raw value of the native object that obj is proxying for.- Parameters:
obj- The java proxy object for a native object.- Returns:
- The raw pointer obj is proxying for.
-
getMyCPtr
public long getMyCPtr()
Internal Only. Not part of public API. Get the raw value of the native object that we're proxying for.- Overrides:
getMyCPtrin classRefCounted- Returns:
- The raw pointer we're proxying for.
-
copyReference
public IContainer copyReference()
Create a new IContainer object that is actually referring to the exact same underlying native object.- Overrides:
copyReferencein classRefCounted- Returns:
- the new Java object.
-
equals
public boolean equals(java.lang.Object obj)
Compares two values, returning true if the underlying objects in native code are the same object. That means you can have two different Java objects, but when you do a comparison, you'll find out they are the EXACT same object.- Overrides:
equalsin classjava.lang.Object- Returns:
- True if the underlying native object is the same. False otherwise.
-
hashCode
public int hashCode()
Get a hashable value for this object.- Overrides:
hashCodein classjava.lang.Object- Returns:
- the hashable value.
-
toString
public java.lang.String toString()
info about this container. We only print information that can be determined without reading data from the container.- Overrides:
toStringin classjava.lang.Object- Returns:
- a string representation of this object
-
open
public int open(IURLProtocolHandler handler, IContainer.Type type, IContainerFormat format)
Open this container and make it ready for reading or writing. Reading or writing ability is determined by what theIURLProtocolHandlerpassed in supports.
-
open
public int open(java.io.OutputStream output, IContainerFormat format)
Open this container and make it ready for writing.
-
open
public int open(java.io.InputStream input, IContainerFormat format)
Open this container and make it ready for reading.
-
open
public int open(java.io.DataOutput output, IContainerFormat format)
Open this container and make it ready for writing.
-
open
public int open(java.io.DataOutputStream output, IContainerFormat format)
Open this container and make it ready for writing.
-
open
public int open(java.io.DataInput input, IContainerFormat format)
Open this container and make it ready for reading.
-
open
public int open(java.io.DataInputStream input, IContainerFormat format)
Open this container and make it ready for reading.
-
open
public int open(java.io.RandomAccessFile file, IContainer.Type type, IContainerFormat format)
Open this container and make it ready for reading or writing.
-
open
public int open(java.nio.channels.WritableByteChannel output, IContainerFormat format)
Open this container and make it ready for writing.
-
open
public int open(java.nio.channels.ReadableByteChannel input, IContainerFormat format)
Open this container and make it ready for reading.
-
open
public int open(java.nio.channels.ByteChannel channel, IContainer.Type type, IContainerFormat format)
Open this container and make it ready for reading or writing.
-
open
public int open(IURLProtocolHandler handler, IContainer.Type type, IContainerFormat format, boolean streamsCanBeAddedDynamically, boolean queryStreamMetaData)
Open this container and make it ready for reading or writing, optionally reading as far into the container as necessary to find all streams.
-
open
public int open(java.io.OutputStream output, IContainerFormat format, boolean streamsCanBeAddedDynamically, boolean queryStreamMetaData)
Open this container and make it ready for writing.
-
open
public int open(java.io.InputStream input, IContainerFormat format, boolean streamsCanBeAddedDynamically, boolean queryStreamMetaData)
Open this container and make it ready for reading.
-
open
public int open(java.io.DataOutput output, IContainerFormat format, boolean streamsCanBeAddedDynamically, boolean queryStreamMetaData)
Open this container and make it ready for writing.
-
open
public int open(java.io.DataOutputStream output, IContainerFormat format, boolean streamsCanBeAddedDynamically, boolean queryStreamMetaData)
Open this container and make it ready for writing.
-
open
public int open(java.io.DataInput input, IContainerFormat format, boolean streamsCanBeAddedDynamically, boolean queryStreamMetaData)
Open this container and make it ready for reading.
-
open
public int open(java.io.DataInputStream input, IContainerFormat format, boolean streamsCanBeAddedDynamically, boolean queryStreamMetaData)
Open this container and make it ready for reading.
-
open
public int open(java.io.RandomAccessFile file, IContainer.Type type, IContainerFormat format, boolean streamsCanBeAddedDynamically, boolean queryStreamMetaData)
Open this container and make it ready for reading or writing.
-
open
public int open(java.nio.channels.WritableByteChannel output, IContainerFormat format, boolean streamsCanBeAddedDynamically, boolean queryStreamMetaData)
Open this container and make it ready for writing.
-
open
public int open(java.nio.channels.ReadableByteChannel input, IContainerFormat format, boolean streamsCanBeAddedDynamically, boolean queryStreamMetaData)
Open this container and make it ready for reading.
-
open
public int open(java.nio.channels.ByteChannel channel, IContainer.Type type, IContainerFormat format, boolean streamsCanBeAddedDynamically, boolean queryStreamMetaData)
Open this container and make it ready for reading or writing.
-
setCustomURLHandlerFactory
public int setCustomURLHandlerFactory(IURLProtocolHandlerFactory factory)
-
createSDPData
public java.lang.String createSDPData()
Gets the SDP data as a Java string.This method only supports SDP files up to 4K in size. If you have a larger SDP file, use the
createSDPData(com.avpkit.ferry.IBuffer)method and pass in your ownIBufferobject.- Returns:
- A
Stringrepresenting the data. - See Also:
createSDPData(IBuffer)
-
getPropertyNames
public java.util.Collection<java.lang.String> getPropertyNames()
Gets a collection of all properties settable on this object. You can then query current settings withIConfigurable.getPropertyAsString(String)and set properties withIConfigurable.setProperty(String, String).- Specified by:
getPropertyNamesin interfaceIConfigurable- Returns:
- a collection of all properties for this object.
-
setInputBufferLength
public int setInputBufferLength(int size)
Set the buffer length AVPKit will suggest to FFMPEG for reading inputs.
If called when a IContainer is open, the call is ignored and -1 is returned.
- Parameters:
size- The suggested buffer size.- Returns:
- size on success; <0 on error.
-
getInputBufferLength
public int getInputBufferLength()
Return the input buffer length.
- Returns:
- The input buffer length AVPKit's told FFMPEG to assume.
0 means FFMPEG should choose it's own
size (and it'll probably be 32768).
-
isOpened
public boolean isOpened()
Is this container opened?- Returns:
- true if opened; false if not.
-
isHeaderWritten
public boolean isHeaderWritten()
Has a header been successfully written?- Returns:
- true if yes, false if no.
-
open
public int open(java.lang.String url, IContainer.Type type, IContainerFormat pContainerFormat)
Open this container and make it ready for reading or writing.
The caller must call {#close()} when done, but if not, the
{IContainer} will eventually close
them later but warn to the logging system.
This just forwards to {#open(String, Type, IContainerFormat, boolean, boolean)}
passing false for aStreamsCanBeAddedDynamically, and true for aLookForAllStreams.
If the current thread is interrupted while this blocking method
is running the method will return with a negative value.
To check if the method exited because of an interruption
pass the return value to {IError#make(int)} and then
check {IError#getType()} to see if it is
{IError.Type#ERROR_INTERRUPTED}.
- Parameters:
url- The resource to open; The format of this string is any
url that FFMPEG supports (including additional protocols if added
through the core.io library).type- The type of this container.pContainerFormat- A pointer to a ContainerFormat object specifying
the format of this container, or 0 (NULL) if you want us to guess.
- Returns:
- >= 0 on success; < 0 on error.
-
open
public int open(java.lang.String url, IContainer.Type type, IContainerFormat pContainerFormat, boolean aStreamsCanBeAddedDynamically, boolean aQueryStreamMetaData)
Open this container and make it ready for reading or writing, optionally
reading as far into the container as necessary to find all streams.
The caller must call {#close()} when done, but if not, the
{IContainer} will eventually close
them later but warn to the logging system.
If the current thread is interrupted while this blocking method
is running the method will return with a negative value.
To check if the method exited because of an interruption
pass the return value to {IError#make(int)} and then
check {IError#getType()} to see if it is
{IError.Type#ERROR_INTERRUPTED}.
- Parameters:
url- The resource to open; The format of this string is any
url that FFMPEG supports (including additional protocols if added
through the core.io library).type- The type of this container.pContainerFormat- A pointer to a ContainerFormat object specifying
the format of this container, or 0 (NULL) if you want us to guess.aStreamsCanBeAddedDynamically- If true, open() will expect that new
streams can be added at any time, even after the format header has been read.aQueryStreamMetaData- If true, open() will call {#queryStreamMetaData()}
on this container, which will potentially block until it has ready
enough data to find all streams in a container. If false, it will only
block to read a minimal header for this container format.
- Returns:
- >= 0 on success; < 0 on error.
-
getStandardsCompliance
public IStreamCoder.CodecStandardsCompliance getStandardsCompliance()
Gets the current level of standards compliance.- Returns:
- The level of standards compliance.
- Since:
- 5.7
- See Also:
CodecStandardsCompliance
-
setStandardsCompliance
public int setStandardsCompliance(IStreamCoder.CodecStandardsCompliance compliance)
Set the level of standards compliance. Only paid attention to
before the code is opened.
- Parameters:
compliance- The desired compliance level to set- Returns:
- 0 on success; non-zero on failure
- Since:
- 5.7
- See Also:
CodecStandardsCompliance
-
getContainerFormat
public IContainerFormat getContainerFormat()
Returns the IContainerFormat object being used for this IContainer,
or null if the {IContainer} doesn't yet know.
- Returns:
- the IContainerFormat object, or null.
-
close
public int close(boolean dangling)
Close the container. open() must have been called first, or
else an error is returned.If the current thread is interrupted while this blocking method
is running the method will return with a negative value.
To check if the method exited because of an interruption
pass the return value to {IError#make(int)} and then
check {IError#getType()} to see if it is
{IError.Type#ERROR_INTERRUPTED}.
If this method exits because of an interruption,
all resources will be closed anyway.
- Returns:
- >= 0 on success; < 0 on error.
-
close
public int close()
Close the container. open() must have been called first, or
else an error is returned.If the current thread is interrupted while this blocking method
is running the method will return with a negative value.
To check if the method exited because of an interruption
pass the return value to {IError#make(int)} and then
check {IError#getType()} to see if it is
{IError.Type#ERROR_INTERRUPTED}.
If this method exits because of an interruption,
all resources will be closed anyway.
- Returns:
- >= 0 on success; < 0 on error.
-
getType
public IContainer.Type getType()
Find out the type of this container.
- Returns:
- The Type of this container.
{IContainer.Type#READ} if not yet opened.
-
getNumStreams
public int getNumStreams()
The number of streams in this container.
If opened in {IContainer.Type#READ} mode, this will query the stream and find out
how many streams are in it.If opened in
{IContainer.Type#WRITE} mode, this will return the number of streams
the caller has added to date.If the current thread is interrupted while this blocking method
is running the method will return with a negative value.
To check if the method exited because of an interruption
pass the return value to {IError#make(int)} and then
check {IError#getType()} to see if it is
{IError.Type#ERROR_INTERRUPTED}.
- Returns:
- The number of streams in this container.
-
getStream
public IStream getStream(int streamIndex)
Get the stream at the given position.
- Parameters:
streamIndex- the index of this stream in the container- Returns:
- The stream at that position in the container, or null if none there.
-
addNewStream
@Deprecated public IStream addNewStream(int id)
Deprecated.Use {#addNewStream(ICodec.ID)} instead.
Creates a new stream in this container and returns it.
- Parameters:
id- A format-dependent id for this stream.
- Returns:
- A new stream.
-
writeHeader
public int writeHeader()
Adds a header, if needed, for this container.
Call this AFTER you've added all streams you want to add,
opened all IStreamCoders for those streams (with proper
configuration) and
before you write the first frame. If you attempt to write
a header but haven't opened all codecs, this method will log
a warning, and your output file will likely be corrupt.
If the current thread is interrupted while this blocking method
is running the method will return with a negative value.
To check if the method exited because of an interruption
pass the return value to {IError#make(int)} and then
check {IError#getType()} to see if it is
{IError.Type#ERROR_INTERRUPTED}.
- Returns:
- 0 if successful. < 0 if not. Always -1 if this is
a READ container.
-
writeTrailer
public int writeTrailer()
Adds a trailer, if needed, for this container.
Call this AFTER you've written all data you're going to write
to this container but BEFORE you call
{IStreamCoder#close()} on your {IStreamCoder}
objects.
You must call {#writeHeader()} before you call
this (and if you don't, the {IContainer}
will warn loudly and not
actually write the trailer).
If you have closed any of the {IStreamCoder} objects
that were open when you called
{#writeHeader()}, then this method will fail.
If the current thread is interrupted while this blocking method
is running the method will return with a negative value.
To check if the method exited because of an interruption
pass the return value to {IError#make(int)} and then
check {IError#getType()} to see if it is
{IError.Type#ERROR_INTERRUPTED}.
- Returns:
- 0 if successful. < 0 if not. Always <0 if this is
a READ container.
-
readNextPacket
public int readNextPacket(IPacket packet)
Reads the next packet into the IPacket. This method will
release any buffers currently held by this packet and allocate
new ones.
If the current thread is interrupted while this blocking method
is running the method will return with a negative value.
To check if the method exited because of an interruption
pass the return value to {IError#make(int)} and then
check {IError#getType()} to see if it is
{IError.Type#ERROR_INTERRUPTED}.
- Parameters:
packet- [In/Out] The packet the IContainer will read into.
- Returns:
- 0 if successful, or <0 if not.
-
writePacket
public int writePacket(IPacket packet, boolean forceInterleave)
Writes the contents of the packet to the container.
If the current thread is interrupted while this blocking method
is running the method will return with a negative value.
To check if the method exited because of an interruption
pass the return value to {IError#make(int)} and then
check {IError#getType()} to see if it is
{IError.Type#ERROR_INTERRUPTED}.
- Parameters:
packet- [In] The packet to write out.forceInterleave- [In] If true, then this {IContainer} will
make sure all packets
are interleaved by DTS (even across streams in a container).
If false, the {IContainer} won't,
and it's up to the caller to interleave if necessary.
- Returns:
- # of bytes written if successful, or <0 if not.
-
writePacket
public int writePacket(IPacket packet)
Writes the contents of the packet to the container, but make sure the
packets are interleaved.
This means the {IContainer} may have to queue up packets from one
stream while waiting for packets from another.
If the current thread is interrupted while this blocking method
is running the method will return with a negative value.
To check if the method exited because of an interruption
pass the return value to {IError#make(int)} and then
check {IError#getType()} to see if it is
{IError.Type#ERROR_INTERRUPTED}.
- Parameters:
packet- [In] The packet to write out.
- Returns:
- # of bytes written if successful, or <0 if not.
-
make
public static IContainer make()
Create a new container object.
- Returns:
- a new container, or null on error.
-
queryStreamMetaData
public int queryStreamMetaData()
Attempts to read all the meta data in this stream, potentially by reading ahead
and decoding packets.
Any packets this method reads ahead will be cached and correctly returned when you
read packets, but this method can be non-blocking potentially until end of container
to get all meta data. Take care when you call it.
After this method is called, other meta data methods like {#getDuration()} should
work.If the current thread is interrupted while this blocking method
is running the method will return with a negative value.
To check if the method exited because of an interruption
pass the return value to {IError#make(int)} and then
check {IError#getType()} to see if it is
{IError.Type#ERROR_INTERRUPTED}.
- Returns:
- >= 0 on success; <0 on failure.
-
seekKeyFrame
public int seekKeyFrame(int streamIndex, long timestamp, int flags)
Seeks to the key frame at (or the first one after) the given timestamp. This method will
always fail for any IContainer that is not seekable (e.g. is streamed). When successful
the next call to {#readNextPacket(IPacket)} will get the next keyframe from the
sought for stream.If the current thread is interrupted while this blocking method
is running the method will return with a negative value.
To check if the method exited because of an interruption
pass the return value to {IError#make(int)} and then
check {IError#getType()} to see if it is
{IError.Type#ERROR_INTERRUPTED}.
WARNING:: This method will be deprecated
in a future AVPKit release and replaced with the new
API {#seekKeyFrame(int, long, long, long, int)}.
- Parameters:
streamIndex- The stream to search for the keyframe in; must be a
stream the IContainer has either queried
meta-data about or already ready a packet for.timestamp- The timestamp, in the timebase of the stream you're looking in (not necessarily Microseconds).flags- Flags to pass to com.avpkit.core.io.IURLProtocolHandler's seek method.
- Returns:
- >= 0 on success; <0 on failure.
-
getDuration
public long getDuration()
Gets the duration, if known, of this container.
This will only work for non-streamable containers where IContainer
can calculate the container size.
- Returns:
- The duration, or {Global#NO_PTS} if not known.
-
getStartTime
public long getStartTime()
Get the starting timestamp in microseconds of the first packet of the earliest stream in this container.
This will only return value values either either (a) for non-streamable
containers where IContainer can calculate the container size or
(b) after IContainer has actually read the
first packet from a streamable source.
- Returns:
- The starting timestamp in microseconds, or {Global#NO_PTS} if not known.
-
getFileSize
public long getFileSize()
Get the file size in bytes of this container.
This will only return a valid value if the container is non-streamed and supports seek.
- Returns:
- The file size in bytes, or <0 on error.
-
getBitRate
public int getBitRate()
Get the calculated overall bit rate of this file.
This will only return a valid value if the container is non-streamed and supports seek.
- Returns:
- The overall bit rate in bytes per second, or <0 on error.
-
getNumProperties
public int getNumProperties()
Returns the total number of settable properties on this object
- Specified by:
getNumPropertiesin interfaceIConfigurable- Returns:
- total number of options (not including constant definitions)
-
getPropertyMetaData
public IProperty getPropertyMetaData(int propertyNo)
Returns the name of the numbered property.
- Specified by:
getPropertyMetaDatain interfaceIConfigurable- Parameters:
propertyNo- The property number in the options list.
- Returns:
- an IProperty value for this properties meta-data
-
getPropertyMetaData
public IProperty getPropertyMetaData(java.lang.String name)
Returns the name of the numbered property.
- Specified by:
getPropertyMetaDatain interfaceIConfigurable- Parameters:
name- The property name.
- Returns:
- an IProperty value for this properties meta-data
-
setProperty
public int setProperty(java.lang.String name, java.lang.String value)
Sets a property on this Object.
All AVOptions supported by the underlying AVClass are supported.
- Specified by:
setPropertyin interfaceIConfigurable- Parameters:
name- The property name. For example "b" for bit-rate.value- The value of the property.
- Returns:
- >= 0 if the property was successfully set; <0 on error
-
setProperty
public int setProperty(java.lang.String name, double value)
Looks up the property 'name' and sets the
value of the property to 'value'.
- Specified by:
setPropertyin interfaceIConfigurable- Parameters:
name- name of optionvalue- Value of option
- Returns:
- >= 0 on success; <0 on error.
-
setProperty
public int setProperty(java.lang.String name, long value)
Looks up the property 'name' and sets the
value of the property to 'value'.
- Specified by:
setPropertyin interfaceIConfigurable- Parameters:
name- name of optionvalue- Value of option
- Returns:
- >= 0 on success; <0 on error.
-
setProperty
public int setProperty(java.lang.String name, boolean value)
Looks up the property 'name' and sets the
value of the property to 'value'.
- Specified by:
setPropertyin interfaceIConfigurable- Parameters:
name- name of optionvalue- Value of option
- Returns:
- >= 0 on success; <0 on error.
-
setProperty
public int setProperty(java.lang.String name, IRational value)
Looks up the property 'name' and sets the
value of the property to 'value'.
- Specified by:
setPropertyin interfaceIConfigurable- Parameters:
name- name of optionvalue- Value of option
- Returns:
- >= 0 on success; <0 on error.
-
getPropertyAsString
public java.lang.String getPropertyAsString(java.lang.String name)
Gets a property on this Object.
Note for C++ callers; you must free the returned array with
delete[] in order to avoid a memory leak. If you call
from Java or any other language, you don't need to worry
about this.
- Specified by:
getPropertyAsStringin interfaceIConfigurable- Parameters:
name- property name
- Returns:
- an string copy of the option value, or null if the option doesn't exist.
-
getPropertyAsDouble
public double getPropertyAsDouble(java.lang.String name)
Gets the value of this property, and returns as a double;
- Specified by:
getPropertyAsDoublein interfaceIConfigurable- Parameters:
name- name of option
- Returns:
- double value of property, or 0 on error.
-
getPropertyAsLong
public long getPropertyAsLong(java.lang.String name)
Gets the value of this property, and returns as an long;
- Specified by:
getPropertyAsLongin interfaceIConfigurable- Parameters:
name- name of option
- Returns:
- long value of property, or 0 on error.
-
getPropertyAsRational
public IRational getPropertyAsRational(java.lang.String name)
Gets the value of this property, and returns as an IRational;
- Specified by:
getPropertyAsRationalin interfaceIConfigurable- Parameters:
name- name of option
- Returns:
- long value of property, or 0 on error.
-
getPropertyAsBoolean
public boolean getPropertyAsBoolean(java.lang.String name)
Gets the value of this property, and returns as a boolean
- Specified by:
getPropertyAsBooleanin interfaceIConfigurable- Parameters:
name- name of option
- Returns:
- boolean value of property, or false on error.
-
getFlags
public int getFlags()
Get the flags associated with this object.
- Returns:
- The (compacted) value of all flags set.
-
setFlags
public void setFlags(int newFlags)
Set the flags to use with this object. All values
must be ORed (|) together.
- Parameters:
newFlags- The new set flags for this codec.- See Also:
Flags
-
getFlag
public boolean getFlag(IContainer.Flags flag)
Get the setting for the specified flag
- Parameters:
flag- The flag you want to find the setting for
- Returns:
- 0 for false; non-zero for true
-
setFlag
public void setFlag(IContainer.Flags flag, boolean value)
Set the flag.
- Parameters:
flag- The flag to setvalue- The value to set it to (true or false)
-
getURL
public java.lang.String getURL()
Get the URL the IContainer was opened with.
May return null if unknown.- Returns:
- the URL opened, or null.
-
flushPackets
public int flushPackets()
Flush all packets to output.
Will only work on {IContainer.Type#WRITE} containers.
If the current thread is interrupted while this blocking method
is running the method will return with a negative value.
To check if the method exited because of an interruption
pass the return value to {IError#make(int)} and then
check {IError#getType()} to see if it is
{IError.Type#ERROR_INTERRUPTED}.
- Returns:
- >= 0 on success; <0 on error
-
getReadRetryCount
public int getReadRetryCount()
Get the number of times {IContainer#readNextPacket(IPacket)}
will retry a read if it gets a {IError.Type#ERROR_AGAIN}
value back.
Defaults to 1 times. <0 means it will keep retrying indefinitely.
- Returns:
- the read retry count
-
setReadRetryCount
public void setReadRetryCount(int count)
Sets the read retry count.
- Parameters:
count- The read retry count. <0 means keep trying.
-
canStreamsBeAddedDynamically
public boolean canStreamsBeAddedDynamically()
Can streams be added dynamically to this container?
- Returns:
- true if streams can be added dynamically
-
getMetaData
public IMetaData getMetaData()
Get the {IMetaData} for this object,
or null if none.
If the {IContainer} or {IStream} object
that this {IMetaData} came from was opened
for reading, then changes via {IMetaData#setValue(String, String)}
will have no effect on the underlying media.
If the {IContainer} or {IStream} object
that this {IMetaData} came from was opened
for writing, then changes via {IMetaData#setValue(String, String)}
will have no effect after {IContainer#writeHeader()}
is called.
- Returns:
- the {IMetaData}.
-
setMetaData
public void setMetaData(IMetaData data)
Set the {IMetaData} on this object, overriding
any previous meta data. You should call this
method on writable containers and
before you call {IContainer#writeHeader}, as
it probably won't do anything after that.
- See Also:
getMetaData()
-
createSDPData
public int createSDPData(IBuffer buffer)
Fills the given buffer with a null-terminated ASCII
set of bytes representing SDP data that
is suitable for use with an RTSP-based system.
This method only works if AVPKit is linking
against a version of FFmpeg that supports RTSP.
- Parameters:
buffer- the {com.avpkit.ferry.IBuffer}
object to fill with data.- Returns:
- the number of bytes written, including the
terminating 0 byte, or < 0 on error.
-
setForcedAudioCodec
public int setForcedAudioCodec(ICodec.ID id)
Forces the {IContainer} to assume all audio streams are
encoded with the given audio codec when demuxing.- Parameters:
id- The codec id- Returns:
- < 0 on error (e.g. not an audio codec); >= 0 on success.
- Since:
- 3.3
-
setForcedVideoCodec
public int setForcedVideoCodec(ICodec.ID id)
Forces the {IContainer} to assume all video streams are
encoded with the given video codec when demuxing.- Parameters:
id- The codec id- Returns:
- < 0 on error (e.g. not an video codec); >= 0 on success.
- Since:
- 3.3
-
setForcedSubtitleCodec
public int setForcedSubtitleCodec(ICodec.ID id)
Forces the {IContainer} to assume all subtitle streams are
encoded with the given subtitle codec when demuxing.- Parameters:
id- The codec id- Returns:
- < 0 on error (e.g. not an subtitle codec); >= 0 on success.
- Since:
- 3.3
-
seekKeyFrame
public int seekKeyFrame(int streamIndex, long minTimeStamp, long targetTimeStamp, long maxTimeStamp, int flags)
EXPERIMENTAL - Seeks to timestamp in the container.
Seeking will be done so that the point from which all active streams
can be presented successfully will be closest to
targetTimeStampand within.
minTimeStamp/maxTimeStamp
If flags contain {#SEEK_FLAG_BYTE}, then all time stamps are in bytes and
are the file position (this may not be supported by all demuxers).
If flags contain {#SEEK_FLAG_FRAME}, then all time stamps are in frames
in the stream withstreamIndex(this may not be supported by all demuxers).
Otherwise all time stamps are in units of the stream selected by stream_index
or if stream_index is -1, in microseconds.
If flags contain {#SEEK_FLAG_ANY}, then non-keyframes are treated as
keyframes (this may not be supported by all demuxers).
If flags contain {#SEEK_FLAG_BACKWARDS}, then we will attempt to
search backwards in the container (this may not be supported by all
demuxers and file protocols).
This is part of the new seek API which is still under construction.
It may change in future AVPKit versions.
- Parameters:
streamIndex- index of the stream which is used as time base referenceminTimeStamp- smallest acceptable time stamp.targetTimeStamp- target time stamp.maxTimeStamp- largest acceptable time stamp.flags- A bitmask of theSEEK_FLAG_*flags, or 0 to turn
all flags off.- Returns:
- >=0 on success, error code otherwise
- Since:
- 3.4
-
setPreload
@Deprecated public int setPreload(int preload)
Deprecated.use {#setProperty} instead.
If the container has not already been opened, sets the AVFormatContext.preload property
which can be useful in some circumstances such as when dealing with mpeg formats.
- Parameters:
preload- amount to preload- Returns:
- >= 0 on success, error code otherwise
- Since:
- 4.0
-
getPreload
@Deprecated public int getPreload()
Deprecated.use {#getPropertyAsLong} instead.
The amount container will attemtp to preload.
- Returns:
- The amount to preload, error code otherwise.
-
setMaxDelay
public int setMaxDelay(int maxdelay)
Sets the max delay for the AVFormatContext.max_delay property.
- Parameters:
maxdelay- maximum delay for container- Returns:
- >= 0 on success, error code otherwise
- Since:
- 4.0
-
getMaxDelay
public int getMaxDelay()
Gets the AVFormatContext.max_delay property if possible.- Returns:
- The max delay, error code otherwise.
- Since:
- 4.0
-
addNewStream
public IStream addNewStream(ICodec.ID id)
Add a new stream that will use the given codec.
- Parameters:
id- The id for the codec used to insert packets. If you are adding an arbitrary data stream, use {ICodec.ID#AV_CODEC_ID_NONE}, otherwise
use the ID of the code type you plan to use.
- Returns:
- An {IStream} for the new stream on success, or null on failure.
- Since:
- 5.0
-
addNewStream
public IStream addNewStream(ICodec codec)
Add a new stream that will use the given codec.
- Parameters:
codec- The codec that will be used to insert packets.
- Returns:
- An {IStream} for the new stream on success, or null on failure.
- Since:
- 5.0
-
addNewStream
public IStream addNewStream(IStreamCoder coder)
Add a new stream that will use the given StreamCoder. The StreamCoder passed in MUST contain the {IStreamCoder#getExtraData} that
was used to encode the packet.
- Parameters:
coder- The {IStreamCoder} that contains the meta-information needed for decoding the packets that will be muexed into this stream.- Returns:
- An {IStream} for the new stream on success, or null on failure.
- Since:
- 5.0
-
setProperty
public int setProperty(IMetaData valuesToSet, IMetaData valuesNotFound)
{- Specified by:
setPropertyin interfaceIConfigurable- Parameters:
valuesToSet- The set of key-value pairs to try to setvaluesNotFound- If non null will contain all key-values pairs in valuesToSet that were not found in context.- Returns:
- 0 on success; <0 on failure
-
getFormat
public IContainerFormat getFormat()
Get the {IContainerFormat} that is used by this {IContainer}.
- Returns:
- The format, or null if none is set yet.
- Since:
- 5.0
-
setFormat
public int setFormat(IContainerFormat format)
Set the {IContainerFormat} to use with this {IContainer}. If called when the
{IContainer} is opened, or if previously called with a non-null value,
an error is returned and no action is taken.- Parameters:
format- The format to use
return 0 on success; <0 on failure- Since:
- 5.0
-
make
public static IContainer make(IContainerFormat format)
Create a new {IContainer} and call {#setFormat(IContainerFormat)} on it immediately.- Parameters:
format- The format to pass to {#setFormat(IContainerFormat)}- Returns:
- An {IContainer} on success, or null on failure.
- Since:
- 5.0
-
open
public int open(java.lang.String url, IContainer.Type type, IContainerFormat containerFormat, boolean streamsCanBeAddedDynamically, boolean queryStreamMetaData, IMetaData options, IMetaData optionsNotSet)
Open this container and make it ready for reading or writing, optionally
reading as far into the container as necessary to find all streams.
The caller must call {#close()} when done, but if not, the
{IContainer} will eventually close
them later but warn to the logging system.
If the current thread is interrupted while this blocking method
is running the method will return with a negative value.
To check if the method exited because of an interruption
pass the return value to {IError#make(int)} and then
check {IError#getType()} to see if it is
{IError.Type#ERROR_INTERRUPTED}.
- Parameters:
url- The resource to open; The format of this string is any
url that FFMPEG supports (including additional protocols if added
through the core.io library).type- The type of this container.containerFormat- A pointer to a ContainerFormat object specifying
the format of this container, or 0 (NULL) if you want us to guess.streamsCanBeAddedDynamically- If true, open() will expect that new
streams can be added at any time, even after the format header has been read.queryStreamMetaData- If true, open() will call {#queryStreamMetaData()}
on this container, which will potentially block until it has ready
enough data to find all streams in a container. If false, it will only
block to read a minimal header for this container format.options- If not null, a set of key-value pairs that will be set on the container immediately
the format is determined. Some options cannot be set (especially for input containers) until the
system has a chance to parse what data is in the file.optionsNotSet- If not null, on return this {IMetaData} object will be cleared out, and
replace with any key/value pairs that were inoptionsbut could not be set on this
{IContainer}.
- Returns:
- >= 0 on success; < 0 on error.
- Since:
- 5.0
-
-