CAVAPA-GUI  30.5.2014
 All Classes Namespaces Functions Variables Typedefs Enumerations Pages
Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | Static Protected Attributes | List of all members
cavapa_gui::VideoFile Class Reference

The class for the video file source. More...

#include <videofile.h>

Inheritance diagram for cavapa_gui::VideoFile:
cavapa_gui::Source cavapa_gui::VideoFileSet

Public Member Functions

 VideoFile (SourceID desired_id=UNDEFINED_SOURCE)
 Creates a new source. More...
 
bool canRecord () const overridefinal
 Returns information on the source recording abilities. More...
 
virtual void fetchFirstFrame ()
 Seeks the startup point of the video and the first frame.
 
virtual FrameCapture get (FrameTime passed_time) override
 Retrieves the next frame from the camera. More...
 
virtual double getBarrelCorrection () override
 Returns the barrel correction applied to the source frames. More...
 
int getCurrentFrame () const
 Returns the current frame of the video shown. More...
 
virtual std::string getDescription () const override
 Retrieves the description of the source. More...
 
virtual std::vector< std::string > getFilenames () const
 Returns the filenames of the source. More...
 
virtual double getFramerate () const override
 Retrieves the framerate. More...
 
virtual FrameTime getLength () const final
 Retrieves the video file length. More...
 
virtual FrameTime getPosition () const overridefinal
 Retrieves the current time position of the source. More...
 
virtual cv::Size getResolution () const override
 Retrieves the resolution of the source. More...
 
virtual SourceType getSourceType () const override
 Returns the type of the source. More...
 
virtual SourceStats getStats () override
 Retrieves the source statistical information. More...
 
virtual bool hasNew () override
 Checks whether the device has a new image to be retrieved or not. More...
 
virtual bool isOpen () const override
 Checks whether the source has been initialized or not. More...
 
virtual bool isPlaying () const override
 Checks whether the source is playing or not. More...
 
virtual bool open (const std::string &filename, bool get_first, FrameTime start_point)
 Opens a video file. More...
 
virtual void play () override
 Starts frame updates on the file. More...
 
bool record (const std::string &filename, const std::string &codec="") overridefinal
 Starts the recording of the source to the file. More...
 
virtual void release ()
 Forces the release of the worker thread. More...
 
bool seekTime (FrameTime pos)
 Seeks a specific position of the video frame. More...
 
virtual bool skipFrame (int step)
 Skips the specific amount of frames on the video. More...
 
virtual void setBarrelCorrection (double amount) override
 Sets the new barrel correction value. More...
 
void setCurrentAsStartPoint ()
 Sets the current video time as the seeking start point. More...
 
bool setResolution (const cv::Size &new_size) overridefinal
 Should change resolution, but does not have an effect on video files. More...
 
virtual FrameTime startPoint () const final
 Returns the start point of the video file. More...
 
virtual void stop () override
 Will stop the file from playing. More...
 
int totalFrames () const
 Returns the total count of the frames in the video file. More...
 
- Public Member Functions inherited from cavapa_gui::Source
 DISALLOW_COPY_AND_ASSIGN (Source)
 Copy and assign of the class is not allowed.
 
virtual SourceID getID () const final
 Gets the unique source ID number. More...
 
virtual void resetStats () final
 Resets the source statistics.
 

Static Public Member Functions

static void setSpeed (double multiplier)
 Sets playing speed of the video file. More...
 

Protected Member Functions

FrameTime currentFrameTime () const
 Returns the time of the currently buffered frame. More...
 
int frameFromFrameTime (FrameTime time) const
 Returns the expected frame number from the frame time. More...
 
FrameTime frameTimeFromFrame (int frame) const
 Returns the expected frame time of the given frame. More...
 
- Protected Member Functions inherited from cavapa_gui::Source
 Source (SourceID desired_id=UNDEFINED_SOURCE)
 General Source creator. More...
 

Protected Attributes

int current_frame
 The number of the currently buffered frame.
 
FrameTime initial_position
 The initial position of the video file.
 
bool opened = false
 The open status of the video file.
 
bool playing = false
 The flag indicates if the video file is playing or not.
 
int total_frames = 0
 The total frames in the video file.
 
FrameTime video_time = 0
 The current time of the video file.
 
- Protected Attributes inherited from cavapa_gui::Source
SourceStats statistics = EMPTY_SOURCE_STATS
 The statistics of the source.
 

Static Protected Attributes

static double speed_ratio = 1.0
 The multiplier of the video file playing speed.
 

Detailed Description

The class for the video file source.

The class uses OpenCV to retrieve images from the video files. The video files can be played, stopped and stepped frame by frame. You can also seek the specific point of the video. Unlike Camera, the class does not support recording, or any alterations to framerate or resolution of the source.

Author
Petri Partanen

Constructor & Destructor Documentation

cavapa_gui::VideoFile::VideoFile ( SourceID  desired_id = UNDEFINED_SOURCE)
inline

