Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
VideoSource_FFMPEGVideo.hh
1 /*
2 This file is part of the BIAS library (Basic ImageAlgorithmS).
3 
4 Copyright (C) 2003-2009 (see file CONTACT for details)
5  Multimediale Systeme der Informationsverarbeitung
6  Institut fuer Informatik
7  Christian-Albrechts-Universitaet Kiel
8 
9 
10 BIAS is free software; you can redistribute it and/or modify
11 it under the terms of the GNU Lesser General Public License as published by
12 the Free Software Foundation; either version 2.1 of the License, or
13 (at your option) any later version.
14 
15 BIAS is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU Lesser General Public License for more details.
19 
20 You should have received a copy of the GNU Lesser General Public License
21 along with BIAS; if not, write to the Free Software
22 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 */
24 
25 #ifndef _VideoSource_FFMPEGVideo_H_
26 #define _VideoSource_FFMPEGVideo_H_
27 
28 #include <string>
29 #include <vector>
30 extern "C"
31 {
32  #include <avcodec.h>
33  #include <avformat.h>
34  #include <avutil.h>
35  #include <swscale.h>
36 }
37 #include <Base/Image/ImageBase.hh>
38 
39 namespace BIAS
40 {
41  /** \class VideoSource_FFMPEGVideo, formerly FFMPEGVideo
42  * \test tested with TestVideoSource_FFMPEGVideo.cpp
43  * \ingroup g_videosource
44  * \author Max hollmann
45  * \brief Class for extracting frames from video files using FFMpeg, analog to class DShowVideo
46  * \deprecated replaced by VideoSource_FFmpeg, to be removed (ischiller)
47  */
49  {
50  public:
53 
54  /** Open file and retreive info. */
55  bool Open(const char *file);
56 
57  /** Select video stream, initialize stuff and set destination size
58  * and pixel format. Only call after successfully calling Open().
59  * If width and height both are zero, the video is not resized.
60  * If either is zero, the other is calculated to maintain the aspect ratio.
61  */
62  bool Init(int width = 0, int height = 0,
63  PixelFormat pixFmt = PIX_FMT_RGB24, unsigned int streamIndex = 0);
64 
65  /** Close file and free buffers. */
66  void Close();
67 
68 
69  /** Return number of video streams. */
70  unsigned int CountVideoStreams();
71 
72 
73  /** Return width of selected video stream. */
74  int Width();
75 
76  /** Return height of selected video stream. */
77  int Height();
78 
79 
80  /** Retreive the next frame from the video. */
81  bool GetFrame(BIAS::ImageBase &img);
82 
83  /** Seeks to \p time which is given in TimeBase units. */
84  void Seek(int64_t time);
85 
86  /** Returns the TimeBase of the video stream. */
87  AVRational TimeBase();
88 
89  /** Returns the current decoding timestamp. */
90  unsigned int GetCurrentDTS() const;
91 
92  /** Returns the length of the video in TimeBase units. */
93  unsigned int GetLength() const;
94 
95 
96  /** Returns last error message. */
97  std::string ErrMsg();
98 
99  /** Maps BIAS colormodels to ffmpeg pixelformats.
100  * Supported so far:
101  * - CM_RGB
102  * - CM_BGR
103  * - CM_GRAY
104  */
105  static PixelFormat Colormodel2PixFmt(ImageBase::EColorModel cm);
106 
107  protected:
108  std::string _errMsg;
109 
110  std::vector<int> _vidStreams;
111  unsigned int _streamIndex;
112  AVFormatContext *_fmtCtx;
113  AVCodecContext *_codecCtx;
114  SwsContext *_swsCtx;
115  AVCodec *_codec;
116  int _vidStr;
117  AVFrame *_frame;
118  AVFrame *_frameRGB;
119  uint8_t *_buffer;
120  };
121 }
122 
123 #endif
EColorModel
These are the most often used color models.
Definition: ImageBase.hh:127
bool Open(const char *file)
Open file and retreive info.
AVRational TimeBase()
Returns the TimeBase of the video stream.
unsigned int GetCurrentDTS() const
Returns the current decoding timestamp.
bool Init(int width=0, int height=0, PixelFormat pixFmt=PIX_FMT_RGB24, unsigned int streamIndex=0)
Select video stream, initialize stuff and set destination size and pixel format.
void Close()
Close file and free buffers.
void Seek(int64_t time)
Seeks to time which is given in TimeBase units.
unsigned int CountVideoStreams()
Return number of video streams.
Class for extracting frames from video files using FFMpeg, analog to class DShowVideo.
int Width()
Return width of selected video stream.
static PixelFormat Colormodel2PixFmt(ImageBase::EColorModel cm)
Maps BIAS colormodels to ffmpeg pixelformats.
std::string ErrMsg()
Returns last error message.
unsigned int GetLength() const
Returns the length of the video in TimeBase units.
int Height()
Return height of selected video stream.
This is the base class for images in BIAS.
Definition: ImageBase.hh:102
bool GetFrame(BIAS::ImageBase &img)
Retreive the next frame from the video.