Class XuggleVideo

All Implemented Interfaces:
PropertyChangeListener, EventListener, Drawable, Interactive, Measurable, DrawableImage, IncrementallyLoadable, InteractiveImage, Trackable, Video, SmoothPlayable

public class XuggleVideo extends MovieVideo implements SmoothPlayable, IncrementallyLoadable
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.
  • Field Details

    • rawStartTimes

      protected double[] rawStartTimes
      times 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

      protected void finalizeLoading() throws IOException
      Specified by:
      finalizeLoading in class MovieVideo
      Throws:
      IOException
    • loadMoreFrames

      public boolean loadMoreFrames(int n) throws IOException
      Description copied from interface: IncrementallyLoadable
      Attempt to load n more frames.
      Specified by:
      loadMoreFrames in interface IncrementallyLoadable
      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.
      Specified by:
      play in interface Video
    • stop

      public void stop()
      Stops the video.
      Specified by:
      stop in interface Video
    • setFrameNumber

      public void setFrameNumber(int n)
      Sets the frame number. Overrides VideoAdapter setFrameNumber method.
      Specified by:
      setFrameNumber in interface Video
      Overrides:
      setFrameNumber in class VideoAdapter
      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 interface Video
      Overrides:
      setRate in class VideoAdapter
      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 interface Video
      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 interface SmoothPlayable
      Parameters:
      smooth - true to play smoothly
    • isSmoothPlay

      public boolean isSmoothPlay()
      Gets the playSmoothly flag.
      Specified by:
      isSmoothPlay in interface SmoothPlayable
      Returns:
      true if playing smoothly
    • dispose

      public void dispose()
      Disposes of this video.
      Specified by:
      dispose in interface Video
      Overrides:
      dispose in class VideoAdapter
    • 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 class MovieVideo
      Returns:
    • getImageForMSTimePoint

      protected BufferedImage getImageForMSTimePoint(double timeMS)
      Specified by:
      getImageForMSTimePoint in class MovieVideo
    • getTypeName

      public String getTypeName()
      Description copied from interface: Video
      Returns the VideoType name of this video.
      Specified by:
      getTypeName in interface Video
    • getLoadedFrameCount

      public int getLoadedFrameCount()
      Description copied from interface: IncrementallyLoadable
      Get the total number of frames loaded.
      Specified by:
      getLoadedFrameCount in interface IncrementallyLoadable
      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 interface IncrementallyLoadable
      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 interface IncrementallyLoadable
      Returns:
    • setLoadableFrameCount

      public void setLoadableFrameCount(int n)
      Description copied from interface: IncrementallyLoadable
      Set the total number of frames expected.
      Specified by:
      setLoadableFrameCount in interface IncrementallyLoadable
      Parameters:
      n - the number of frames expected
    • getLoader

      public static XML.ObjectLoader getLoader()
      Returns an XML.ObjectLoader to save and load XuggleVideo data.
      Returns:
      the object loader
    • getPlatform

      protected String getPlatform()
      Description copied from class: MovieVideo
      Get this platform's name
      Specified by:
      getPlatform in class MovieVideo
      Returns:
      "Java" or navigator.userAgent