Class IContainerFormat


  • public class IContainerFormat
    extends RefCounted
    Specifies format information than can be used to configure
    an {IContainer} for input or output.


    Often times AVPKIT can guess the correct formats to put into
    a given IContainer object, but sometimes it needs help. You
    can allocate an IContainerFormat object and specify information about
    input or output containers, and then pass this to IContainer.open(...)
    to help us guess.

    • Constructor Detail

      • IContainerFormat

        protected IContainerFormat​(long cPtr,
                                   boolean cMemoryOwn)
        Internal Only.
      • IContainerFormat

        protected IContainerFormat​(long cPtr,
                                   boolean cMemoryOwn,
                                   java.util.concurrent.atomic.AtomicLong ref)
        Internal Only.
    • Method Detail

      • getCPtr

        public static long getCPtr​(IContainerFormat 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:
        getMyCPtr in class RefCounted
        Returns:
        The raw pointer we're proxying for.
      • 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:
        equals in class java.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:
        hashCode in class java.lang.Object
        Returns:
        the hashable value.
      • toString

        public java.lang.String toString()
        info about this format object
        Overrides:
        toString in class java.lang.Object
        Returns:
        information about this object
      • getOutputCodecsSupported

        public java.util.List<ICodec.IDgetOutputCodecsSupported()
        Returns a list of all codecs supported for this Object.

        If this object hasn't been set up for output, then we return null.

        Returns:
        A list of supported codecs, in decreasing preferred order.
        Since:
        3.1
      • getOutputTagsSupported

        public java.util.List<java.lang.Integer> getOutputTagsSupported()
        Returns a list of all codec tags supported for this container.

        If this object hasn't been set up for output, then we return null.

        Returns:
        A list of supported codec tags, in decreasing preferred order.
        Since:
        3.3
      • establishOutputCodecId

        public ICodec.ID establishOutputCodecId​(ICodec.Type type,
                                                ICodec.ID inputCodecId)
        For a given input codec guess an ID supported by this IContainerFormat that might be good for encoding.

        For example, if the input codec ID was ICodec.ID#CODEC_ID_FLAC and you were trying to encoding into an "FLV" file that doesn't support that codec for outputting, this method will instead suggest ICodec.ID#CODEC_ID_MP3 instead.

        The algorithm followed is:

        • If the container has a preferred codec for the given codec type, use that; else
        • If the input codec can be used for encoding into this container, and is installed on this system, use that; else
        • Query the container format to see what other formats it can support, and are installed on this system, and choose the first one that will work; else
        • Throw an UnsupportedOperationException.

        This method relies on FFMPEGs internal database of codec IDs to identify the correct output codec IDs that can fit in this container.

        Parameters:
        type - the type of codec desired
        inputCodecId - an input codec id to attempt to match, or null if none.
        Returns:
        the best guess output codec ID
        Throws:
        java.lang.IllegalArgumentException - if inputCodecId is null or equal to ICodec.ID#CODEC_ID_NONE, or isOutput() is false.
        java.lang.UnsupportedOperationException - if we cannot establish a codec.
      • setInputFormat

        public int setInputFormat​(java.lang.String shortName)
        Sets the input format for this container.

        Parameters:
        shortName - The short name for this container (using FFMPEG's
        short name).
        Returns:
        >= 0 on success. < 0 if shortName cannot be found.
      • setOutputFormat

        public int setOutputFormat​(java.lang.String shortName,
                                   java.lang.String url,
                                   java.lang.String mimeType)
        Sets the output format for this container.

        We'll look at the shortName, url and mimeType and try to guess
        a valid output container format.

        Parameters:
        shortName - The short name for this container (using FFMPEG's
        short name).
        url - The URL for this container.
        mimeType - The mime type for this container.
        Returns:
        >= 0 on success. < 0 if we cannot find a good container.
      • getInputFormatShortName

        public java.lang.String getInputFormatShortName()
        Get the short name for the input format.
        Returns:
        The short name for the input format, or null if none.
      • getInputFormatLongName

        public java.lang.String getInputFormatLongName()
        Get the long name for the input format.
        Returns:
        The long name for the input format, or null if none.
      • getOutputFormatShortName

        public java.lang.String getOutputFormatShortName()
        Get the short name for the output format.
        Returns:
        The short name for the output format, or null if none.
      • getOutputFormatLongName

        public java.lang.String getOutputFormatLongName()
        Get the long name for the output format.
        Returns:
        The long name for the output format, or null if none.
      • getOutputFormatMimeType

        public java.lang.String getOutputFormatMimeType()
        Get the mime type for the output format.
        Returns:
        The mime type for the output format, or null if none.
      • make

        public static IContainerFormat make()
        Create a new IContainerFormat object.

        Returns:
        a new object, or null on error.
      • getInputFlags

        public int getInputFlags()
        Get the input flags associated with this object.

        Returns:
        The (compacted) value of all flags set.
      • setInputFlags

        public void setInputFlags​(int newFlags)
        Set the input flags to use with this object. All values
        must be ORed (|) together.

        Parameters:
        newFlags - The new set flags for this codec.
        See Also:
        Flags

      • getInputFlag

        public boolean getInputFlag​(IContainerFormat.Flags flag)
        Get the input setting for the specified flag

        Parameters:
        flag - The flag you want to find the setting for

        Returns:
        0 for false; non-zero for true
      • setInputFlag

        public void setInputFlag​(IContainerFormat.Flags flag,
                                 boolean value)
        Set the input flag.

        Parameters:
        flag - The flag to set
        value - The value to set it to (true or false)
      • getOutputFlags

        public int getOutputFlags()
        Get the output flags associated with this object.

        Returns:
        The (compacted) value of all flags set.
      • setOutputFlags

        public void setOutputFlags​(int newFlags)
        Set the output flags to use with this object. All values
        must be ORed (|) together.

        Parameters:
        newFlags - The new set flags for this codec.
        See Also:
        Flags

      • getOutputFlag

        public boolean getOutputFlag​(IContainerFormat.Flags flag)
        Get the output setting for the specified flag

        Parameters:
        flag - The flag you want to find the setting for

        Returns:
        0 for false; non-zero for true
      • setOutputFlag

        public void setOutputFlag​(IContainerFormat.Flags flag,
                                  boolean value)
        Set the output flag.

        Parameters:
        flag - The flag to set
        value - The value to set it to (true or false)
      • isOutput

        public boolean isOutput()
        Is this an output container format?

        Returns:
        true if output; false it not
      • isInput

        public boolean isInput()
        Is this an input container format?

        Returns:
        true if input; false it not
      • getOutputExtensions

        public java.lang.String getOutputExtensions()
        Get the filename extensions that this output format prefers
        (most common first).

        Returns:
        a command separated string of output extensions, or
        null if none.
      • getOutputDefaultAudioCodec

        public ICodec.ID getOutputDefaultAudioCodec()
        Get the default audio codec this container prefers, if known.

        Returns:
        the default audio codec id, or {ICodec.ID#CODEC_ID_NONE}
        if unknown.
      • getOutputDefaultVideoCodec

        public ICodec.ID getOutputDefaultVideoCodec()
        Get the default video codec this container prefers, if known.

        Returns:
        the default video codec id, or {ICodec.ID#CODEC_ID_NONE}
        if unknown.
      • getOutputDefaultSubtitleCodec

        public ICodec.ID getOutputDefaultSubtitleCodec()
        Get the default subtitle codec this container prefers, if known.

        Returns:
        the default subtitle codec id, or {ICodec.ID#CODEC_ID_NONE}
        if unknown.
      • getOutputNumCodecsSupported

        public int getOutputNumCodecsSupported()
        Gets the number of different codecs this container
        can include for encoding.

        This can be used as an upper bound when using the
        {#getOutputCodecID(int)} and
        {#getOutputCodecTag(int)}
        methods to dynamically query the actual codecs.

        Returns:
        The total number of different codec types that can
        be encoded into this container format.
      • getOutputCodecID

        public ICodec.ID getOutputCodecID​(int index)
        Queries for a supported codec id from the list of codecs
        that can be encoded into this ContainerFormat.

        Parameters:
        index - The index in our lookup table. Index >= 0 and
        < {#getOutputNumCodecsSupported()}. Index values may
        change between releases, so always query.

        Returns:
        The codec id at this position, or
        {ICodec.ID#CODEC_ID_NONE}
        if there is none.
      • getOutputCodecTag

        public int getOutputCodecTag​(int index)
        Queries for a supported codec tag from the list of codecs
        that can be encoded into this ContainerFormat.


        Tags are 4-byte values that are often used as markers
        in a container format for a codec type.


        Parameters:
        index - The index in our lookup table. Index >= 0 and
        < {#getOutputNumCodecsSupported()}. Index values may
        change between releases, so always query.

        Returns:
        The codec id tag this position, or 0 if there is none.
      • getOutputCodecTag

        public int getOutputCodecTag​(ICodec.ID id)
        Get the 4-byte tag the container would output for
        the given codec id.

        Parameters:
        id - the codec you are about

        Returns:
        the 4-byte codec tag, or 0 if that id is not
        supported.
      • isCodecSupportedForOutput

        public boolean isCodecSupportedForOutput​(ICodec.ID id)
        Returns true if this container format can output media
        encoded with the given codec.

        Parameters:
        id - the codec you care about.

        Returns:
        true if the codec can be put in this output container;
        false otherwise.
      • getNumInstalledInputFormats

        public static int getNumInstalledInputFormats()
        Get the number of input formats this install can demultiplex (read)
        from.

        Returns:
        the number of formats
      • getInstalledInputFormat

        public static IContainerFormat getInstalledInputFormat​(int index)
        Return an object for the input format at the given index.

        Parameters:
        index - an index for the input format list we maintain

        Returns:
        a format object for that input or null if
        unknown, index < 0 or index >= {#getNumInstalledInputFormats()}
      • getNumInstalledOutputFormats

        public static int getNumInstalledOutputFormats()
        Get the number of output formats this install can multiplex
        (write) to.

        Returns:
        the number of formats
      • getInstalledOutputFormat

        public static IContainerFormat getInstalledOutputFormat​(int index)
        Return an object for the output format at the given index.

        Parameters:
        index - an index for the output format list we maintain

        Returns:
        a format object for that output or null if
        unknown, index < 0 or index >= {#getNumInstalledOutputFormats()}