Package org.opensourcephysics.media.core
Class ScratchVideoRecorder
java.lang.Object
org.opensourcephysics.media.core.ScratchVideoRecorder
- All Implemented Interfaces:
VideoRecorder
- Direct Known Subclasses:
GifVideoRecorder
,ImageVideoRecorder
,XuggleVideoRecorder
This VideoRecorder records to a scratch file which is then copied as needed.
- Version:
- 1.0
- Author:
- Douglas Brown
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected String
protected boolean
protected static JFileChooser
protected static JTextComponent
protected String
protected Dimension
protected static String
protected int
protected double
protected Image
protected boolean
protected static boolean
protected boolean
protected boolean
protected File
protected File
protected String
protected int
protected String
protected static String
protected String
protected static String
protected String
protected VideoType
-
Constructor Summary
ConstructorsConstructorDescriptionScratchVideoRecorder
(VideoType vidType) Constructs a ScratchVideoRecorder for the specified video type. -
Method Summary
Modifier and TypeMethodDescriptionvoid
Adds a video frame with the specified image.protected abstract boolean
Appends a frame to the current video.protected void
Creates the scratch file.void
Creates a new video (scratch file) and sets fileName to null.void
createVideo
(String fileName) Creates a new video and sets the destination file name.void
createVideo
(String fileName, String trkPath) Creates a new video with the specified file name.protected void
deleteFiles
(ArrayList<File> files) Deletes files.protected void
Deletes the temporary files.protected void
finalize()
Called by the garbage collector when this recorder is no longer in use.Gets the file name of the destination video.protected File
getFileToBeSaved
(File file) Return the file that will be saved if the specified file is selected.protected String
Returns the extension to use for the scratch file.getVideo()
Gets the current scratch video.Gets the VideoType.void
reset()
Discards the current video and resets the recorder to a ready state.protected abstract void
Saves the current video to the scratch file.Saves the scratch video to the current file or chooser file.Saves the current scratch video to the specified file name.Saves the scratch video to a file picked from a chooser.protected File
Shows a save dialog used to set the output movie file.static void
setChooserExtension
(String extension) Sets the extension used in the chooser.void
setFileName
(String path) Sets the file name.void
setFrameDuration
(double millis) Sets the time duration per frame.void
Sets the size of the video.protected abstract boolean
Starts the video recording process using current dimension dim.void
suggestFileName
(String name) Suggests a file name.Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.opensourcephysics.media.core.VideoRecorder
getCodec
-
Field Details
-
chooser
-
chooserField
-
ext
-
ignoreChooser
protected static boolean ignoreChooser -
tempDirectory
-
tempFilePrefix
-
videoType
-
dim
-
frameImage
-
frameDuration
protected double frameDuration -
frameCount
protected int frameCount -
scratchName
-
scratchNumber
protected int scratchNumber -
scratchFile
-
canRecord
protected boolean canRecord -
hasContent
protected boolean hasContent -
isSaved
protected boolean isSaved -
saveFile
-
saveChanges
protected boolean saveChanges -
tempFileBasePath
-
tempFileType
-
tempFiles
-
suggestedFileName
-
chosenExtension
-
baseDir
-
-
Constructor Details
-
ScratchVideoRecorder
Constructs a ScratchVideoRecorder for the specified video type.- Parameters:
vidType
- the video type
-
-
Method Details
-
createVideo
Creates a new video (scratch file) and sets fileName to null.- Specified by:
createVideo
in interfaceVideoRecorder
- Throws:
IOException
-
createVideo
Creates a new video and sets the destination file name. If fileName is null, the user can select a file with a chooser.- Specified by:
createVideo
in interfaceVideoRecorder
- Parameters:
fileName
- name of the file to which the video will be written- Throws:
IOException
-
createVideo
Description copied from interface:VideoRecorder
Creates a new video with the specified file name.- Specified by:
createVideo
in interfaceVideoRecorder
- Parameters:
fileName
- name of the file to which the video will be written- Throws:
IOException
-
setSize
Sets the size of the video.- Specified by:
setSize
in interfaceVideoRecorder
- Parameters:
dimension
- the dimensions of the new video
-
setFrameDuration
public void setFrameDuration(double millis) Sets the time duration per frame.- Specified by:
setFrameDuration
in interfaceVideoRecorder
- Parameters:
millis
- the duration per frame in milliseconds
-
addFrame
Adds a video frame with the specified image.- Specified by:
addFrame
in interfaceVideoRecorder
- Parameters:
image
- the image to be drawn on the video frame.- Throws:
IOException
-
getVideoType
Gets the VideoType.- Returns:
- the video type
-
getVideo
Gets the current scratch video.- Specified by:
getVideo
in interfaceVideoRecorder
- Returns:
- the video
- Throws:
IOException
-
saveVideo
Saves the scratch video to the current file or chooser file.- Specified by:
saveVideo
in interfaceVideoRecorder
- Returns:
- the full path to the saved file
- Throws:
IOException
-
saveVideo
Saves the current scratch video to the specified file name.- Specified by:
saveVideo
in interfaceVideoRecorder
- Parameters:
fileName
- the file name- Returns:
- the full path of the saved file
- Throws:
IOException
-
saveVideoAs
Saves the scratch video to a file picked from a chooser.- Specified by:
saveVideoAs
in interfaceVideoRecorder
- Returns:
- the full path of the saved file
- Throws:
IOException
-
getFileName
Gets the file name of the destination video.- Specified by:
getFileName
in interfaceVideoRecorder
- Returns:
- the file name
-
setFileName
Sets the file name. May be null.- Specified by:
setFileName
in interfaceVideoRecorder
- Parameters:
path
- the file name
-
suggestFileName
Suggests a file name. May be null.- Parameters:
name
- the file name
-
reset
public void reset()Discards the current video and resets the recorder to a ready state.- Specified by:
reset
in interfaceVideoRecorder
-
setChooserExtension
Sets the extension used in the chooser. -
createScratch
Creates the scratch file.- Throws:
IOException
-
getScratchExtension
Returns the extension to use for the scratch file.- Returns:
- the extension
-
selectFile
Shows a save dialog used to set the output movie file.- Returns:
- the movie file, or none if canceled by user
-
getFileToBeSaved
Return the file that will be saved if the specified file is selected. This is needed by ImageVideoRecorder since it strips and/or appends digits to the selected file name. This default implementation returns the file itself.- Parameters:
file
- the file selected with the chooser- Returns:
- the file (or first file) to be saved
-
finalize
protected void finalize()Called by the garbage collector when this recorder is no longer in use. -
deleteTempFiles
protected void deleteTempFiles()Deletes the temporary files. -
deleteFiles
Deletes files. -
saveScratch
Saves the current video to the scratch file.- Throws:
IOException
-
startRecording
protected abstract boolean startRecording()Starts the video recording process using current dimension dim.- Returns:
- true if video recording successfully started
-
append
Appends a frame to the current video.- Parameters:
image
- the image to append- Returns:
- true if image successfully appended
-