Class FLVReader

  • All Implemented Interfaces:
    IKeyFrameDataAnalyzer, IoConstants, ITagReader

    public class FLVReader
    extends Object
    implements IoConstants, ITagReader, IKeyFrameDataAnalyzer
    A Reader is used to read the contents of a FLV file. NOTE: This class is not implemented as threading-safe. The caller should make sure the threading-safety.
    Author:
    The Red5 Project, Dominick Accattato (daccattato@gmail.com), Luke Hubbard, Codegent Ltd (luke@codegent.com), Paul Gregoire, (mondain@gmail.com)
    • Constructor Detail

      • FLVReader

        public FLVReader​(File f)
                  throws IOException
        Creates FLV reader from file input stream.
        Parameters:
        f - File
        Throws:
        IOException - on error
      • FLVReader

        public FLVReader​(File f,
                         boolean generateMetadata)
                  throws IOException
        Creates FLV reader from file input stream, sets up metadata generation flag.
        Parameters:
        f - File input stream
        generateMetadata - true if metadata generation required, false otherwise
        Throws:
        IOException - on error
      • FLVReader

        public FLVReader​(FileChannel channel)
                  throws IOException
        Creates FLV reader from file channel.
        Parameters:
        channel - file channel
        Throws:
        IOException - on error
      • FLVReader

        public FLVReader​(org.apache.mina.core.buffer.IoBuffer buffer,
                         boolean generateMetadata)
        Accepts mapped file bytes to construct internal members.
        Parameters:
        generateMetadata - true if metadata generation required, false otherwise
        buffer - IoBuffer
    • Method Detail

      • getTotalBytes

        public long getTotalBytes()
        Get the total readable bytes in a file or ByteBuffer.
        Specified by:
        getTotalBytes in interface ITagReader
        Returns:
        Total readable bytes
      • hasVideo

        public boolean hasVideo()
        Check if the reader also has video tags.
        Specified by:
        hasVideo in interface ITagReader
        Returns:
        has video
      • getBufferType

        public static String getBufferType()
        Getter for buffer type (auto, direct or heap).
        Returns:
        Value for property 'bufferType'
      • setBufferType

        public static void setBufferType​(String bufferType)
        Setter for buffer type.
        Parameters:
        bufferType - Value to set for property 'bufferType'
      • getBufferSize

        public static int getBufferSize()
        Getter for buffer size.
        Returns:
        Value for property 'bufferSize'
      • setBufferSize

        public static void setBufferSize​(int bufferSize)
        Setter for property 'bufferSize'.
        Parameters:
        bufferSize - Value to set for property 'bufferSize'
      • getFileData

        public org.apache.mina.core.buffer.IoBuffer getFileData()
        Returns the file buffer.
        Returns:
        File contents as byte buffer
      • decodeHeader

        public void decodeHeader()
        Decode the header of the stream;
        Specified by:
        decodeHeader in interface ITagReader
      • getOffset

        public int getOffset()
        Returns the offet length
        Specified by:
        getOffset in interface ITagReader
        Returns:
        int
      • getBytesRead

        public long getBytesRead()
        Returns the amount of bytes read
        Specified by:
        getBytesRead in interface ITagReader
        Returns:
        long
      • getDuration

        public long getDuration()
        Return length in seconds
        Specified by:
        getDuration in interface ITagReader
        Returns:
        length in seconds
      • getVideoCodecId

        public int getVideoCodecId()
      • getAudioCodecId

        public int getAudioCodecId()
      • hasMoreTags

        public boolean hasMoreTags()
        Returns a boolean stating whether the FLV has more tags
        Specified by:
        hasMoreTags in interface ITagReader
        Returns:
        boolean
      • readTag

        public ITag readTag()
        Returns a Tag object
        Specified by:
        readTag in interface ITagReader
        Returns:
        Tag
      • close

        public void close()
        Closes the reader and free any allocated memory.
        Specified by:
        close in interface ITagReader
      • position

        public void position​(long pos)
        Put the current position to pos. The caller must ensure the pos is a valid one (eg. not sit in the middle of a frame).
        Specified by:
        position in interface ITagReader
        Parameters:
        pos - New position in file. Pass Long.MAX_VALUE to seek to end of file.
      • getDuration

        public static int getDuration​(File flvFile)
        Returns the last tag's timestamp as the files duration.
        Parameters:
        flvFile - FLV file
        Returns:
        duration