Class XuggleVideo
java.lang.Object
org.opensourcephysics.display.OSPRuntime.Supported
org.opensourcephysics.media.core.VideoAdapter
org.opensourcephysics.media.mov.MovieVideo
org.opensourcephysics.media.xuggle.XuggleVideo
- All Implemented Interfaces:
PropertyChangeListener
,EventListener
,Drawable
,Interactive
,Measurable
,DrawableImage
,IncrementallyLoadable
,InteractiveImage
,Trackable
,Video
,SmoothPlayable
A class to display videos using the Xuggle library. Xuggle in turn uses
FFMpeg as its video engine.
Support for B-Frames added by Bob Hanson 2021.01.10. As discussed at
https://groups.google.com/g/xuggler-users/c/PNggEjfsBcg by Art Clarke:
B-frames are frames that, in order to decode, you need P-frames from the future. They are used in the H264 and Theora codecs for more compression, but it means that a future P-frame (with a higher PTS) may show up with a DTS before a past B-frame (with a lower PTS). and The trick is that we report the DTS of frames (i.e. when they need to be decoded) not the PTS (presentation time stamps) in the indexes. DTS will always be in-order but PTS will not.Also adds imageCache to improve performance. Initially set to 50 images, but ALWAYS includes any !isComplete() pictures. These images are always precalculated.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
A class to save and load XuggleVideo data. -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected double[]
times from this engine for its reading of the starting times; distinct from startTimes, which may come from another creator via a video XMLControlElementFields inherited from class org.opensourcephysics.media.mov.MovieVideo
allowControlData, control, fileName, frameRateMaximum, frameRateMinimum, frameTimes, isExport, isLocal, isVariableFrameRate, nominalFrameRate, path, PLATFORM_JAVA, PROPERTY_VIDEO_PROGRESS, PROPERTY_VIDEO_STALLED, rawDuration, rawFrameCount, TIME_SLOP_MS, url
Fields inherited from class org.opensourcephysics.media.core.VideoAdapter
aspects, baseDir, bufferedImage, clearRaster, coords, displayedSize, endFrameNumber, filteredImage, filterStack, frameCount, frameNumber, isMeasured, isValidFilteredImage, isValidImage, isValidMeasure, looping, maxX, maxY, minX, minY, mouseEnabled, playing, properties, rate, rawImage, size, startFrameNumber, startTimesMS, visible, widthDominates
Fields inherited from interface org.opensourcephysics.media.core.Trackable
PROPERTY_ADJUSTING
Fields inherited from interface org.opensourcephysics.media.core.Video
PROPERTY_VIDEO_COORDS, PROPERTY_VIDEO_ENDFRAME, PROPERTY_VIDEO_FILTERCHANGED, PROPERTY_VIDEO_FRAMENUMBER, PROPERTY_VIDEO_IMAGE, PROPERTY_VIDEO_LOOPING, PROPERTY_VIDEO_NEXTFRAME, PROPERTY_VIDEO_PLAYING, PROPERTY_VIDEO_RATE, PROPERTY_VIDEO_SIZE, PROPERTY_VIDEO_VIDEOVISIBLE
-
Method Summary
Modifier and TypeMethodDescriptionprotected void
Plays the next time-appropriate frame at the current rate.void
dispose()
Disposes of this video.protected void
double
Gets the duration of the media, including a time for the last frame From XuggleVideo code, now also for JSMovieVideoprotected BufferedImage
getImageForMSTimePoint
(double timeMS) int
Get the total number of frames expected.int
Get the total number of frames loaded.static XML.ObjectLoader
Returns an XML.ObjectLoader to save and load XuggleVideo data.protected String
Get this platform's nameprotected int
getRawFrameNumberBefore
(double time) Currently not called.Returns the VideoType name of this video.boolean
Determines if the video is fully loaded.boolean
Gets the playSmoothly flag.boolean
loadMoreFrames
(int n) Attempt to load n more frames.void
play()
Plays the video at the current rate.protected boolean
seekMS
(double timeMS) uses seekKeyFrame: Seeks to timestamp in the container.void
setFrameNumber
(int n) Sets the frame number.void
setLoadableFrameCount
(int n) Set the total number of frames expected.void
setRate
(double rate) Sets the relative play rate.void
setSmoothPlay
(boolean smooth) Sets the playSmoothly flag.void
stop()
Stops the video.Methods inherited from class org.opensourcephysics.media.mov.MovieVideo
getFrameNumberBefore, setFromControl, setFromMediaTrackInfo, setStartTimes
Methods inherited from class org.opensourcephysics.media.core.VideoAdapter
back, draw, finalize, findInteractive, findMinMaxValues, getAbsolutePath, getAngle, getCoords, getEndFrameNumber, getEndTime, getFilterStack, getFrameCount, getFrameDuration, getFrameNumber, getFrameTime, getHeight, getImage, getImageSize, getProperty, getPropertyNames, getRate, getRawBufferedImage, getRelativeAspect, getStartFrameNumber, getStartTime, getWidth, getX, getXMax, getXMin, getY, getYMax, getYMin, goToEnd, goToStart, initialize, invalidateVideoAndFilter, isEnabled, isLooping, isMeasured, isPlaying, isVisible, notifyFrame, notifySize, propertyChange, refreshBufferedImage, reset, setAngle, setCoords, setEnabled, setEndFrameNumber, setEndTime, setFilterStack, setFrameAngle, setFrameCount, setFrameHeight, setFrameRelativeAspect, setFrameWidth, setFrameX, setFrameXY, setFrameY, setHeight, setLooping, setNotify, setPlaying, setProperty, setRelativeAspect, setStartFrameNumber, setStartTime, setVisible, setWidth, setX, setXY, setY, step, updateBufferedImage
Methods inherited from class org.opensourcephysics.display.OSPRuntime.Supported
addListeners, addPropertyChangeListener, addPropertyChangeListener, addPropertyChangeListenerSafely, dispose, firePropertyChange, firePropertyChange, removeListeners, removePropertyChangeListener, removePropertyChangeListener
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.opensourcephysics.display.Interactive
isInteractive
Methods inherited from interface org.opensourcephysics.media.core.Video
addListener, addPropertyChangeListener, addPropertyChangeListener, getAverageFrameDuration, getAverageFrameRate, getOutliers, isValid, removeListener, removePropertyChangeListener, removePropertyChangeListener
-
Field Details
-
rawStartTimes
protected double[] rawStartTimestimes from this engine for its reading of the starting times; distinct from startTimes, which may come from another creator via a video XMLControlElement
-
-
Method Details
-
getRawFrameNumberBefore
protected int getRawFrameNumberBefore(double time) Currently not called. Gets the number of the last frame before the specified time in milliseconds for the "raw" start times - the ones for this engine, not the ones from controls. If rawStartTimes is null (always the case in JavaScript), then just use startTimes. It is not clear yet whether A 0.1-ms slop is added to ensure that double rounding errors are not involved- Parameters:
time
- the time in milliseconds- Returns:
- the frame number, or -1 if not found
-
finalizeLoading
- Specified by:
finalizeLoading
in classMovieVideo
- Throws:
IOException
-
loadMoreFrames
Description copied from interface:IncrementallyLoadable
Attempt to load n more frames.- Specified by:
loadMoreFrames
in interfaceIncrementallyLoadable
- Parameters:
n
- the number of additional frames to load- Returns:
- true if n additional frames were loaded, false if fewer or none loaded
- Throws:
IOException
-
play
public void play()Plays the video at the current rate. Overrides VideoAdapter method. -
stop
public void stop()Stops the video. -
setFrameNumber
public void setFrameNumber(int n) Sets the frame number. Overrides VideoAdapter setFrameNumber method.- Specified by:
setFrameNumber
in interfaceVideo
- Overrides:
setFrameNumber
in classVideoAdapter
- Parameters:
n
- the desired frame number- See Also:
-
setRate
public void setRate(double rate) Sets the relative play rate. Overrides VideoAdapter method.- Specified by:
setRate
in interfaceVideo
- Overrides:
setRate
in classVideoAdapter
- Parameters:
rate
- the relative play rate.
-
getFrameCountDurationMS
public double getFrameCountDurationMS()Gets the duration of the media, including a time for the last frame From XuggleVideo code, now also for JSMovieVideo// ....[0][1][2]...[startFrame][i]...[j][endFrame]...[frameCount-1] // ....|-----------------duration---------------------------------] // ....^..^..^..^..^...........^..^..^..^.........^..^ startTimes[i] // ............................|--| frameDuration[i] // ..................................................|------------| // ..................................................frameDuration[frameCoumt-1] // (note that final frame duration is defined // as frameDuration[frameCount-2] here)
- Specified by:
getFrameCountDurationMS
in interfaceVideo
- Returns:
- the duration of the media in milliseconds or -1 if no video, or 100 if one frame
-
setSmoothPlay
public void setSmoothPlay(boolean smooth) Sets the playSmoothly flag.- Specified by:
setSmoothPlay
in interfaceSmoothPlayable
- Parameters:
smooth
- true to play smoothly
-
isSmoothPlay
public boolean isSmoothPlay()Gets the playSmoothly flag.- Specified by:
isSmoothPlay
in interfaceSmoothPlayable
- Returns:
- true if playing smoothly
-
dispose
public void dispose()Disposes of this video.- Specified by:
dispose
in interfaceVideo
- Overrides:
dispose
in classVideoAdapter
-
continuePlaying
protected void continuePlaying()Plays the next time-appropriate frame at the current rate. -
seekMS
protected boolean seekMS(double timeMS) uses seekKeyFrame: Seeks to timestamp in the container. Seeking will be done so that the point from which all active streams can be presented successfully will be closest to targetTimeStamp and within minTimeStamp/maxTimeStamp. If flags contain SEEK_FLAG_BYTE, then all time stamps are in bytes and are the file position (this may not be supported by all demuxers). If flags contain SEEK_FLAG_FRAME, then all time stamps are in frames in the stream with streamIndex (this may not be supported by all demuxers). Otherwise all time stamps are in units of the stream selected by stream_index or if stream_index is -1, in microseconds. If flags contain SEEK_FLAG_ANY, then non-keyframes are treated as keyframes (this may not be supported by all demuxers). If flags contain SEEK_FLAG_BACKWARDS, then we will attempt to search backwards in the container (this may not be supported by all demuxers and file protocols). This is part of the new seek API which is still under construction. It may change in future Xuggler versions. Parameters: streamIndex - index of the stream which is used as time base reference minTimeStamp - smallest acceptable time stamp. targetTimeStamp - target time stamp. maxTimeStamp - largest acceptable time stamp. flags - A bitmask of the SEEK_FLAG_* flags, or 0 to turn all flags off. Returns: >=0 on success, error code otherwise Since: 3.4- Specified by:
seekMS
in classMovieVideo
- Returns:
-
getImageForMSTimePoint
- Specified by:
getImageForMSTimePoint
in classMovieVideo
-
getTypeName
Description copied from interface:Video
Returns the VideoType name of this video.- Specified by:
getTypeName
in interfaceVideo
-
getLoadedFrameCount
public int getLoadedFrameCount()Description copied from interface:IncrementallyLoadable
Get the total number of frames loaded.- Specified by:
getLoadedFrameCount
in interfaceIncrementallyLoadable
- Returns:
- the number of frames loaded
-
isFullyLoaded
public boolean isFullyLoaded()Description copied from interface:IncrementallyLoadable
Determines if the video is fully loaded.- Specified by:
isFullyLoaded
in interfaceIncrementallyLoadable
- Returns:
- true if fully loaded
-
getLoadableFrameCount
public int getLoadableFrameCount()Description copied from interface:IncrementallyLoadable
Get the total number of frames expected.- Specified by:
getLoadableFrameCount
in interfaceIncrementallyLoadable
- Returns:
-
setLoadableFrameCount
public void setLoadableFrameCount(int n) Description copied from interface:IncrementallyLoadable
Set the total number of frames expected.- Specified by:
setLoadableFrameCount
in interfaceIncrementallyLoadable
- Parameters:
n
- the number of frames expected
-
getLoader
Returns an XML.ObjectLoader to save and load XuggleVideo data.- Returns:
- the object loader
-
getPlatform
Description copied from class:MovieVideo
Get this platform's name- Specified by:
getPlatform
in classMovieVideo
- Returns:
- "Java" or navigator.userAgent
-