public final class FLVUtils
extends Object
FLVUtils: utility for reading and writing .flv files.
| Modifier and Type | Field | Description |
|---|---|---|
static Class<FLVUtils> |
CLASS |
|
static String |
CLASSNAME |
|
static int |
FLV_CHUNKHEADER_BUFFERSIZE |
Size of temporary buffer needed for flv reading (byte[])
|
static int |
FLV_CHUNKHEADER_FIRSTBYTE |
Header values: first byte of packet data
|
static int |
FLV_CHUNKHEADER_HEADERSIZE |
Size of packet header (byte[])
|
static int |
FLV_CHUNKHEADER_ISIZE |
Header values: packet size
|
static int |
FLV_CHUNKHEADER_ITIMECODE |
Header values: timecode (milliseconds)
|
static int |
FLV_CHUNKHEADER_ITYPE |
Heaeder values: packet type
|
static int |
FLV_CHUNKHEADER_SECONDBYTE |
Header values: second byte of packet data
|
static int |
FLV_CHUNKHEADER_VALUESIZE |
Size of header values array (long[])
|
static int |
FLV_DFRAME |
D video frame type (partial frame based on key frame)
|
static int |
FLV_KFRAME |
Key video frame type
|
static int |
FLV_PFRAME |
P video frame type (partial frame based on previous frame)
|
static int |
FLV_TCINDEXAUDIO |
|
static int |
FLV_TCINDEXDATA |
|
static int |
FLV_TCINDEXVIDEO |
|
static int |
FLV_UFRAME |
Unknown video frame type
|
static long |
METADATAFILTER_NONE |
|
static long |
METADATAFILTER_REMOVE_OBJS |
| Constructor | Description |
|---|---|
FLVUtils() |
| Modifier and Type | Method | Description |
|---|---|---|
static long |
adjustFirstPacketTCs(java.util.List audioTCs,
java.util.List videoTCs,
java.util.List dataTCs) |
Align list of timecode for each data type.
|
static int |
audioCodecStringToId(String codecString) |
Parse a string to get the codec ID defined by IVHost.CODEC_AUDIO_*
|
static String |
audioCodecToMetaDataString(int codec) |
Get a printable string representation of the audio codecs defined as IVHost.CODEC_AUDIO_* as the string used in the onMetaData event
|
static String |
audioCodecToString(int codec) |
Get a printable string representation of the audio codecs defined as IVHost.CODEC_AUDIO_*
|
static String |
frameTypeToString(int frameType) |
|
static int |
getAudioCodec(int value) |
Return the codec portion of the first byte of an audio packet.
|
static int |
getAudioCodec(AMFPacket packet) |
Get the codec id for this audio packet.
|
static int |
getAudioMP3Layer(AMFPacket packet) |
Audio marked as MP3 is really MPEG1 Layer 1-3.
|
static int |
getFrameType(byte value) |
Given the first byte of a video packet, determine the frame type (FLV_*FRAME)
|
static int |
getFrameType(int value) |
Given the first byte of a video packet, determine the frame type (FLV_*FRAME)
|
static int |
getFrameType(int[] values) |
Given the headers values (including first byte of the packet), determine the
type of video frame (FLV_*FRAME)
|
static byte |
getHeaderFlags(java.io.File file) |
|
static long |
getLastTC(java.io.File file) |
Get the duration of an .flv file.
|
static OnMetadataBasic |
getOnMetadataData(AMFPacket metaDataPacket) |
|
static int |
getVideoCodec(int value) |
Return the codec portion of the first byte of an video packet.
|
static int |
getVideoCodec(AMFPacket packet) |
Get the codec id for this video packet.
|
static int |
getVideoFrameType(AMFPacket packet) |
|
static int |
getVideoTimecodeOffset(byte[] buffer) |
Get the timecode offset in milliseconds between the PTS and DTS for this frame.
|
static int |
getVideoTimecodeOffset(AMFPacket packet) |
Get the timecode offset in milliseconds between the PTS and DTS for this frame.
|
static java.util.List |
interleavePackets(java.util.List audioPackets,
java.util.List videoPackets,
java.util.List dataPackets,
java.util.List audioTCs,
java.util.List videoTCs,
java.util.List dataTCs,
long[] currentTCs) |
This is a utility function primarily used for IMediaWriters.
|
static java.util.List<AMFPacket> |
interleavePackets(java.util.List audioPackets,
java.util.List videoPackets,
java.util.List dataPackets,
java.util.List audioTCs,
java.util.List videoTCs,
java.util.List dataTCs,
java.util.List dataTypes,
long[] currentTCs) |
This is a utility function primarily used for IMediaWriters.
|
static boolean |
isAudioCodecConfig(AMFPacket packet) |
Returns true if the packet is a audio codec config packet
|
static boolean |
isAudioCodecConfig(java.nio.ByteBuffer buffer) |
Returns true if the packet is a audio codec config packet
|
static boolean |
isOnMetadata(byte[] dataDataBytes) |
|
static boolean |
isOnMetadataPacket(AMFPacket packet) |
Returns true if packet is onMetaData or [@setDataFrame, onMetaData] data packet.
|
static boolean |
isVideoCodecConfig(int firstByte,
int secondByte) |
Returns true if the packet is a video codec config packet
|
static boolean |
isVideoCodecConfig(AMFPacket packet) |
Returns true if the packet is a video codec config packet
|
static boolean |
isVideoCodecConfig(java.nio.ByteBuffer buffer) |
Returns true if the packet is a video codec config packet
|
static boolean |
isVideoKeyFrame(byte[] buffer) |
Returns true if the packet is a video key frame
|
static boolean |
isVideoKeyFrame(int[] chunkHeaderValues) |
Returns true if the packet is a video key frame
|
static boolean |
isVideoKeyFrame(AMFPacket packet) |
Returns true if the packet is a video key frame
|
static boolean |
isVideoKeyFrame(java.nio.ByteBuffer buffer) |
Returns true if the packet is a video key frame
|
static byte[] |
modifyOnMetadataEvent(byte[] buffer,
long flags,
java.util.List<String> itemsToRemove,
java.util.Map<String,AMFData> itemsToAdd) |
Modifies onMetadata event to remove or add items
|
static AMFPacket |
readChunk(java.io.DataInput is) |
Read a packets worth of .flv data from an InputStream and return as an AMFPacket
|
static AMFPacket |
readChunk(java.io.InputStream is) |
Read a packets worth of .flv data from an InputStream and return as an AMFPacket
|
static void |
readChunkHeader(java.io.RandomAccessFile is,
byte[] buffer,
int[] values) |
Read packet header.
|
static boolean |
readHeader(java.io.DataInput is) |
Read file header.
|
static boolean |
readHeader(java.io.InputStream is) |
Read file header.
|
static void |
readPrevChunkHeader(java.io.RandomAccessFile is,
byte[] buffer,
int[] values) |
Back up one packet from current position in the file and read the packet header.
|
static String |
streamCodecToString(int codec) |
Get a printable string representation of the stream codecs defined as IVHost.CODEC_STREAM_*
|
static AMFPacket |
updateOnCuePointTimecode(AMFPacket packet,
long timecode) |
|
static java.nio.ByteBuffer |
updateOnCuePointTimecode(java.nio.ByteBuffer data,
int dataType,
long timecode) |
|
static int |
videoCodecStringToCodecVersion(String codecString) |
Parse a string to get the codec version defined by IVHost.CODEC_VIDEO_VERSION_*
|
static int |
videoCodecStringToId(String codecString) |
Parse a string to get the codec ID defined by IVHost.CODEC_VIDEO_*
|
static String |
videoCodecToMetaDataString(int codec) |
Get a printable string representation of the video codecs defined as IVHost.CODEC_VIDEO_* as the string used in the onMetaData event
|
static String |
videoCodecToMetaDataString(int codec,
int codecVersion) |
Get a printable string representation of the video codecs defined as IVHost.CODEC_VIDEO_* as the string used in the onMetaData event
|
static String |
videoCodecToString(int codec) |
Get a printable string representation of the video codecs defined as IVHost.CODEC_VIDEO_*
|
static String |
videoCodecToString(int codec,
int codecVersion) |
|
static com.wowza.wms.mediawriter.MediaWriterStatus |
writeChunk(java.io.DataOutput ds,
java.nio.ByteBuffer data,
int size,
long timecode,
byte type) |
|
static com.wowza.wms.mediawriter.MediaWriterStatus |
writeChunk(java.io.OutputStream ds,
java.nio.ByteBuffer data,
int size,
long timecode,
byte type) |
Write a packets worth of data.
|
static void |
writeDuration(java.io.File file,
double duration) |
Write the duration to an existing .flv file.
|
static void |
writeHeader(java.io.OutputStream ds,
double duration,
int audiocodecid,
int videocodecid,
String createdBy,
java.util.Map extraMetadata) |
Write file header including onMetaData packet.
|
static void |
writeHeader(java.io.OutputStream ds,
double duration,
java.util.Map extraMetadata) |
Write file header including onMetaData packet.
|
static void |
writeHeaderFlags(java.io.File file,
byte newFlags) |
|
static void |
writePackets(java.io.OutputStream ds,
java.util.List packetList,
long tcOffset) |
Write audio/video/data packets to an .flv file.
|
static void |
writePackets(java.io.OutputStream ds,
java.util.List audioPackets,
java.util.List videoPackets,
java.util.List dataPackets,
java.util.List audioTCs,
java.util.List videoTCs,
java.util.List dataTCs,
long[] currentTCs) |
Write a bunch of packets to .flv file all at once.
|
static void |
writePackets(java.io.OutputStream ds,
java.util.List audioPackets,
java.util.List videoPackets,
java.util.List dataPackets,
java.util.List audioTCs,
java.util.List videoTCs,
java.util.List dataTCs,
java.util.List dataTypes,
long[] currentTCs) |
Write a bunch of packets to .flv file all at once.
|
static void |
writePackets(java.io.OutputStream ds,
java.util.List audioPackets,
java.util.List videoPackets,
java.util.List dataPackets,
java.util.List audioTCs,
java.util.List videoTCs,
java.util.List dataTCs,
java.util.List dataTypes,
long[] currentTCs,
com.wowza.util.IFLVWriterAdjustTimecode dataPacketTimecodeAdjuster) |
Write a bunch of packets to .flv file all at once.
|
static void |
writeShortHeader(java.io.DataOutput ds) |
|
static void |
writeShortHeader(java.io.OutputStream ds) |
Write just the FLV file header (without the metadata packet)
|
public static final Class<FLVUtils> CLASS
public static final String CLASSNAME
public static final int FLV_CHUNKHEADER_BUFFERSIZE
public static final int FLV_CHUNKHEADER_FIRSTBYTE
public static final int FLV_CHUNKHEADER_HEADERSIZE
public static final int FLV_CHUNKHEADER_ISIZE
public static final int FLV_CHUNKHEADER_ITIMECODE
public static final int FLV_CHUNKHEADER_ITYPE
public static final int FLV_CHUNKHEADER_SECONDBYTE
public static final int FLV_CHUNKHEADER_VALUESIZE
public static final int FLV_DFRAME
public static final int FLV_KFRAME
public static final int FLV_PFRAME
public static final int FLV_TCINDEXAUDIO
public static final int FLV_TCINDEXDATA
public static final int FLV_TCINDEXVIDEO
public static final int FLV_UFRAME
public static final long METADATAFILTER_NONE
public static final long METADATAFILTER_REMOVE_OBJS
public static long adjustFirstPacketTCs(java.util.List audioTCs,
java.util.List videoTCs,
java.util.List dataTCs)
audioTCs - list of audio timecodesvideoTCs - list of video timecodesdataTCs - list of data timecodespublic static int audioCodecStringToId(String codecString)
codecString - codec stringpublic static String audioCodecToMetaDataString(int codec)
codec - codec id defined IVHost.CODEC_AUDIO_*public static String audioCodecToString(int codec)
codec - codec id defined IVHost.CODEC_AUDIO_*public static String frameTypeToString(int frameType)
public static int getAudioCodec(int value)
value - first byte of audio packetpublic static int getAudioCodec(AMFPacket packet)
packet - packetpublic static int getAudioMP3Layer(AMFPacket packet)
packet - amf packetpublic static int getFrameType(byte value)
value - first byte of packetpublic static int getFrameType(int value)
value - first byte of packetpublic static int getFrameType(int[] values)
values - header valuespublic static byte getHeaderFlags(java.io.File file)
public static long getLastTC(java.io.File file)
file - public static OnMetadataBasic getOnMetadataData(AMFPacket metaDataPacket)
public static int getVideoCodec(int value)
value - first byte of audio packetpublic static int getVideoCodec(AMFPacket packet)
packet - packetpublic static int getVideoFrameType(AMFPacket packet)
public static int getVideoTimecodeOffset(byte[] buffer)
buffer - video packet bufferpublic static int getVideoTimecodeOffset(AMFPacket packet)
packet - AMFPacketpublic static java.util.List interleavePackets(java.util.List audioPackets,
java.util.List videoPackets,
java.util.List dataPackets,
java.util.List audioTCs,
java.util.List videoTCs,
java.util.List dataTCs,
long[] currentTCs)
audioPackets - list of audio packets (ByteBuffer)videoPackets - list of video packets (ByteBuffer)dataPackets - list of data packets (ByteBuffer)audioTCs - list of relative audio timecodes (Long)videoTCs - list of relative video timecodes (Long)dataTCs - list of relative data timecodes (Long)currentTCs - array of longs containing last TCs written for each packet type FLV_TCINDEX* (long[3]). Last timecode written for each packet type wil be returned
in this same array.public static java.util.List<AMFPacket> interleavePackets(java.util.List audioPackets, java.util.List videoPackets, java.util.List dataPackets, java.util.List audioTCs, java.util.List videoTCs, java.util.List dataTCs, java.util.List dataTypes, long[] currentTCs)
audioPackets - list of audio packets (ByteBuffer)videoPackets - list of video packets (ByteBuffer)dataPackets - list of data packets (ByteBuffer)audioTCs - list of relative audio timecodes (Long)videoTCs - list of relative video timecodes (Long)dataTCs - list of relative data timecodes (Long)dataTypes - list of integer packets types (IVHost.CONTENTTYPE_DATA0, IVHost.CONTENTTYPE_DATA3) - if null assumed to be IVHost.CONTENTTYPE_DATA0currentTCs - array of longs containing last TCs written for each packet type FLV_TCINDEX* (long[3]). Last timecode written for each packet type wil be returned
in this same array.public static boolean isAudioCodecConfig(AMFPacket packet)
packet - public static boolean isAudioCodecConfig(java.nio.ByteBuffer buffer)
buffer - packet datapublic static boolean isOnMetadata(byte[] dataDataBytes)
public static boolean isOnMetadataPacket(AMFPacket packet)
packet - packetpublic static boolean isVideoCodecConfig(int firstByte,
int secondByte)
firstByte - first byte of packetsecondByte - second byte of packetpublic static boolean isVideoCodecConfig(AMFPacket packet)
packet - public static boolean isVideoCodecConfig(java.nio.ByteBuffer buffer)
buffer - packet datapublic static boolean isVideoKeyFrame(byte[] buffer)
buffer - packet data (only need first two bytes of data)public static boolean isVideoKeyFrame(int[] chunkHeaderValues)
chunkHeaderValues - chunk header values returned by FLVUtils.readChunkHeaderpublic static boolean isVideoKeyFrame(AMFPacket packet)
packet - packetpublic static boolean isVideoKeyFrame(java.nio.ByteBuffer buffer)
buffer - packet data (only need first two bytes of data)public static byte[] modifyOnMetadataEvent(byte[] buffer,
long flags,
java.util.List<String> itemsToRemove,
java.util.Map<String,AMFData> itemsToAdd)
buffer - byte buffer with onMetadata event serializedflags - flags to control what gets removed (see METADATAFILTER_*)itemsToRemove - list of names of fields to removeitemsToAdd - map of items to addpublic static AMFPacket readChunk(java.io.DataInput is)
is - InputStreampublic static AMFPacket readChunk(java.io.InputStream is)
is - InputStreampublic static void readChunkHeader(java.io.RandomAccessFile is,
byte[] buffer,
int[] values)
is - RandomAccessFilebuffer - temporary buffer byte[FLV_CHUNKHEADER_BUFFERSIZE]values - header values long[FLV_CHUNKHEADER_VALUESIZE]public static boolean readHeader(java.io.DataInput is)
public static boolean readHeader(java.io.InputStream is)
public static void readPrevChunkHeader(java.io.RandomAccessFile is,
byte[] buffer,
int[] values)
is - RandomAccessFilebuffer - temporary buffer byte[FLV_CHUNKHEADER_BUFFERSIZE]values - header values long[FLV_CHUNKHEADER_VALUESIZE]public static String streamCodecToString(int codec)
codec - codec id defined IVHost.CODEC_STREAM_*public static AMFPacket updateOnCuePointTimecode(AMFPacket packet, long timecode)
public static java.nio.ByteBuffer updateOnCuePointTimecode(java.nio.ByteBuffer data,
int dataType,
long timecode)
public static int videoCodecStringToCodecVersion(String codecString)
codecString - public static int videoCodecStringToId(String codecString)
codecString - codec stringpublic static String videoCodecToMetaDataString(int codec)
codec - codec id defined IVHost.CODEC_VIDEO_*public static String videoCodecToMetaDataString(int codec,
int codecVersion)
codec - codec id defined IVHost.CODEC_VIDEO_*codecVersion - codec versionpublic static String videoCodecToString(int codec)
codec - codec id defined IVHost.CODEC_VIDEO_*public static String videoCodecToString(int codec,
int codecVersion)
public static com.wowza.wms.mediawriter.MediaWriterStatus writeChunk(java.io.DataOutput ds,
java.nio.ByteBuffer data,
int size,
long timecode,
byte type)
public static com.wowza.wms.mediawriter.MediaWriterStatus writeChunk(java.io.OutputStream ds,
java.nio.ByteBuffer data,
int size,
long timecode,
byte type)
ds - OutputStreamdata - packet datasize - size of the packettimecode - timecode (milliseconds)type - type of packet IVHost.CONTENTTYPE_*public static void writeDuration(java.io.File file,
double duration)
file - .flv fileduration - new duration value (seconds)public static void writeHeader(java.io.OutputStream ds,
double duration,
int audiocodecid,
int videocodecid,
String createdBy,
java.util.Map extraMetadata)
Write file header including onMetaData packet.
With this method you can provide a Map of metadata to write to the file. This map can include a mixture of simple types like: int, long, String, boolean. These types will be wrapped in AMFData classes before they are written to the file. This map can also contain AMFData items. For example if you wanted to insert and array of cuePoints the code would look like:
Map extraMetadata = new HashMap();
AMFDataArray amfArray = new AMFDataArray();
for(int i=0;i
ds - OutputStreamduration - duration of .flv file in secondsaudiocodecid - audio codec ID see IVHost.CODEC_AUDIO_* (-1 for now audio)videocodecid - video codec ID see IVHost.CODEC_VIDEO_* (-1 for now video)createdBy - created by string (null for empty)extraMetadata - Map of name/value pairs of metadata that will be appended to the onMetaData blockpublic static void writeHeader(java.io.OutputStream ds,
double duration,
java.util.Map extraMetadata)
ds - OutputStreamduration - duration of .flv file in secondsextraMetadata - Map of name/value pairs of metadata that will be appended to the onMetaData blockpublic static void writeHeaderFlags(java.io.File file,
byte newFlags)
public static void writePackets(java.io.OutputStream ds,
java.util.List packetList,
long tcOffset)
ds - OutputStreampacketList - List of AMFPacket objectstcOffset - timecode offsetpublic static void writePackets(java.io.OutputStream ds,
java.util.List audioPackets,
java.util.List videoPackets,
java.util.List dataPackets,
java.util.List audioTCs,
java.util.List videoTCs,
java.util.List dataTCs,
long[] currentTCs)
ds - OutputStreamaudioPackets - list of audio packets (ByteBuffer)videoPackets - list of video packets (ByteBuffer)dataPackets - list of data packets (ByteBuffer)audioTCs - list of relative audio timecodes (Long)videoTCs - list of relative video timecodes (Long)dataTCs - list of relative data timecodes (Long)currentTCs - array of longs containing last TCs written for each packet type FLV_TCINDEX* (long[3]). Last timecode written for each packet type wil be returned
in this same array.public static void writePackets(java.io.OutputStream ds,
java.util.List audioPackets,
java.util.List videoPackets,
java.util.List dataPackets,
java.util.List audioTCs,
java.util.List videoTCs,
java.util.List dataTCs,
java.util.List dataTypes,
long[] currentTCs)
ds - OutputStreamaudioPackets - list of audio packets (ByteBuffer)videoPackets - list of video packets (ByteBuffer)dataPackets - list of data packets (ByteBuffer)audioTCs - list of relative audio timecodes (Long)videoTCs - list of relative video timecodes (Long)dataTCs - list of relative data timecodes (Long)dataTypes - list of integer packets types (IVHost.CONTENTTYPE_DATA0, IVHost.CONTENTTYPE_DATA3) - if null assumed to be IVHost.CONTENTTYPE_DATA0currentTCs - array of longs containing last TCs written for each packet type FLV_TCINDEX* (long[3]). Last timecode written for each packet type wil be returned
in this same array.public static void writePackets(java.io.OutputStream ds,
java.util.List audioPackets,
java.util.List videoPackets,
java.util.List dataPackets,
java.util.List audioTCs,
java.util.List videoTCs,
java.util.List dataTCs,
java.util.List dataTypes,
long[] currentTCs,
com.wowza.util.IFLVWriterAdjustTimecode dataPacketTimecodeAdjuster)
ds - OutputStreamaudioPackets - list of audio packets (ByteBuffer)videoPackets - list of video packets (ByteBuffer)dataPackets - list of data packets (ByteBuffer)audioTCs - list of relative audio timecodes (Long)videoTCs - list of relative video timecodes (Long)dataTCs - list of relative data timecodes (Long)dataTypes - list of integer packets types (IVHost.CONTENTTYPE_DATA0, IVHost.CONTENTTYPE_DATA3) - if null assumed to be IVHost.CONTENTTYPE_DATA0currentTCs - array of longs containing last TCs written for each packet type FLV_TCINDEX* (long[3]). Last timecode written for each packet type wil be returneddataPacketTimecodeAdjuster - class that implements the IFLVWriterAdjustTimecode interface for adjusting timecodes
in this same array.public static void writeShortHeader(java.io.DataOutput ds)
public static void writeShortHeader(java.io.OutputStream ds)
ds - OutputStream