public class AVIOutputStream extends AbstractAVIStream
The length of an AVI 1.0 file is limited to 1 GB. This class supports lengths of up to 4 GB, but such files may not work on all players.
For detailed information about the AVI 1.0 file format
see:
msdn.microsoft.com
AVI RIFF
www.microsoft.com
FOURCC for Video Compression
www.saettler.com
RIFF
Modifier and Type | Class and Description |
---|---|
protected static class |
AVIOutputStream.States
The states of the movie output stream.
|
AbstractAVIStream.AudioTrack, AbstractAVIStream.AVIMediaType, AbstractAVIStream.Chunk, AbstractAVIStream.CompositeChunk, AbstractAVIStream.DataChunk, AbstractAVIStream.FixedSizeDataChunk, AbstractAVIStream.MainHeader, AbstractAVIStream.MidiTrack, AbstractAVIStream.Sample, AbstractAVIStream.TextTrack, AbstractAVIStream.Track, AbstractAVIStream.VideoTrack
Modifier and Type | Field and Description |
---|---|
protected AbstractAVIStream.CompositeChunk |
aviChunk
This chunk holds the whole AVI content.
|
protected AbstractAVIStream.FixedSizeDataChunk |
avihChunk
This chunk holds the AVI Main Header.
|
protected AbstractAVIStream.CompositeChunk |
moviChunk
This chunk holds the movie frames.
|
protected AVIOutputStream.States |
state
The current state of the movie output stream.
|
AVI_ID, AVIH_FLAG_COPYRIGHTED, AVIH_FLAG_HAS_INDEX, AVIH_FLAG_IS_INTERLEAVED, AVIH_FLAG_MUST_USE_INDEX, AVIH_FLAG_TRUST_CK_TYPE, AVIH_FLAG_WAS_CAPTURE_FILE, AVIH_ID, AVIX_ID, CHUNK_SUBTYPE_MASK, DB_ID, DC_ID, HDRL_ID, IDX1_ID, LIST_ID, MOVI_ID, out, PC_ID, REC_ID, RIFF_ID, STRD_ID, streamOffset, STRF_ID, STRH_FLAG_DISABLED, STRH_FLAG_VIDEO_PALETTE_CHANGES, STRH_ID, STRL_ID, STRN_ID, tracks, WB_ID
Constructor and Description |
---|
AVIOutputStream(java.io.File file)
Creates a new instance.
|
AVIOutputStream(javax.imageio.stream.ImageOutputStream out)
Creates a new instance.
|
Modifier and Type | Method and Description |
---|---|
int |
addAudioTrack(int waveFormatTag,
long scale,
long rate,
int numberOfChannels,
int sampleSizeInBits,
boolean isCompressed,
int frameDuration,
int frameSize)
Adds an audio track.
|
int |
addVideoTrack(java.lang.String fccHandler,
long scale,
long rate,
int width,
int height,
int depth,
int syncInterval)
Adds a video track.
|
void |
close()
Closes the stream.
|
protected void |
ensureFinished()
Sets the state of the QuickTimeOutpuStream to finished.
|
protected void |
ensureStarted()
Sets the state of the QuickTimeOutpuStream to started.
|
void |
finish()
Finishes writing the contents of the AVI output stream without closing
the underlying stream.
|
float |
getCompressionQuality(int track)
Returns the compression quality of a track.
|
java.lang.String[] |
getExtraHeaderFourCCs(int track)
Returns the fourcc's of all extra stream headers.
|
long |
getMediaDuration(int track)
Returns the duration of the track in media time scale.
|
java.awt.Dimension |
getVideoDimension(int track)
Gets the dimension of a track.
|
boolean |
isDataLimitReached()
Returns true if the limit for media samples has been reached.
|
void |
putExtraHeader(int track,
java.lang.String fourcc,
byte[] data)
Returns the contents of the extra track header.
|
void |
setCompressionQuality(int track,
float newValue)
Sets the compression quality of a track.
|
void |
setName(int track,
java.lang.String name) |
void |
setPalette(int track,
java.awt.image.ColorModel palette)
Sets the global color palette.
|
void |
writePalette(int track,
byte[] data,
int off,
int len,
boolean isKeyframe)
Writes an already encoded palette change into the specified track.
|
void |
writeSample(int track,
byte[] data,
int off,
int len,
boolean isKeyframe)
Writes an already encoded sample from a byte array into a track.
|
void |
writeSample(int track,
java.io.File file,
boolean isKeyframe)
Writes an already encoded sample from a file to the specified track.
|
void |
writeSample(int track,
java.io.InputStream in,
boolean isKeyframe)
Writes an already encoded sample from an input stream to the specified
track.
|
void |
writeSamples(int track,
int sampleCount,
byte[] data,
int off,
int len,
boolean isKeyframe)
Writes multiple already encoded samples from a byte array into a track.
|
getRelativeStreamPosition, intToType, isFlagSet, seekRelative, typeToInt
protected AVIOutputStream.States state
protected AbstractAVIStream.CompositeChunk aviChunk
protected AbstractAVIStream.CompositeChunk moviChunk
protected AbstractAVIStream.FixedSizeDataChunk avihChunk
public AVIOutputStream(java.io.File file) throws java.io.IOException
file
- the output filejava.io.IOException
public AVIOutputStream(javax.imageio.stream.ImageOutputStream out) throws java.io.IOException
out
- the output stream.java.io.IOException
public int addVideoTrack(java.lang.String fccHandler, long scale, long rate, int width, int height, int depth, int syncInterval) throws java.io.IOException
fccHandler
- The 4-character code of the format.scale
- The numerator of the sample rate.rate
- The denominator of the sample rate.width
- The width of a video image. Must be greater than 0.height
- The height of a video image. Must be greater than 0.depth
- The number of bits per pixel. Must be greater than 0.syncInterval
- Interval for sync-samples. 0=automatic. 1=all frames
are keyframes. Values larger than 1 specify that for every n-th frame is
a keyframe.java.lang.IllegalArgumentException
- if the width or the height is smaller
than 1.java.io.IOException
public int addAudioTrack(int waveFormatTag, long scale, long rate, int numberOfChannels, int sampleSizeInBits, boolean isCompressed, int frameDuration, int frameSize) throws java.io.IOException
waveFormatTag
- The format of the audio stream given in MMREG.H, for
example 0x0001 for WAVE_FORMAT_PCM.scale
- The numerator of the sample rate.rate
- The denominator of the sample rate.numberOfChannels
- The number of channels: 1 for mono, 2 for stereo.sampleSizeInBits
- The number of bits in a sample: 8 or 16.isCompressed
- Whether the sound is compressed.frameDuration
- The frame duration, expressed in the media’s
timescale, where the timescale is equal to the sample rate. For
uncompressed formats, this field is always 1.frameSize
- For uncompressed audio, the number of bytes in a sample
for a single channel (sampleSize divided by 8). For compressed audio, the
number of bytes in a frame.java.lang.IllegalArgumentException
- if the format is not 4 characters long,
if the time scale is not between 1 and 2^32, if the integer portion of
the sampleRate is not equal to the scale, if numberOfChannels is not 1 or
2.java.io.IOException
public void setPalette(int track, java.awt.image.ColorModel palette)
public java.awt.Dimension getVideoDimension(int track)
public void putExtraHeader(int track, java.lang.String fourcc, byte[] data) throws java.io.IOException
Note: this method can only be performed before media data has been written into the tracks.
track
- fourcc
- data
- the extra header as a byte arrayjava.io.IOException
public java.lang.String[] getExtraHeaderFourCCs(int track) throws java.io.IOException
track
- java.io.IOException
public void setName(int track, java.lang.String name)
public void setCompressionQuality(int track, float newValue)
A value of 0 stands for "high compression is important" a value of 1 for "high image quality is important".
Changing this value affects the encoding of video frames which are subsequently written into the track. Frames which have already been written are not changed.
This value has no effect on videos encoded with lossless encoders such as the PNG format.
The default value is 0.97.
newValue
- public float getCompressionQuality(int track)
protected void ensureStarted() throws java.io.IOException
If the state is changed by this method, the prolog is written.
java.io.IOException
protected void ensureFinished() throws java.io.IOException
If the state is changed by this method, the prolog is written.
java.io.IOException
public void writePalette(int track, byte[] data, int off, int len, boolean isKeyframe) throws java.io.IOException
If a track contains palette changes, then all key frames must be immediately preceeded by a palette change chunk which also is a key frame. If a key frame is not preceeded by a key frame palette change chunk, it will be downgraded to a delta frame.
java.lang.IllegalArgumentException
- if the track is not a video track.java.io.IOException
public void writeSample(int track, java.io.File file, boolean isKeyframe) throws java.io.IOException
This method does not inspect the contents of the file. For example, Its your responsibility to only append JPG files if you have chosen the JPEG video format.
If you append all frames from files or from input streams, then you have to explicitly set the dimension of the video track before you call finish() or close().
file
- The file which holds the sample data.java.lang.IllegalStateException
- if the duration is less than 1.java.io.IOException
- if writing the sample data failed.public void writeSample(int track, java.io.InputStream in, boolean isKeyframe) throws java.io.IOException
This method does not inspect the contents of the file. For example, its your responsibility to only append JPG files if you have chosen the JPEG video format.
If you append all frames from files or from input streams, then you have to explicitly set the dimension of the video track before you call finish() or close().
track
- The track number.in
- The input stream which holds the sample data.isKeyframe
- True if the sample is a key frame.java.lang.IllegalArgumentException
- if the duration is less than 1.java.io.IOException
- if writing the sample data failed.public void writeSample(int track, byte[] data, int off, int len, boolean isKeyframe) throws java.io.IOException
This method does not inspect the contents of the samples. The contents has to match the format and dimensions of the media in this track.
If a track contains palette changes, then all key frames must be immediately preceeded by a palette change chunk. If a key frame is not preceeded by a palette change chunk, it will be downgraded to a delta frame.
track
- The track index.data
- The encoded sample data.off
- The startTime offset in the data.len
- The number of bytes to write.isKeyframe
- Whether the sample is a sync sample (keyframe).java.lang.IllegalArgumentException
- if the duration is less than 1.java.io.IOException
- if writing the sample data failed.public void writeSamples(int track, int sampleCount, byte[] data, int off, int len, boolean isKeyframe) throws java.io.IOException
This method does not inspect the contents of the data. The contents has to match the format and dimensions of the media in this track.
track
- The track index.sampleCount
- The number of samples.data
- The encoded sample data.off
- The startTime offset in the data.len
- The number of bytes to write. Must be dividable by
sampleCount.isKeyframe
- Whether the samples are sync samples. All samples must
either be sync samples or non-sync samples.java.lang.IllegalArgumentException
- if the duration is less than 1.java.io.IOException
- if writing the sample data failed.public long getMediaDuration(int track)
public void close() throws java.io.IOException
java.io.IOException
- if an I/O error has occurredpublic void finish() throws java.io.IOException
java.lang.IllegalStateException
- if the dimension of the video track has
not been specified or determined yet.java.io.IOException
- if an I/O exception has occurredpublic boolean isDataLimitReached()
AVI 1.0 files have a file size limit of 2 GB. This method returns true if a file size of 1.8 GB has been reached.