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 classA 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, urlFields 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, widthDominatesFields inherited from interface org.opensourcephysics.media.core.Trackable
PROPERTY_ADJUSTINGFields 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 voidPlays the next time-appropriate frame at the current rate.voiddispose()Disposes of this video.protected voiddoubleGets the duration of the media, including a time for the last frame From XuggleVideo code, now also for JSMovieVideoprotected BufferedImagegetImageForMSTimePoint(double timeMS) intGet the total number of frames expected.intGet the total number of frames loaded.static XML.ObjectLoaderReturns an XML.ObjectLoader to save and load XuggleVideo data.protected StringGet this platform's nameprotected intgetRawFrameNumberBefore(double time) Currently not called.Returns the VideoType name of this video.booleanDetermines if the video is fully loaded.booleanGets the playSmoothly flag.booleanloadMoreFrames(int n) Attempt to load n more frames.voidplay()Plays the video at the current rate.protected booleanseekMS(double timeMS) uses seekKeyFrame: Seeks to timestamp in the container.voidsetFrameNumber(int n) Sets the frame number.voidsetLoadableFrameCount(int n) Set the total number of frames expected.voidsetRate(double rate) Sets the relative play rate.voidsetSmoothPlay(boolean smooth) Sets the playSmoothly flag.voidstop()Stops the video.Methods inherited from class org.opensourcephysics.media.mov.MovieVideo
getFrameNumberBefore, setFromControl, setFromMediaTrackInfo, setStartTimesMethods 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, updateBufferedImageMethods inherited from class org.opensourcephysics.display.OSPRuntime.Supported
addListeners, addPropertyChangeListener, addPropertyChangeListener, addPropertyChangeListenerSafely, dispose, firePropertyChange, firePropertyChange, removeListeners, removePropertyChangeListener, removePropertyChangeListenerMethods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.opensourcephysics.display.Interactive
isInteractiveMethods 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:
finalizeLoadingin classMovieVideo- Throws:
IOException
-
loadMoreFrames
Description copied from interface:IncrementallyLoadableAttempt to load n more frames.- Specified by:
loadMoreFramesin 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:
setFrameNumberin interfaceVideo- Overrides:
setFrameNumberin 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:
setRatein interfaceVideo- Overrides:
setRatein 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:
getFrameCountDurationMSin 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:
setSmoothPlayin interfaceSmoothPlayable- Parameters:
smooth- true to play smoothly
-
isSmoothPlay
public boolean isSmoothPlay()Gets the playSmoothly flag.- Specified by:
isSmoothPlayin interfaceSmoothPlayable- Returns:
- true if playing smoothly
-
dispose
public void dispose()Disposes of this video.- Specified by:
disposein interfaceVideo- Overrides:
disposein 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:
seekMSin classMovieVideo- Returns:
-
getImageForMSTimePoint
- Specified by:
getImageForMSTimePointin classMovieVideo
-
getTypeName
Description copied from interface:VideoReturns the VideoType name of this video.- Specified by:
getTypeNamein interfaceVideo
-
getLoadedFrameCount
public int getLoadedFrameCount()Description copied from interface:IncrementallyLoadableGet the total number of frames loaded.- Specified by:
getLoadedFrameCountin interfaceIncrementallyLoadable- Returns:
- the number of frames loaded
-
isFullyLoaded
public boolean isFullyLoaded()Description copied from interface:IncrementallyLoadableDetermines if the video is fully loaded.- Specified by:
isFullyLoadedin interfaceIncrementallyLoadable- Returns:
- true if fully loaded
-
getLoadableFrameCount
public int getLoadableFrameCount()Description copied from interface:IncrementallyLoadableGet the total number of frames expected.- Specified by:
getLoadableFrameCountin interfaceIncrementallyLoadable- Returns:
-
setLoadableFrameCount
public void setLoadableFrameCount(int n) Description copied from interface:IncrementallyLoadableSet the total number of frames expected.- Specified by:
setLoadableFrameCountin 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:MovieVideoGet this platform's name- Specified by:
getPlatformin classMovieVideo- Returns:
- "Java" or navigator.userAgent
-