Main MRPT website > C++ reference
MRPT logo
CFFMPEG_InputStream.h
Go to the documentation of this file.
1 /* +---------------------------------------------------------------------------+
2  | The Mobile Robot Programming Toolkit (MRPT) C++ library |
3  | |
4  | http://www.mrpt.org/ |
5  | |
6  | Copyright (C) 2005-2012 University of Malaga |
7  | |
8  | This software was written by the Machine Perception and Intelligent |
9  | Robotics Lab, University of Malaga (Spain). |
10  | Contact: Jose-Luis Blanco <jlblanco@ctima.uma.es> |
11  | |
12  | This file is part of the MRPT project. |
13  | |
14  | MRPT is free software: you can redistribute it and/or modify |
15  | it under the terms of the GNU General Public License as published by |
16  | the Free Software Foundation, either version 3 of the License, or |
17  | (at your option) any later version. |
18  | |
19  | MRPT is distributed in the hope that it will be useful, |
20  | but WITHOUT ANY WARRANTY; without even the implied warranty of |
21  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
22  | GNU General Public License for more details. |
23  | |
24  | You should have received a copy of the GNU General Public License |
25  | along with MRPT. If not, see <http://www.gnu.org/licenses/>. |
26  | |
27  +---------------------------------------------------------------------------+ */
28 
29 #ifndef CFFMPEG_InputStream_H
30 #define CFFMPEG_InputStream_H
31 
32 #include <mrpt/utils/utils_defs.h>
33 #include <mrpt/utils/CImage.h>
35 
37 
38 
39 /*---------------------------------------------------------------
40  Class
41  ---------------------------------------------------------------*/
42 namespace mrpt
43 {
44  namespace hwdrivers
45  {
46  /** 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.
47  * Video sources can be open with "openURL", which can manage both video files and "rtsp://" sources (IP cameras).
48  *
49  * Frames are retrieved by calling CFFMPEG_InputStream::retrieveFrame
50  *
51  * For an example of usage, see the file "samples/grab_camera_ffmpeg"
52  *
53  * \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>.
54  * \ingroup mrpt_hwdrivers_grp
55  */
57  {
58  private:
59  mrpt::utils::void_ptr_noncopy m_state; //!< The internal ffmpeg state
60  std::string m_url; //!< The open URL
62 
63  public:
64  CFFMPEG_InputStream(); //!< Default constructor, does not open any video source at startup
65  virtual ~CFFMPEG_InputStream(); //!< Destructor
66 
67  /** Open a video file or a video stream (rtsp://)
68  * 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").
69  * However, note that there is currently no support for user/password in IP access.
70  * If verbose is set to true, more information about the video will be dumped to cout.
71  *
72  * \sa close, retrieveFrame
73  * \return false on any error (and error info dumped to cerr), true on success.
74  */
75  bool openURL( const std::string &url, bool grab_as_grayscale = false, bool verbose = false );
76 
77  bool isOpen() const; //!< Return whether the video source was open correctly
78 
79  /** Close the video stream (this is called automatically at destruction).
80  * \sa openURL
81  */
82  void close();
83 
84  double getVideoFPS() const; //!< Get the frame-per-second (FPS) of the video source, or "-1" if the video is not open.
85 
86  /** Get the next frame from the video stream.
87  * Note that for remote streams (IP cameras) this method may block until enough information is read to generate a new frame.
88  * Images are returned as 8-bit depth grayscale if "grab_as_grayscale" is true.
89  * \return false on any error, true on success.
90  * \sa openURL, close, isOpen
91  */
92  bool retrieveFrame( mrpt::utils::CImage &out_img );
93 
94 
95  };
96 
97  }
98 }
99 
100 
101 #endif



Page generated by Doxygen 1.8.3 for MRPT 0.9.6 SVN: at Fri Feb 15 22:05:02 EST 2013