Class VideoIO

java.lang.Object
org.opensourcephysics.media.core.VideoIO
Direct Known Subclasses:
TrackerIO

public class VideoIO extends Object
This provides static methods for managing video and text input/output.
Version:
1.0
Author:
Douglas Brown
  • Field Details

  • Constructor Details

    • VideoIO

      protected VideoIO()
      protected constructor to discourage instantiation
  • Method Details

    • getExtension

      public static String getExtension(File file)
      Gets the extension of a file.
      Parameters:
      file - the file
      Returns:
      the extension of the file
    • getZippedImagePaths

      public static String[] getZippedImagePaths(String zipPath)
      Gets an array of image paths inside a zip file.
      Parameters:
      path - the path to the zip file OR to an image inside the zip file
      Returns:
      String[] with image paths in numerical order
    • getDelimiter

      public static String getDelimiter()
      Gets the delimiter for copied or exported data
      Returns:
      the delimiter
    • setDelimiter

      public static void setDelimiter(String d)
      Sets the delimiter for copied or exported data
      Parameters:
      d - the delimiter
    • getDelimiters

      public static Map<String,String> getDelimiters()
      Gets the delimiters for copied or exported data
      Returns:
      the delimiter map
    • getChooser

      public static javajs.async.AsyncFileChooser getChooser()
      Gets the file chooser.
      Returns:
      the file chooser
    • setDefaultXMLExtension

      public static void setDefaultXMLExtension(String ext)
      Sets the default xml extension used when saving data.
      Parameters:
      ext - the default extension
    • getRelativePath

      public static String getRelativePath(String absolutePath)
      Gets the path relative to the user directory.
      Parameters:
      absolutePath - the absolute path
      Returns:
      the relative path
    • testExec

      public static void testExec()
      test executing shell commands
    • getVideoExtensions

      public static String[] getVideoExtensions()
      Returns the currently supported video file extensions
      Returns:
      an array of extensions
    • getPreferredExportExtension

      public static String getPreferredExportExtension()
      Gets the preferred file extension for video exports.
      Returns:
      the preferred extension
    • setPreferredExportExtension

      public static void setPreferredExportExtension(String extension)
      Gets the preferred file extension for video exports.
      Parameters:
      extension - the preferred extension
    • addVideoType

      public static void addVideoType(VideoType type)
      Adds a video type to the list of available types
      Parameters:
      type - the video type
    • getMovieType

      public static MovieVideoType getMovieType(String extension)
    • getVideoType

      public static VideoType getVideoType(String typeName, String extension)
      Returns the first registered video type corresponding to a class name and/or extension. Strings are case-insensitive.
      Parameters:
      typeName - one of the predefined video type names (may be null)
      extension - the extension (may be null)
      Returns:
      the VideoType, or null if none found
    • getVideoTypesForPath

      public static ArrayList<VideoType> getVideoTypesForPath(String path)
      Gets an array of video types that can open files with a given extension.
      Parameters:
      ext - the extension
      Returns:
      the video types
    • getVideoTypes

      public static ArrayList<VideoType> getVideoTypes(boolean mustBeWritable)
      Gets an array of available video types
      Parameters:
      canRecord - true if we need a recorder (TrackerIO and VideoGrabber only)
      Returns:
      the video types
    • requiresReload

      public static void requiresReload(String zipPath)
      Adds a zip image file path to those requiring a reload rather than cached bytes. This is required when a zip file is overwritten, for example
      Parameters:
      zipPath -
    • setCanceled

      public static void setCanceled(boolean cancel)
      Cancels the current operation when true.
      Parameters:
      cancel - true to cancel
    • isCanceled

      public static boolean isCanceled()
      Determines if the current operation is canceled.
      Returns:
      true if canceled
    • isKnownVideoExtension

      public static boolean isKnownVideoExtension(String path)
      Determines if a path ends with a know video extension.
      Parameters:
      path - the path
      Returns:
      true if in KNOWN_VIDEO_EXTENSIONS
    • getVideoCodec

      public static String getVideoCodec(String path0)
    • handleUnsupportedVideo

      public static void handleUnsupportedVideo(String path0, String ext, String codec, VideoPanel vidPanel, String why)
    • getVideo

      public static Video getVideo(String path, VideoType vidType)
      Open a video from a video file opening or dropping. Returns a video from a specified path. May return null.
      Parameters:
      path - the path
      vidType - a requested video type (may be null)
      Returns:
      the video
    • getVideo

      public static Video getVideo(String path, String basePath, VideoType vidType, XMLControl control)
      Open a video from a TRK or TRZ file.
      Parameters:
      path -
      basePath -
      vidType -
      control -
      Returns:
    • clone

      public static Video clone(Video video)
      Returns a clone of the specified video. Never called.
      Parameters:
      video - the video to clone
      Returns:
      the clone
    • canWrite

      public static boolean canWrite(File file)
      Determines if a file can be written. If the file exists, the user is prompted for approval to overwrite.
      Parameters:
      file - the file to check
      Returns:
      true if the file can be written
    • getChooserFilesAsync

      public static File[] getChooserFilesAsync(String type, Function<File[],Void> processFiles)
      Displays a file chooser and returns the chosen files. The parameter "type" can be "open", "save video", "save resource", "save image", "open image". There are more types defined in TrackerIO.getChooserFilesAsync
      Parameters:
      type - String
      processFiles - asynchronous follower method
      Returns:
      the files, or null if no files chosen or asynchronous
    • processChoose

      protected static File processChoose(javajs.async.AsyncFileChooser chooser, File ret, boolean isAsync)
      Also used by TrackerIO
      Parameters:
      chooser -
      ret -
      isAsync -
      Returns:
    • openVideoPanelFileAsync

      public static void openVideoPanelFileAsync(File file, VideoPanel vidPanel)
      Loads the specified video panel from a file selected with a chooser or a video from a specified file into a VideoPanel. If file is null, a file chooser is displayed.
      Parameters:
      file - the file to be loaded
      vidPanel - the video panel
    • save

      public static File save(File file, VideoPanel vidPanel)
      Writes VideoPanel data to the specified file. If the file is null it brings up a chooser.
      Parameters:
      file - the file to write to
      vidPanel - the video panel
      Returns:
      the file written to, or null if not written
    • save

      public static File save(File file, VideoPanel vidPanel, String chooserTitle)
      Writes VideoPanel data to the specified file. If the file is null it displays a filechooser.
      Parameters:
      file - the file to write to
      vidPanel - the video panel
      chooserTitle - the title for the filechooser
      Returns:
      the file written to, or null if not written
    • writeImageFile

      public static File writeImageFile(BufferedImage image, String filePath)
      Writes an image to a file.
      Parameters:
      image - the image to write
      filePath - the path to write to, including extension (png, jpg, gif)
      Returns:
      the file written, or null if failed
    • getImageSequencePaths

      public static String[] getImageSequencePaths(String imagePath, Set<String> names)
      Gets the paths that make up an image sequence.
      Parameters:
      imagePath - the path to the first image
      names - a set of names of available numbered images
      Returns:
      array of full paths to all images in sequence
    • checkMP4

      public static boolean checkMP4(String path, LibraryBrowser libraryBrowser, VideoPanel panel)
      JavaScript only. Check for a valid video codec and file format. Handle it if it is an MP4 or MOV with unsupported codec From JSMovieVideo.load, TFrame.loadVideo, TrackerIO.AsyncLoader.loadVideo
      Parameters:
      path -
      libraryBrowser -
      Returns:
      true if not JS or not an mp4 and not mov, or not is a valid mp4/mov
    • progressForFraction

      public static int progressForFraction(double iFrame, double nFrames)