48 #include <visp/vpDebug.h>
49 #include <visp/vpVideoReader.h>
60 #ifdef VISP_HAVE_FFMPEG
68 firstFrameIndexIsSet =
false;
69 lastFrameIndexIsSet =
false;
78 if (imSequence != NULL)
82 #ifdef VISP_HAVE_FFMPEG
102 if (filename ==
'\0')
108 strcpy(this->fileName,filename);
110 formatType = getFormat(fileName);
144 if (formatType == FORMAT_PGM ||
145 formatType == FORMAT_PPM ||
146 formatType == FORMAT_JPEG ||
147 formatType == FORMAT_PNG ||
148 formatType == FORMAT_TIFF ||
149 formatType == FORMAT_BMP ||
150 formatType == FORMAT_DIB ||
151 formatType == FORMAT_PBM ||
152 formatType == FORMAT_RASTER ||
153 formatType == FORMAT_JPEG2000)
157 if (firstFrameIndexIsSet)
160 #ifdef VISP_HAVE_FFMPEG
161 else if (formatType == FORMAT_AVI ||
162 formatType == FORMAT_MPEG ||
163 formatType == FORMAT_MOV ||
164 formatType == FORMAT_OGV)
173 else if (formatType == FORMAT_AVI ||
174 formatType == FORMAT_MPEG ||
175 formatType == FORMAT_MOV ||
176 formatType == FORMAT_OGV)
178 vpERROR_TRACE(
"To read video files the FFmpeg library has to be installed");
182 else if (formatType == FORMAT_UNKNOWN)
184 vpERROR_TRACE(
"The format of the file does not correpsond to a readable format.");
188 findFirstFrameIndex();
189 frameCount = firstFrame;
200 findLastFrameIndex();
219 if (formatType == FORMAT_PGM ||
220 formatType == FORMAT_PPM ||
221 formatType == FORMAT_JPEG ||
222 formatType == FORMAT_PNG ||
223 formatType == FORMAT_TIFF ||
224 formatType == FORMAT_BMP ||
225 formatType == FORMAT_DIB ||
226 formatType == FORMAT_PBM ||
227 formatType == FORMAT_RASTER ||
228 formatType == FORMAT_JPEG2000)
232 if (firstFrameIndexIsSet)
235 #ifdef VISP_HAVE_FFMPEG
236 else if (formatType == FORMAT_AVI ||
237 formatType == FORMAT_MPEG ||
238 formatType == FORMAT_MOV ||
239 formatType == FORMAT_OGV)
247 else if (formatType == FORMAT_AVI ||
248 formatType == FORMAT_MPEG ||
249 formatType == FORMAT_MOV ||
250 formatType == FORMAT_OGV)
252 vpERROR_TRACE(
"To read video files the FFmpeg library has to be installed");
256 else if (formatType == FORMAT_UNKNOWN)
258 vpERROR_TRACE(
"The format of the file does not correpsond to a readable format.");
262 findFirstFrameIndex();
263 frameCount = firstFrame;
274 findLastFrameIndex();
294 if (imSequence != NULL)
296 #ifdef VISP_HAVE_FFMPEG
297 else if (ffmpeg !=NULL)
318 if (imSequence != NULL)
320 #ifdef VISP_HAVE_FFMPEG
321 else if (ffmpeg != NULL)
343 if (imSequence != NULL)
355 #ifdef VISP_HAVE_FFMPEG
359 if(!ffmpeg->
getFrame(I, (
unsigned int)frame))
384 if (imSequence != NULL)
396 #ifdef VISP_HAVE_FFMPEG
399 if(!ffmpeg->
getFrame(I, (
unsigned int)frame))
415 vpVideoReader::vpVideoFormatType
416 vpVideoReader::getFormat(
const char *filename)
418 std::string sfilename(filename);
420 std::string ext = vpVideoReader::getExtension(sfilename);
422 if (ext.compare(
".PGM") == 0)
424 else if (ext.compare(
".pgm") == 0)
426 else if (ext.compare(
".PPM") == 0)
428 else if (ext.compare(
".ppm") == 0)
430 else if (ext.compare(
".JPG") == 0)
432 else if (ext.compare(
".jpg") == 0)
434 else if (ext.compare(
".JPEG") == 0)
436 else if (ext.compare(
".jpeg") == 0)
438 else if (ext.compare(
".PNG") == 0)
440 else if (ext.compare(
".png") == 0)
442 else if (ext.compare(
".AVI") == 0)
444 else if (ext.compare(
".avi") == 0)
446 else if (ext.compare(
".MPEG") == 0)
448 else if (ext.compare(
".mpeg") == 0)
450 else if (ext.compare(
".MPG") == 0)
452 else if (ext.compare(
".mpg") == 0)
454 else if (ext.compare(
".MOV") == 0)
456 else if (ext.compare(
".mov") == 0)
458 else if (ext.compare(
".OGV") == 0)
460 else if (ext.compare(
".ogv") == 0)
463 return FORMAT_UNKNOWN;
467 std::string vpVideoReader::getExtension(
const std::string &filename)
470 size_t dot = filename.find_last_of(
".");
471 std::string ext = filename.substr(dot, filename.size()-1);
480 vpVideoReader::findLastFrameIndex()
488 if (imSequence != NULL)
490 char name[FILENAME_MAX];
491 int image_number = firstFrame;
496 sprintf(name,fileName,image_number) ;
497 file.open(name, std::fstream::in);
498 failed = file.fail();
499 if (!failed) file.close();
503 lastFrame = image_number - 2;
506 #ifdef VISP_HAVE_FFMPEG
507 else if (ffmpeg != NULL)
515 vpVideoReader::findFirstFrameIndex()
517 if (imSequence != NULL)
519 if (! firstFrameIndexIsSet) {
520 char name[FILENAME_MAX];
521 int image_number = 0;
525 sprintf(name, fileName, image_number) ;
526 file.open(name, std::fstream::in);
527 failed = file.fail();
528 if (!failed) file.close();
532 firstFrame = image_number - 1;
537 #ifdef VISP_HAVE_FFMPEG
538 else if (ffmpeg != NULL) {
539 if (! firstFrameIndexIsSet) {
540 firstFrame = (long)(0);
553 double framerate = -1.;
555 #ifdef VISP_HAVE_FFMPEG
double getFramerate() const
unsigned int getWidth() const
bool getFrame(vpImage< vpRGBa > &I, unsigned int frameNumber)
error that can be emited by ViSP classes.
Error that can be emited by the vpImage class and its derivates.
unsigned long getFrameNumber() const
void open(vpImage< vpRGBa > &I)
bool getFrame(vpImage< vpRGBa > &I, long frame)
unsigned int height
Number of rows in the image.
bool openStream(const char *filename, vpFFMPEGColorType color_type)
void acquire(vpImage< vpRGBa > &I)
This class interfaces the FFmpeg library to enable video stream reading or writing.
void setImageNumber(long number)
void setFileName(const char *filename)
Class to grab (ie. read) images from the disk.
bool acquire(vpImage< vpRGBa > &I)
unsigned int getHeight() const
double getFramerate() const
void acquire(vpImage< unsigned char > &I)
unsigned int width
Number of columns in the image.
void setGenericName(const char *genericName)