Main MRPT website > C++ reference
MRPT logo

CFFMPEG_InputStream.h

Go to the documentation of this file.
00001 /* +---------------------------------------------------------------------------+
00002    |          The Mobile Robot Programming Toolkit (MRPT) C++ library          |
00003    |                                                                           |
00004    |                   http://mrpt.sourceforge.net/                            |
00005    |                                                                           |
00006    |   Copyright (C) 2005-2011  University of Malaga                           |
00007    |                                                                           |
00008    |    This software was written by the Machine Perception and Intelligent    |
00009    |      Robotics Lab, University of Malaga (Spain).                          |
00010    |    Contact: Jose-Luis Blanco  <jlblanco@ctima.uma.es>                     |
00011    |                                                                           |
00012    |  This file is part of the MRPT project.                                   |
00013    |                                                                           |
00014    |     MRPT is free software: you can redistribute it and/or modify          |
00015    |     it under the terms of the GNU General Public License as published by  |
00016    |     the Free Software Foundation, either version 3 of the License, or     |
00017    |     (at your option) any later version.                                   |
00018    |                                                                           |
00019    |   MRPT is distributed in the hope that it will be useful,                 |
00020    |     but WITHOUT ANY WARRANTY; without even the implied warranty of        |
00021    |     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         |
00022    |     GNU General Public License for more details.                          |
00023    |                                                                           |
00024    |     You should have received a copy of the GNU General Public License     |
00025    |     along with MRPT.  If not, see <http://www.gnu.org/licenses/>.         |
00026    |                                                                           |
00027    +---------------------------------------------------------------------------+ */
00028 
00029 #ifndef  CFFMPEG_InputStream_H
00030 #define  CFFMPEG_InputStream_H
00031 
00032 #include <mrpt/utils/utils_defs.h>
00033 #include <mrpt/utils/CImage.h>
00034 #include <mrpt/utils/safe_pointers.h>
00035 
00036 #include <mrpt/hwdrivers/link_pragmas.h>
00037 
00038 
00039 /*---------------------------------------------------------------
00040         Class
00041   ---------------------------------------------------------------*/
00042 namespace mrpt
00043 {
00044         namespace hwdrivers
00045         {
00046                 /** 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.
00047                   *  Video sources can be open with "openURL", which can manage both video files and "rtsp://" sources (IP cameras).
00048                   *
00049                   *  Frames are retrieved by calling CFFMPEG_InputStream::retrieveFrame
00050                   *
00051                   *   For an example of usage, see the file "samples/grab_camera_ffmpeg"
00052                   *
00053                   * \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 <a href="http://www.mrpt.org/Building_and_Installing_Instructions" > MRPT's wiki</a>. In Win32, a precompiled version for Visual Studio must be also downloaded as explained in <a href="http://www.mrpt.org/Building_and_Installing_Instructions" >the wiki</a>.
00054                   */
00055                 class HWDRIVERS_IMPEXP CFFMPEG_InputStream
00056                 {
00057                 private:
00058                         mrpt::utils::void_ptr_noncopy   m_state;        //!< The internal ffmpeg state
00059                         std::string  m_url;     //!< The open URL
00060                         bool  m_grab_as_grayscale;
00061 
00062                 public:
00063                         CFFMPEG_InputStream();                          //!< Default constructor, does not open any video source at startup
00064                         virtual ~CFFMPEG_InputStream();         //!< Destructor
00065 
00066                         /** Open a video file or a video stream (rtsp://)
00067                           *  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").
00068                           *  However, note that there is currently no support for user/password in IP access.
00069                           *  If verbose is set to true, more information about the video will be dumped to cout.
00070                           *
00071                           * \sa close, retrieveFrame
00072                           * \return false on any error (and error info dumped to cerr), true on success.
00073                           */
00074                         bool openURL( const std::string &url, bool grab_as_grayscale = false, bool verbose = false );
00075 
00076                         bool isOpen() const;    //!< Return whether the video source was open correctly
00077 
00078                         /** Close the video stream (this is called automatically at destruction).
00079                           * \sa openURL
00080                           */
00081                         void close();
00082 
00083                         double getVideoFPS() const;     //!< Get the frame-per-second (FPS) of the video source, or "-1" if the video is not open.
00084 
00085                         /** Get the next frame from the video stream.
00086                           *  Note that for remote streams (IP cameras) this method may block until enough information is read to generate a new frame.
00087                           *  Images are returned as 8-bit depth grayscale if "grab_as_grayscale" is true.
00088                           *  \return false on any error, true on success.
00089                           *  \sa openURL, close, isOpen
00090                           */
00091                         bool retrieveFrame( mrpt::utils::CImage &out_img );
00092 
00093 
00094                 };
00095 
00096         }
00097 }
00098 
00099 
00100 #endif



Page generated by Doxygen 1.7.3 for MRPT 0.9.4 SVN: at Sat Mar 26 06:16:28 UTC 2011