Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
VideoSink.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 
26 #ifndef _VIDEOSINK_HH_
27 #define _VIDEOSINK_HH_
28 
29 #include <bias_config.h>
30 #include <Base/Debug/Debug.hh>
31 #include <VideoSource/VideoSource_Disk.hh>
32 #include <Base/Image/Image.hh>
33 #include <Base/Image/ImageConvert.hh>
34 #include <Base/Image/ImageIO.hh>
35 
36 extern "C"
37 {
38  #include <avcodec.h>
39  #include <avformat.h>
40  #include <avutil.h>
41  #include <swscale.h>
42 }
43 
44 #include <vector>
45 #include <string>
46 
47 
48 // FIXME
49 void av_free_packet(AVPacket *pkt)
50 {
51  if (pkt)
52  {
53  if (pkt->destruct) pkt->destruct(pkt);
54  pkt->data = NULL; pkt->size = 0;
55  }
56 }
57 
58 namespace BIAS
59 {
60 
61 /**
62  \class VideoSink
63  \ingroup g_videosink
64  \author Friso Evers
65  \brief VideoSink for writing FFMPEG Videos from images
66  \deprecated Is replaced by VideoSink_FFmpeg
67  */
68 class BIASVideoSink_EXPORT VideoSink
69 {
70 public:
71  VideoSink();
72  VideoSink(std::string Video);
73  VideoSink(std::vector<std::string> Images);
74  VideoSink(std::vector<std::string> Images, std::string Video);
75  ~VideoSink();
76 
77  /**
78  * Append an image to the end of the list.
79  */
80  void AddImage(std::string Image);
81  void AddImages(std::vector<std::string> Images);
82 
83  /**
84  * Set the file where the video will be written to.
85  * This or the according constructor must be called befor encoding.
86  */
87  void SetOutputVideo(std::string Video);
88  /**
89  * Set the framerate for the video.
90  * Note that the encoder only works with some values (e.g. 25, 50).
91  */
92  void SetFPS(float FPS);
93 
94  /**
95  * Set the bitrate of the output video.
96  * This overrides a value set by SetBPP.
97  */
98  void SetBitrate(int Bitrate);
99  /**
100  * Set the bits per pixel of the output video. The initial value is 4.
101  * This overrides a value set by SetBitrate.
102  */
103  void SetBPP(double BPP);
104 
105  /**
106  * Encode the video.
107  */
108  bool Encode();
109 
110  /**
111  * Return the last produced errormessage.
112  * Use the return value of the methods to test for errors though since this
113  * message is not reset on success.
114  */
115  std::string GetErrMsg();
116 
117 protected:
118  bool _SetupVideoSource();
119  //bool _SetupSwsContext(PixelFormat fromFmt, int width = 0, int height = 0);
120 
121  /**
122  * Convert RGB888p data to Y'UV420p.
123  *
124  * \param rgb Pointer to RGB data.
125  * \param yuv Pointer to YUV data, must point to an allocated memory with a
126  * minimum size of (width*height * 3) / 2.
127  */
128  static void _RGB888pToYUV420p(uint8_t *rgb, uint8_t *yuv,
129  int width, int height);
130 
131  std::vector<std::string> _ImgFiles;
132  std::string _Video;
133  float _FPS;
134  int _Bitrate;
135  int _BPP;
137  bool _IsYUV;
138 
139  AVCodec *_Codec;
140  AVCodecContext *_CodecCtx;
141  //SwsContext *_SwsCtx;
142 
143  std::string _ErrMsg;
144 };
145 
146 }
147 
148 #endif
std::vector< std::string > _ImgFiles
Definition: VideoSink.hh:131
AVCodec * _Codec
Definition: VideoSink.hh:139
VideoSink for writing FFMPEG Videos from images.
Definition: VideoSink.hh:68
std::string _Video
Definition: VideoSink.hh:132
std::string _ErrMsg
Definition: VideoSink.hh:143
AVCodecContext * _CodecCtx
Definition: VideoSink.hh:140
VideoSource_Disk _VSD
Definition: VideoSink.hh:136
The image template class for specific storage types.
Definition: Image.hh:78
This class simulates a video device by loading images from disk.