Creates a new source.

Parameters
desired_idThe desired ID number. Use UNDEFINED_SOURCE if you do not want to define it to a specific ID. This does not check if the source with the given ID already exists. The ID number will not be given other new sources with UNDEFINED_SOURCE ID numbers.

Member Function Documentation

bool cavapa_gui::VideoFile::canRecord ( ) const
inlinefinaloverridevirtual

Returns information on the source recording abilities.

Returns
True if the source can record, false otherwise.
False. The video files can't be recorded.

Implements cavapa_gui::Source.

FrameTime cavapa_gui::VideoFile::currentFrameTime ( ) const
inlineprotected

Returns the time of the currently buffered frame.

Returns
Last updated frame time in ms.
int cavapa_gui::VideoFile::frameFromFrameTime ( FrameTime  time) const
inlineprotected

Returns the expected frame number from the frame time.

This is used to skip video frames if the retrieval is lagging behind on what the real time actually is.

Parameters
timeThe frame time where frame number is to be calculated.
Returns
The frame on which the time stamp should be.
FrameTime cavapa_gui::VideoFile::frameTimeFromFrame ( int  frame) const
inlineprotected

Returns the expected frame time of the given frame.

Parameters
frameThe number of the frame.
Returns
FrameTime for this frame with the videos framerate.
FrameCapture cavapa_gui::VideoFile::get ( FrameTime  passed_time)
overridevirtual

Retrieves the next frame from the camera.

The time supplied to the function informs the source about how much time has passed since the last image retrieval. The source will depend on its internal clock, either retrieving a new image or returning the buffered image that it retrieved previously.

Parameters
passed_timeThe time passed since the last call (in milliseconds).
Returns
The latest frame capture. This will actually return a reference to the original image, so you are NOT allowed to edit it! Otherwise the source buffer will be altered too. This is just the way OpenCV handles Mat memory.

Implements cavapa_gui::Source.

Reimplemented in cavapa_gui::VideoFileSet.

virtual double cavapa_gui::VideoFile::getBarrelCorrection ( )
inlineoverridevirtual

Returns the barrel correction applied to the source frames.

Returns
The barrel effect value.

Implements cavapa_gui::Source.

Reimplemented in cavapa_gui::VideoFileSet.

int cavapa_gui::VideoFile::getCurrentFrame ( ) const
inline

Returns the current frame of the video shown.

Returns
The frame number on 0-based linear index.
string cavapa_gui::VideoFile::getDescription ( ) const
overridevirtual

Retrieves the description of the source.

Returns
The source description.

Implements cavapa_gui::Source.

Reimplemented in cavapa_gui::VideoFileSet.

virtual std::vector<std::string> cavapa_gui::VideoFile::getFilenames ( ) const
inlinevirtual

Returns the filenames of the source.

Returns
The video filenames.

Reimplemented in cavapa_gui::VideoFileSet.

virtual double cavapa_gui::VideoFile::getFramerate ( ) const
inlineoverridevirtual

Retrieves the framerate.

Returns
The framerate or 0.0 if not supported.

Implements cavapa_gui::Source.

Reimplemented in cavapa_gui::VideoFileSet.

virtual FrameTime cavapa_gui::VideoFile::getLength ( ) const
inlinefinalvirtual

Retrieves the video file length.

Returns
The video length in milliseconds.
virtual FrameTime cavapa_gui::VideoFile::getPosition ( ) const
inlinefinaloverridevirtual

Retrieves the current time position of the source.

Returns
The source time position.

Implements cavapa_gui::Source.

virtual cv::Size cavapa_gui::VideoFile::getResolution ( ) const
inlineoverridevirtual

Retrieves the resolution of the source.

Returns
The source resolution.

Implements cavapa_gui::Source.

Reimplemented in cavapa_gui::VideoFileSet.

virtual SourceType cavapa_gui::VideoFile::getSourceType ( ) const
inlineoverridevirtual

Returns the type of the source.

Returns
The source type.

Reimplemented from cavapa_gui::Source.

Reimplemented in cavapa_gui::VideoFileSet.

SourceStats cavapa_gui::VideoFile::getStats ( )
overridevirtual

Retrieves the source statistical information.

Returns
The source statistics.

Implements cavapa_gui::Source.

Reimplemented in cavapa_gui::VideoFileSet.

virtual bool cavapa_gui::VideoFile::hasNew ( )
inlineoverridevirtual

Checks whether the device has a new image to be retrieved or not.

This checks if the FrameTime on the buffered image differs from what was retrieved on the last get().

Returns
True if a new image available or false otherwise.
Remarks
This is protected by a mutex and should not be used when time is critical. Use it only when you know that any lag produced by this is not going to be a problem.

Implements cavapa_gui::Source.

Reimplemented in cavapa_gui::VideoFileSet.

virtual bool cavapa_gui::VideoFile::isOpen ( ) const
inlineoverridevirtual

