public class XuggleVideo extends Video<MBFImage>
Video
interface.
Some Notes:
The hasNextFrame()
method must attempt to read the next packet in
the stream to determine if there is a next frame. That means that it incurs a
time penalty. It also means there's various logic in that method and the
getNextFrame()
method to avoid reading frames that have already been
read. It also means that, to avoid getCurrentFrame()
incorrectly
returning a new frame after hasNextFrame()
has been called, the
class may be holding two frames (the current frame and the next frame) after
hasNextFrame()
has been called.
The constructors have signatures that allow the passing of a boolean that
determines whether the video is looped or not. This has a different effect
than looping using the VideoDisplay
. When the video is set to loop it
will loop indefinitely and the timestamp of frames will be consecutive. That
is, when the video loops the timestamps will continue to increase. This is in
contrast to setting the VideoDisplay
end action (using
VideoDisplay.setEndAction(org.openimaj.video.VideoDisplay.EndAction)
where the looping will reset all timestamps when the video loops.
Modifier and Type | Class and Description |
---|---|
protected class |
XuggleVideo.FrameGetter
This implements the Xuggle MediaTool listener that will be called every
time a video picture has been decoded from the stream.
|
protected static class |
XuggleVideo.MBFImageConverter
Converter for converting IVideoPictures directly to MBFImages.
|
protected static class |
XuggleVideo.MBFImageWrapper
Wrapper that created an MBFImage from a BufferedImage.
|
Modifier and Type | Field and Description |
---|---|
boolean |
nextFrameIsKeyFrame
Whether the next frame is a key frame or not
|
long |
nextFrameTimestamp
The timestamp of the next frame
|
currentFrame
Constructor and Description |
---|
XuggleVideo(DataInput input)
Default constructor that takes a data input.
|
XuggleVideo(File videoFile)
Default constructor that takes the video file to read.
|
XuggleVideo(File videoFile,
boolean loop)
Default constructor that takes the video file to read.
|
XuggleVideo(InputStream stream)
Default constructor that takes an input stream.
|
XuggleVideo(String url)
Default constructor that takes the location of a video file to read.
|
XuggleVideo(String url,
boolean loop)
Default constructor that takes the location of a video file to read.
|
XuggleVideo(URL url)
Default constructor that takes the URL of a video file to read.
|
XuggleVideo(URL url,
boolean loop)
Default constructor that takes the location of a video file to read.
|
Modifier and Type | Method and Description |
---|---|
void |
close()
Close the video object
|
long |
countFrames()
Return the number of frames in the whole video.
|
MBFImage |
getCurrentFrame()
Get the current frame
|
int |
getCurrentFrameIndex()
Get the index of the current frame
|
VideoTimecode |
getCurrentTimecode()
Returns a video timecode for the current frame.
|
long |
getDuration()
Returns the duration of the video in seconds.
|
double |
getFPS()
Get the frame rate
|
int |
getHeight()
Get the height of the video frame.
|
MBFImage |
getNextFrame()
Get the next frame.
|
long |
getTimeStamp()
Get the timestamp of the current frame in milliseconds
|
int |
getWidth()
Get the width of the video frame
|
boolean |
hasNextFrame()
Returns whether this video has another frame to provide.
|
void |
reset()
Reset the video - putting the frame counter back to the start.
|
void |
seek(double timestamp)
Seek the video to a given timestamp in SECONDS.
|
void |
seekPrecise(double timestamp)
Implements a precise seeking mechanism based on the Xuggle seek method
and the naive seek method which simply reads frames.
|
void |
seekToBeginning()
This is a convenience method that will seek the stream to be the
beginning.
|
void |
setCurrentFrameIndex(long newFrame)
Set the current frame index (i.e.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
forEach, spliterator
public long nextFrameTimestamp
public boolean nextFrameIsKeyFrame
public XuggleVideo(File videoFile)
videoFile
- The video file to read.public XuggleVideo(File videoFile, boolean loop)
videoFile
- The video file to read.loop
- should the video looppublic XuggleVideo(String url)
url
- The URL of the file to readpublic XuggleVideo(URL url)
url
- The URL of the file to readpublic XuggleVideo(URL url, boolean loop)
getNextFrame()
will never return null; otherwise this method will return null at the end
of the video.url
- The URL of the file to readloop
- Whether to loop the video indefinitelypublic XuggleVideo(String url, boolean loop)
getNextFrame()
will never return null; otherwise this method will return null at the end
of the video.url
- The URL of the file to readloop
- Whether to loop the video indefinitelypublic XuggleVideo(InputStream stream)
stream
- The video data streampublic XuggleVideo(DataInput input)
input
- The video datapublic long countFrames()
countFrames
in class Video<MBFImage>
Video.countFrames()
public MBFImage getNextFrame()
getNextFrame
in class Video<MBFImage>
Video.getNextFrame()
public VideoTimecode getCurrentTimecode()
public MBFImage getCurrentFrame()
getCurrentFrame
in class Video<MBFImage>
Video.getCurrentFrame()
public int getWidth()
getWidth
in class Video<MBFImage>
Video.getWidth()
public int getHeight()
getHeight
in class Video<MBFImage>
Video.getHeight()
public boolean hasNextFrame()
hasNextFrame
in class Video<MBFImage>
Video.hasNextFrame()
public void reset()
Note: if you created the video from a DataInput
or
InputStream
, there is no way that it can be reset.
reset
in class Video<MBFImage>
Video.reset()
public void seekToBeginning()
Note: if you created the video from a DataInput
or
InputStream
, there is no way that it can be reset.
public long getTimeStamp()
getTimeStamp
in class Video<MBFImage>
Video.getTimeStamp()
public double getFPS()
getFPS
in class Video<MBFImage>
Video.getFPS()
public int getCurrentFrameIndex()
getCurrentFrameIndex
in class Video<MBFImage>
Video.getCurrentFrameIndex()
public void setCurrentFrameIndex(long newFrame)
setCurrentFrameIndex
in class Video<MBFImage>
newFrame
- the new indexVideo.setCurrentFrameIndex(long)
public void seekPrecise(double timestamp)
Note: if you created the video from a DataInput
or
InputStream
, you can only seek forwards.
timestamp
- The timestamp to get, in seconds.public void seek(double timestamp)
Note: if you created the video from a DataInput
or
InputStream
, you can only seek forwards.
seek
in class Video<MBFImage>
Video.seek(double)
public long getDuration()
public void close()
close
in interface Closeable
close
in interface AutoCloseable
close
in class Video<MBFImage>
Video.close()