Basic Image AlgorithmS Library 2.8.0

VideoSink.hh

00001 /* 
00002 This file is part of the BIAS library (Basic ImageAlgorithmS).
00003 
00004 Copyright (C) 2003-2009    (see file CONTACT for details)
00005   Multimediale Systeme der Informationsverarbeitung
00006   Institut fuer Informatik
00007   Christian-Albrechts-Universitaet Kiel
00008 
00009 
00010 BIAS is free software; you can redistribute it and/or modify
00011 it under the terms of the GNU Lesser General Public License as published by
00012 the Free Software Foundation; either version 2.1 of the License, or
00013 (at your option) any later version.
00014 
00015 BIAS is distributed in the hope that it will be useful,
00016 but WITHOUT ANY WARRANTY; without even the implied warranty of
00017 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018 GNU Lesser General Public License for more details.
00019 
00020 You should have received a copy of the GNU Lesser General Public License
00021 along with BIAS; if not, write to the Free Software
00022 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00023 */
00024 
00025 
00026 #ifndef _VIDEOSINK_HH_
00027 #define _VIDEOSINK_HH_
00028 
00029 #include <bias_config.h>
00030 #include <Base/Debug/Debug.hh>
00031 #include <VideoSource/VideoSource_Disk.hh>
00032 #include <Base/Image/Image.hh>
00033 #include <Base/Image/ImageConvert.hh>
00034 #include <Base/Image/ImageIO.hh>
00035 
00036 extern "C"
00037 {
00038   #include <avcodec.h>
00039   #include <avformat.h>
00040   #include <avutil.h>
00041   #include <swscale.h>
00042 }
00043 
00044 #include <vector>
00045 #include <string>
00046 
00047 
00048 // FIXME
00049 void av_free_packet(AVPacket *pkt) 
00050 { 
00051   if (pkt)
00052   {
00053     if (pkt->destruct) pkt->destruct(pkt);
00054     pkt->data = NULL; pkt->size = 0;
00055   }
00056 }
00057 
00058 namespace BIAS
00059 {
00060 
00061 /**
00062   \class VideoSink
00063   \ingroup g_videosink
00064   \author Friso Evers
00065   \brief VideoSink for writing FFMPEG Videos from images 
00066   \deprecated Is replaced by VideoSink_FFmpeg
00067  */
00068 class BIASVideoSink_EXPORT VideoSink
00069 {
00070 public:
00071   VideoSink();
00072   VideoSink(std::string Video);
00073   VideoSink(std::vector<std::string> Images);
00074   VideoSink(std::vector<std::string> Images, std::string Video);
00075   ~VideoSink();
00076 
00077   /**
00078    * Append an image to the end of the list.
00079    */
00080   void AddImage(std::string Image);
00081   void AddImages(std::vector<std::string> Images);
00082 
00083   /**
00084    * Set the file where the video will be written to.
00085    * This or the according constructor must be called befor encoding.
00086    */
00087   void SetOutputVideo(std::string Video);
00088   /**
00089    * Set the framerate for the video.
00090    * Note that the encoder only works with some values (e.g. 25, 50).
00091    */
00092   void SetFPS(float FPS);
00093 
00094   /**
00095    * Set the bitrate of the output video.
00096    * This overrides a value set by SetBPP.
00097    */
00098   void SetBitrate(int Bitrate);
00099   /**
00100    * Set the bits per pixel of the output video. The initial value is 4.
00101    * This overrides a value set by SetBitrate.
00102    */
00103   void SetBPP(double BPP);
00104 
00105   /**
00106    * Encode the video.
00107    */
00108   bool Encode();
00109 
00110   /**
00111    * Return the last produced errormessage.
00112    * Use the return value of the methods to test for errors though since this
00113    * message is not reset on success.
00114    */
00115   std::string GetErrMsg();
00116 
00117 protected:
00118   bool _SetupVideoSource();
00119   //bool _SetupSwsContext(PixelFormat fromFmt, int width = 0, int height = 0);
00120 
00121   /**
00122    * Convert RGB888p data to Y'UV420p.
00123    *
00124    * \param rgb Pointer to RGB data.
00125    * \param yuv Pointer to YUV data, must point to an allocated memory with a
00126    *            minimum size of (width*height * 3) / 2.
00127    */
00128   static void _RGB888pToYUV420p(uint8_t *rgb, uint8_t *yuv,
00129                 int width, int height);
00130 
00131   std::vector<std::string> _ImgFiles;
00132   std::string _Video;
00133   float _FPS;
00134   int _Bitrate;
00135   int _BPP;
00136   VideoSource_Disk _VSD;
00137   bool _IsYUV;
00138 
00139   AVCodec *_Codec;
00140   AVCodecContext *_CodecCtx;
00141   //SwsContext *_SwsCtx;
00142 
00143   std::string _ErrMsg;
00144 };
00145 
00146 }
00147 
00148 #endif
 All Classes Functions Variables Typedefs Enumerations Enumerator Friends