Checks whether the source has been initialized or not.

Returns
True if it is initialized or false otherwise.

Implements cavapa_gui::Source.

virtual bool cavapa_gui::VideoFile::isPlaying ( ) const
inlineoverridevirtual

Checks whether the source is playing or not.

Returns
True if the source is playing or false otherwise.

Implements cavapa_gui::Source.

bool cavapa_gui::VideoFile::open ( const std::string &  filename,
bool  get_first,
FrameTime  start_point 
)
virtual

Opens a video file.

Parameters
filenameThe path of the video file.
get_firstIf the first image of the video should be retrieved or not. This is useful in most cases, but if we are opening multiple video files of the same source it might be wise to set this false. This way a worker thread of the frame retrieval is not automatically started.
start_pointThe video start point. This will be used as the initial position of the video. All seekTime() calls will be based on the position.
Returns
True if the file was opened successfully or false otherwise.

Reimplemented in cavapa_gui::VideoFileSet.

virtual void cavapa_gui::VideoFile::play ( )
inlineoverridevirtual

Starts frame updates on the file.

After the video file has been set to play, it will start to retrieve new frames for each get() call.

Reimplemented from cavapa_gui::Source.

Reimplemented in cavapa_gui::VideoFileSet.

bool cavapa_gui::VideoFile::record ( const std::string &  filename,
const std::string &  codec = "" 
)
inlinefinaloverridevirtual

Starts the recording of the source to the file.

This can also be used to start an entirely new video file during the recording. The recording file will change immediately.

Parameters
filenameThe path of the recording file.
codecThe codec to be used for recording.
Returns
True if the recording started or false otherwise.
Parameters
filenameNot used.
codecNot used.
Returns
False.
Remarks
Does nothing. It is safe to call this.

Implements cavapa_gui::Source.

virtual void cavapa_gui::VideoFile::release ( )
inlinevirtual

Forces the release of the worker thread.

This is used when multiple video files are combined as a one source of video. When the particular video file is currently not being accessed, the worker thread can be released to free up system's resources. The worker thread is again automatically started when the get() function is called. These threads are sleeping when no frames are being fetched, but the system still has limited amount of threads at its disposal. If you plan to use hundreds of them, then you should release the ones you don't need at the time.

Remarks
Calling the function might produce a slight lag as it waits for the thread to finish first.
bool cavapa_gui::VideoFile::seekTime ( FrameTime  pos)

Seeks a specific position of the video frame.

This does not use the actual start position of the video.

Parameters
posThe new desired video frame position.
Returns
True if seeking was successful or false otherwise.
Remarks
Unknown when this actually does fail, might be never on video files.
virtual void cavapa_gui::VideoFile::setBarrelCorrection ( double  amount)
inlineoverridevirtual

Sets the new barrel correction value.

The value is used to correct barrel effect (lens correction) on each image that the source will return.

Parameters
amountThe barrel value.

Implements cavapa_gui::Source.

Reimplemented in cavapa_gui::VideoFileSet.

void cavapa_gui::VideoFile::setCurrentAsStartPoint ( )
inline

Sets the current video time as the seeking start point.

Remarks
This is usually given in the open() function but there might be a reason to do this manually too.
bool cavapa_gui::VideoFile::setResolution ( const cv::Size &  new_size)
inlinefinaloverridevirtual

Should change resolution, but does not have an effect on video files.

It is safe to call this.

Parameters
new_sizeNot used.
Returns
False.
Remarks
This method does nothing.

Implements cavapa_gui::Source.

static void cavapa_gui::VideoFile::setSpeed ( double  multiplier)
inlinestatic

Sets playing speed of the video file.

Parameters
multiplierThe speed multiplier for the video file. The default is 1.0.
bool cavapa_gui::VideoFile::skipFrame ( int  step)
virtual

Skips the specific amount of frames on the video.

The positive numbers skip forward and negatives skip backward. The frame will be limited to the actual limits of the video, skipping 10 million frames will just seek to the last frame of the video.

Parameters
stepThe desired frame change.
Returns
True if the skipping was successful or false otherwise.
Remarks
Unknown when this actually does fail. It might be never on video files.

Reimplemented in cavapa_gui::VideoFileSet.

virtual FrameTime cavapa_gui::VideoFile::startPoint ( ) const
inlinefinalvirtual

Returns the start point of the video file.

Returns
The first frame of the initial position.
virtual void cavapa_gui::VideoFile::stop ( )
inlineoverridevirtual

Will stop the file from playing.

Any calls to function get() will return the same buffered image and will not advance the videos internal clock. Use play() to start retrieving images again.

Implements cavapa_gui::Source.

Reimplemented in cavapa_gui::VideoFileSet.

int cavapa_gui::VideoFile::totalFrames ( ) const
inline

Returns the total count of the frames in the video file.

Returns
The frame count. 0 usually means that the video file is broken and cannot determine the total frame count. They can still be played.

The documentation for this class was generated from the following files: