TuttleOFX
1
|
00001 #ifndef _TUTTLE_PLUGIN_LIBAV_LIBAVVIDEOWRITER_HPP_ 00002 #define _TUTTLE_PLUGIN_LIBAV_LIBAVVIDEOWRITER_HPP_ 00003 00004 #include "LibAV.hpp" 00005 #include "LibAVVideoReader.hpp" 00006 00007 #include <tuttle/plugin/global.hpp> 00008 00009 #include <boost/cstdint.hpp> 00010 00011 #include <iostream> 00012 #include <string> 00013 #include <vector> 00014 00015 namespace tuttle { 00016 namespace plugin { 00017 namespace av { 00018 00019 class LibAVVideoWriter : public LibAV 00020 { 00021 private: 00022 enum EWriterStatus 00023 { 00024 eWriterStatusSuccess = 0, 00025 eWriterStatusIgnoreFinish, 00026 eWriterStatusCleanup 00027 }; 00028 00029 public: 00030 explicit LibAVVideoWriter(); 00031 00032 bool movie() const 00033 { 00034 return true; 00035 } 00036 00037 int start( ); 00038 bool finishInit(); 00039 int execute( boost::uint8_t* const in_buffer, const int in_width, const int height, const PixelFormat in_fmt = PIX_FMT_RGB24 ); 00040 void finish(); 00041 00042 private: 00043 void freeFormat(); 00044 std::string getErrorStr( const int errnum ) const; 00045 00046 public: 00047 void setFilename( const std::string& filename ) 00048 { 00049 _filename = filename; 00050 } 00051 00052 std::string getFilename() const 00053 { 00054 return _filename; 00055 } 00056 00057 void setWidth( const int width ) 00058 { 00059 _width = width; 00060 } 00061 00062 int getWidth() const 00063 { 00064 return _width; 00065 } 00066 00067 void setHeight( const int height ) 00068 { 00069 _height = height; 00070 } 00071 00072 int getHeight() const 00073 { 00074 return _height; 00075 } 00076 00077 void setAspectRatio( const double aspectRatio ) 00078 { 00079 _aspectRatio = aspectRatio; 00080 } 00081 00082 double getAspectRatio() const 00083 { 00084 return _aspectRatio; 00085 } 00086 00087 void setFps( const double fps ) 00088 { 00089 _fps = fps; 00090 } 00091 00092 double getFps() const 00093 { 00094 return _fps; 00095 } 00096 00097 void setPixelFormat( const PixelFormat pxlFmt ) 00098 { 00099 _out_pixelFormat = pxlFmt; 00100 } 00101 00102 PixelFormat getPixelFormat() const 00103 { 00104 return _out_pixelFormat; 00105 } 00106 00107 const std::string& getFormat() const 00108 { 00109 return _formatName; 00110 } 00111 00112 const std::vector<std::string>& getFormatsShort() const 00113 { 00114 return _formatsShortNames; 00115 } 00116 00117 const std::vector<std::string>& getFormatsLong() const 00118 { 00119 return _formatsLongNames; 00120 } 00121 00122 void setFormat( const unsigned int id ) 00123 { 00124 _formatName = _formatsShortNames[id]; 00125 } 00126 00127 void setFormat( const std::string& format ) 00128 { 00129 _formatName = format; 00130 } 00131 00132 const std::string& getVideoCodec() const 00133 { 00134 return _videoCodecName; 00135 } 00136 00137 const std::vector<std::string>& getVideoCodecsShort() const 00138 { 00139 return _videoCodecsShortNames; 00140 } 00141 00142 const std::vector<std::string>& getVideoCodecsLong() const 00143 { 00144 return _videoCodecsLongNames; 00145 } 00146 00147 const std::string& getAudioCodec() const 00148 { 00149 return _audioCodecName; 00150 } 00151 00152 const std::vector<std::string>& getAudioCodecsShort() const 00153 { 00154 return _audioCodecsShortNames; 00155 } 00156 00157 const std::vector<std::string>& getAudioCodecsLong() const 00158 { 00159 return _audioCodecsLongNames; 00160 } 00161 00162 const std::vector<AVPrivOption>& getFormatPrivOpts() const 00163 { 00164 return _formatPrivOpts; 00165 } 00166 00167 const std::vector<AVPrivOption>& getVideoCodecPrivOpts() const 00168 { 00169 return _videoCodecPrivOpts; 00170 } 00171 00172 const std::vector<AVPrivOption>& getAudioCodecPrivOpts() const 00173 { 00174 return _audioCodecPrivOpts; 00175 } 00176 00177 void setVideoCodec( const unsigned int id ) 00178 { 00179 _videoCodecName = _videoCodecsShortNames[id]; 00180 } 00181 00182 void setVideoCodec( const std::string& codec ) 00183 { 00184 _videoCodecName = codec; 00185 } 00186 00187 void setAudioCodec( const unsigned int id ) 00188 { 00189 _audioCodecName = _audioCodecsShortNames[id]; 00190 } 00191 00192 void setAudioCodec( const std::string& codec ) 00193 { 00194 _audioCodecName = codec; 00195 } 00196 00197 void configureFromRead( const LibAVVideoReader& reader ) 00198 { 00199 setWidth ( reader.width() ); 00200 setHeight ( reader.height() ); 00201 setAspectRatio ( reader.aspectRatio() ); 00202 setFps ( reader.fps() ); 00203 setFormat ( reader.formatName() ); 00204 setVideoCodec ( reader.codecName() ); 00205 //setAudioCodec ( reader.codecName() ); 00206 } 00207 00208 public: 00209 AVFormatContext* _avFormatOptions; 00210 AVStream* _stream; 00211 00212 private: 00213 00214 AVCodecContext* _avVideoOptions; 00215 AVCodecContext* _avAudioOptions; 00216 struct SwsContext* _sws_context; ///< swscale: transformation context 00217 00218 AVCodec* _videoCodec; 00219 AVCodec* _audioCodec; 00220 AVOutputFormat* _ofmt; 00221 00222 std::vector<AVPrivOption> _formatPrivOpts; 00223 std::vector<AVPrivOption> _videoCodecPrivOpts; 00224 std::vector<AVPrivOption> _audioCodecPrivOpts; 00225 00226 std::vector<std::string> _formatsLongNames; 00227 std::vector<std::string> _formatsShortNames; 00228 00229 std::vector<std::string> _videoCodecsLongNames; 00230 std::vector<std::string> _videoCodecsShortNames; 00231 00232 std::vector<std::string> _audioCodecsLongNames; 00233 std::vector<std::string> _audioCodecsShortNames; 00234 00235 EWriterStatus _statusCode; 00236 int _hasFrame; 00237 00238 std::string _filename; 00239 int _width; 00240 int _height; 00241 double _aspectRatio; 00242 PixelFormat _out_pixelFormat; 00243 00244 double _fps; 00245 std::string _formatName; 00246 std::string _videoCodecName; 00247 std::string _audioCodecName; 00248 }; 00249 00250 } 00251 } 00252 } 00253 00254 #endif 00255