00001 /* 00002 * Copyright (C) Massimo Cora' 2006 <maxcvs@email.it> 00003 * 00004 * This program is free software; you can redistribute it and/or modify 00005 * it under the terms of the GNU General Public License as published by 00006 * the Free Software Foundation; either version 2 of the License, or 00007 * (at your option) any later version. 00008 * 00009 * This program is distributed in the hope that it will be useful, 00010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 * GNU Library General Public License for more details. 00013 * 00014 * You should have received a copy of the GNU General Public License 00015 * along with this program; if not, write to the Free Software 00016 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 00017 */ 00018 00019 #ifndef _OSTREAMVIDEOENCODER_H_ 00020 #define _OSTREAMVIDEOENCODER_H_ 00021 00022 #include <cv.h> 00023 #include <highgui.h> 00024 #include <ffmpeg/avcodec.h> 00025 #include <ffmpeg/avformat.h> 00026 00027 #include "OStreamConfig.hh" 00028 00034 class OStreamVideoEncoder 00035 { 00036 public: 00037 00055 OStreamVideoEncoder( unsigned int io_buf_size, ostream_encoding_type encoding_type, 00056 int video_width, int video_height, 00057 int fps = 25, 00058 PixelFormat opencv_pix_fmt = PIX_FMT_BGR24 ); 00059 virtual ~OStreamVideoEncoder(); 00060 00070 const unsigned char* encode_video_frame( IplImage *image, int *out_size ); 00071 00072 private: // functions 00073 00078 bool encoder_initialize (); 00079 00087 AVFrame* create_avframe( int pixel_format ); 00088 00095 AVStream* create_video_stream( AVFormatContext *io_fmt_context, int codec_id ); 00096 00098 bool open_codec( AVStream *stream ); 00099 00100 private: // data 00102 bool _initialized; 00103 00105 AVFrame *_ready_to_encode_frame, *_opencv_frame; 00106 00108 AVOutputFormat *_out_fmt; 00109 00111 AVFormatContext *_out_fmt_context; 00112 00114 AVStream *_video_stream; 00115 00117 PixelFormat _opencv_pix_fmt; 00118 00120 unsigned char* _internal_buffer; 00121 int _internal_buffer_size; 00122 00124 int _encoding_type; 00125 00126 int _video_height; 00127 int _video_width; 00128 int _fps; 00129 00130 }; 00131 00132 00133 #endif //_OSTREAMVIDEOENCODER_H_ 00134