00001
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #define ORIGINAL_VER
00023
00024 #include "ccvt/conv.h"
00025 #include "MPEGSource.h"
00026
00027
00028
00029
00030 MPEGSource::MPEGSource(char* path)
00036 {
00037
00038 if (!mpeg3_check_sig(path))
00039 throw "incompatible mpeg file";
00040
00041
00042 file = mpeg3_open(path);
00043 if (file == NULL)
00044 throw "error opening mpeg file";
00045
00046
00047 if (!mpeg3_has_video(file))
00048 throw "non-video MPEG file";
00049
00050
00051 width = mpeg3_video_width(file, 0);
00052 height = mpeg3_video_height(file, 0);
00053 frames = mpeg3_video_frames(file, 0);
00054 framerate = mpeg3_frame_rate(file, 0);
00055
00056
00057 buff = new (unsigned char*)[height];
00058 for (unsigned int i = 0; i < height - 1; i++)
00059 buff[i] = new (unsigned char)[width*3];
00060
00061
00062 buff[height - 1] = new (unsigned char)[width*3 + 4];
00063
00064
00065 Y = new char[width*height] ;
00066 U = new char[width*height/4] ;
00067 V = new char[width*height/4] ;
00068
00069
00070 type = Image::COLOUR;
00071 }
00072
00073
00074 MPEGSource::~MPEGSource()
00078 {
00079 mpeg3_close(file);
00080
00081
00082 for (unsigned int i = 0; i < height; i++)
00083 delete [] buff[i];
00084
00085
00086 delete [] buff;
00087 }
00088
00089
00090 ImageSource& MPEGSource::operator >> (ImageRGB& img)
00096 {
00097
00098 mpeg3_read_frame(file, buff,
00099 0, 0,
00100 width, height,
00101 width, height,
00102 MPEG3_RGB888, 0);
00103
00104
00105 conv_rgb24_rgb96(width, height, buff, img.data[0]);
00106
00107 return *this;
00108 }
00109
00110
00111 ImageSource& MPEGSource::operator >> (ImageGrey& img)
00118 {
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128 mpeg3_read_yuvframe(file,
00129 Y,U,V,
00130 0, 0,
00131 width, height,
00132 0);
00133
00134
00135
00136 conv_420p_grey(width, height, Y, img.brightness);
00137
00138
00139 return *this;
00140 }
00141
00142
00143 ImageSource& MPEGSource::operator >> (Image& img)
00152 {
00153 (type == Image::COLOUR) ? *this >> (ImageRGB&)img
00154 : *this >> (ImageGrey&)img;
00155
00156 return *this;
00157 }
00158
00159 int MPEGSource::get_no_frames()
00160 {
00161 return (int) frames;
00162 }
00163
00164 void MPEGSource::get_size(unsigned int& w, unsigned int& h)
00171 {
00172 w = width;
00173 h = height;
00174 }
00175
00176 int MPEGSource::set_frame(long frame_no)
00182 {
00183 return mpeg3_set_frame(file, frame_no, 0) ;
00184 }
00185
00186 void MPEGSource::get_framerate(float& fr_rate)
00192 {
00193 fr_rate = framerate;
00194 }
00195
00196 bool MPEGSource::eof() const
00201 {
00202 return (bool)(mpeg3_end_of_video(file, 0));
00203 }
00204