Main MRPT website > C++ reference for MRPT 1.9.9
List of all members | Public Member Functions | Private Attributes
mrpt::hwdrivers::CFFMPEG_InputStream Class Reference

Detailed Description

A generic class which process a video file or other kind of input stream (http, rtsp) and allows the extraction of images frame by frame.

Video sources can be open with "openURL", which can manage both video files and "rtsp://" sources (IP cameras).

Frames are retrieved by calling CFFMPEG_InputStream::retrieveFrame

For an example of usage, see the file "samples/grab_camera_ffmpeg"

Note
This class is an easy to use C++ wrapper for ffmpeg libraries (libavcodec). In Unix systems these libraries must be installed in the system as explained in MRPT's wiki. In Win32, a precompiled version for Visual Studio must be also downloaded as explained in the wiki.

Definition at line 43 of file CFFMPEG_InputStream.h.

#include <mrpt/hwdrivers/CFFMPEG_InputStream.h>

Public Member Functions

 CFFMPEG_InputStream ()
 Default constructor, does not open any video source at startup. More...
 
virtual ~CFFMPEG_InputStream ()
 Destructor. More...
 
bool openURL (const std::string &url, bool grab_as_grayscale=false, bool verbose=false)
 Open a video file or a video stream (rtsp://) This can be used to open local video files (eg. More...
 
bool isOpen () const
 Return whether the video source was open correctly. More...
 
void close ()
 Close the video stream (this is called automatically at destruction). More...
 
double getVideoFPS () const
 Get the frame-per-second (FPS) of the video source, or "-1" if the video is not open. More...
 
bool retrieveFrame (mrpt::utils::CImage &out_img)
 Get the next frame from the video stream. More...
 

Private Attributes

mrpt::utils::void_ptr_noncopy m_state
 The internal ffmpeg state. More...
 
std::string m_url
 The open URL. More...
 
bool m_grab_as_grayscale
 

Constructor & Destructor Documentation

◆ CFFMPEG_InputStream()

CFFMPEG_InputStream::CFFMPEG_InputStream ( )

Default constructor, does not open any video source at startup.

Definition at line 65 of file CFFMPEG_InputStream.cpp.

References m_state, MY_FFMPEG_STATE, mrpt::utils::non_copiable_ptr_basic< T >::set(), and THROW_EXCEPTION.

Here is the call graph for this function:

◆ ~CFFMPEG_InputStream()

CFFMPEG_InputStream::~CFFMPEG_InputStream ( )
virtual

Destructor.

Definition at line 89 of file CFFMPEG_InputStream.cpp.

References close(), m_state, MY_FFMPEG_STATE, and mrpt::utils::non_copiable_ptr_basic< T >::set().

Here is the call graph for this function:

Member Function Documentation

◆ close()

void CFFMPEG_InputStream::close ( )

Close the video stream (this is called automatically at destruction).

See also
openURL

Definition at line 282 of file CFFMPEG_InputStream.cpp.

References isOpen(), and MY_FFMPEG_STATE.

Referenced by openURL(), mrpt::hwdrivers::CRovio::thread_video(), and ~CFFMPEG_InputStream().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getVideoFPS()

double CFFMPEG_InputStream::getVideoFPS ( ) const

Get the frame-per-second (FPS) of the video source, or "-1" if the video is not open.

Definition at line 432 of file CFFMPEG_InputStream.cpp.

References isOpen(), and MY_FFMPEG_STATE.

Here is the call graph for this function:

◆ isOpen()

bool CFFMPEG_InputStream::isOpen ( ) const

Return whether the video source was open correctly.

Definition at line 104 of file CFFMPEG_InputStream.cpp.

References MY_FFMPEG_STATE.

Referenced by close(), getVideoFPS(), and retrieveFrame().

Here is the caller graph for this function:

◆ openURL()

bool CFFMPEG_InputStream::openURL ( const std::string url,
bool  grab_as_grayscale = false,
bool  verbose = false 
)

Open a video file or a video stream (rtsp://) This can be used to open local video files (eg.

"myVideo.avi", "c:\a.mpeg") and also IP cameras (e. "rtsp://a.b.c.d/live.sdp"). However, note that there is currently no support for user/password in IP access. If verbose is set to true, more information about the video will be dumped to cout.

See also
close, retrieveFrame
Returns
false on any error (and error info dumped to cerr), true on success.

Definition at line 117 of file CFFMPEG_InputStream.cpp.

References close(), m_grab_as_grayscale, m_url, and MY_FFMPEG_STATE.

Referenced by mrpt::hwdrivers::CRovio::thread_video().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ retrieveFrame()

bool CFFMPEG_InputStream::retrieveFrame ( mrpt::utils::CImage out_img)

Get the next frame from the video stream.

Note that for remote streams (IP cameras) this method may block until enough information is read to generate a new frame. Images are returned as 8-bit depth grayscale if "grab_as_grayscale" is true.

Returns
false on any error, true on success.
See also
openURL, close, isOpen

Definition at line 341 of file CFFMPEG_InputStream.cpp.

References isOpen(), mrpt::utils::CImage::loadFromMemoryBuffer(), m_grab_as_grayscale, MY_FFMPEG_STATE, and THROW_EXCEPTION.

Referenced by mrpt::hwdrivers::CRovio::thread_video().

Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ m_grab_as_grayscale

bool mrpt::hwdrivers::CFFMPEG_InputStream::m_grab_as_grayscale
private

Definition at line 50 of file CFFMPEG_InputStream.h.

Referenced by openURL(), and retrieveFrame().

◆ m_state

mrpt::utils::void_ptr_noncopy mrpt::hwdrivers::CFFMPEG_InputStream::m_state
private

The internal ffmpeg state.

Definition at line 47 of file CFFMPEG_InputStream.h.

Referenced by CFFMPEG_InputStream(), and ~CFFMPEG_InputStream().

◆ m_url

std::string mrpt::hwdrivers::CFFMPEG_InputStream::m_url
private

The open URL.

Definition at line 49 of file CFFMPEG_InputStream.h.

Referenced by openURL().




Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: ae4571287 Thu Nov 23 00:06:53 2017 +0100 at dom oct 27 23:51:55 CET 2019