48 #include <visp/vpDebug.h>
49 #include <visp/vpVideoReader.h>
59 #ifdef VISP_HAVE_FFMPEG
62 formatType(FORMAT_UNKNOWN), initFileName(false), isOpen(false), frameCount(0),
63 firstFrame(0), lastFrame(0), firstFrameIndexIsSet(false), lastFrameIndexIsSet(false)
72 if (imSequence != NULL)
76 #ifdef VISP_HAVE_FFMPEG
102 if (strlen( filename ) >= FILENAME_MAX) {
104 "Not enough memory to intialize the file name"));
107 strcpy(this->fileName,filename);
109 formatType = getFormat(fileName);
143 if (formatType == FORMAT_PGM ||
144 formatType == FORMAT_PPM ||
145 formatType == FORMAT_JPEG ||
146 formatType == FORMAT_PNG ||
147 formatType == FORMAT_TIFF ||
148 formatType == FORMAT_BMP ||
149 formatType == FORMAT_DIB ||
150 formatType == FORMAT_PBM ||
151 formatType == FORMAT_RASTER ||
152 formatType == FORMAT_JPEG2000)
156 if (firstFrameIndexIsSet)
159 #ifdef VISP_HAVE_FFMPEG
160 else if (formatType == FORMAT_AVI ||
161 formatType == FORMAT_MPEG ||
162 formatType == FORMAT_MOV ||
163 formatType == FORMAT_OGV)
172 else if (formatType == FORMAT_AVI ||
173 formatType == FORMAT_MPEG ||
174 formatType == FORMAT_MOV ||
175 formatType == FORMAT_OGV)
177 vpERROR_TRACE(
"To read video files the FFmpeg library has to be installed");
181 else if (formatType == FORMAT_UNKNOWN)
183 vpERROR_TRACE(
"The format of the file does not correpsond to a readable format.");
187 findFirstFrameIndex();
188 frameCount = firstFrame;
199 findLastFrameIndex();
218 if (formatType == FORMAT_PGM ||
219 formatType == FORMAT_PPM ||
220 formatType == FORMAT_JPEG ||
221 formatType == FORMAT_PNG ||
222 formatType == FORMAT_TIFF ||
223 formatType == FORMAT_BMP ||
224 formatType == FORMAT_DIB ||
225 formatType == FORMAT_PBM ||
226 formatType == FORMAT_RASTER ||
227 formatType == FORMAT_JPEG2000)
231 if (firstFrameIndexIsSet)
234 #ifdef VISP_HAVE_FFMPEG
235 else if (formatType == FORMAT_AVI ||
236 formatType == FORMAT_MPEG ||
237 formatType == FORMAT_MOV ||
238 formatType == FORMAT_OGV)
246 else if (formatType == FORMAT_AVI ||
247 formatType == FORMAT_MPEG ||
248 formatType == FORMAT_MOV ||
249 formatType == FORMAT_OGV)
251 vpERROR_TRACE(
"To read video files the FFmpeg library has to be installed");
255 else if (formatType == FORMAT_UNKNOWN)
257 vpERROR_TRACE(
"The format of the file does not correpsond to a readable format.");
261 findFirstFrameIndex();
262 frameCount = firstFrame;
273 findLastFrameIndex();
293 if (imSequence != NULL)
295 #ifdef VISP_HAVE_FFMPEG
296 else if (ffmpeg !=NULL)
317 if (imSequence != NULL)
319 #ifdef VISP_HAVE_FFMPEG
320 else if (ffmpeg != NULL)
342 if (imSequence != NULL)
354 #ifdef VISP_HAVE_FFMPEG
358 if(!ffmpeg->
getFrame(I, (
unsigned int)frame))
383 if (imSequence != NULL)
395 #ifdef VISP_HAVE_FFMPEG
398 if(!ffmpeg->
getFrame(I, (
unsigned int)frame))
414 vpVideoReader::vpVideoFormatType
415 vpVideoReader::getFormat(
const char *filename)
417 std::string sfilename(filename);
419 std::string ext = vpVideoReader::getExtension(sfilename);
421 if (ext.compare(
".PGM") == 0)
423 else if (ext.compare(
".pgm") == 0)
425 else if (ext.compare(
".PPM") == 0)
427 else if (ext.compare(
".ppm") == 0)
429 else if (ext.compare(
".JPG") == 0)
431 else if (ext.compare(
".jpg") == 0)
433 else if (ext.compare(
".JPEG") == 0)
435 else if (ext.compare(
".jpeg") == 0)
437 else if (ext.compare(
".PNG") == 0)
439 else if (ext.compare(
".png") == 0)
441 else if (ext.compare(
".AVI") == 0)
443 else if (ext.compare(
".avi") == 0)
445 else if (ext.compare(
".MPEG") == 0)
447 else if (ext.compare(
".mpeg") == 0)
449 else if (ext.compare(
".MPG") == 0)
451 else if (ext.compare(
".mpg") == 0)
453 else if (ext.compare(
".MOV") == 0)
455 else if (ext.compare(
".mov") == 0)
457 else if (ext.compare(
".OGV") == 0)
459 else if (ext.compare(
".ogv") == 0)
462 return FORMAT_UNKNOWN;
466 std::string vpVideoReader::getExtension(
const std::string &filename)
469 size_t dot = filename.find_last_of(
".");
470 std::string ext = filename.substr(dot, filename.size()-1);
479 vpVideoReader::findLastFrameIndex()
487 if (imSequence != NULL)
489 if (! lastFrameIndexIsSet) {
490 char name[FILENAME_MAX];
491 int image_number = firstFrame;
496 sprintf(name,fileName,image_number) ;
497 file.open(name, std::ios::in);
498 failed = file.fail();
499 if (!failed) file.close();
503 lastFrame = image_number - 2;
507 #ifdef VISP_HAVE_FFMPEG
508 else if (ffmpeg != NULL) {
509 if (! lastFrameIndexIsSet) {
519 vpVideoReader::findFirstFrameIndex()
521 if (imSequence != NULL)
523 if (! firstFrameIndexIsSet) {
524 char name[FILENAME_MAX];
525 int image_number = 0;
529 sprintf(name, fileName, image_number) ;
530 file.open(name, std::ios::in);
531 failed = file.fail();
532 if (!failed) file.close();
536 firstFrame = image_number - 1;
541 #ifdef VISP_HAVE_FFMPEG
542 else if (ffmpeg != NULL) {
543 if (! firstFrameIndexIsSet) {
544 firstFrame = (long)(0);
557 double framerate = -1.;
559 #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)