48 #include <visp/vpDebug.h>
49 #include <visp/vpVideoWriter.h>
56 #ifdef VISP_HAVE_FFMPEG
58 # if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(54,51,110)
59 codec(CODEC_ID_MPEG1VIDEO),
61 codec(AV_CODEC_ID_MPEG1VIDEO),
66 formatType(FORMAT_UNKNOWN), initFileName(false), isOpen(false), frameCount(0),
67 firstFrame(0), width(0), height(0)
74 #ifdef VISP_HAVE_FFMPEG
76 # if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(54,51,110) // libavcodec 54.51.100
77 codec = CODEC_ID_MPEG1VIDEO;
79 codec = AV_CODEC_ID_MPEG1VIDEO;
92 #ifdef VISP_HAVE_FFMPEG
108 if (filename ==
'\0')
114 if (strlen( filename ) >= FILENAME_MAX) {
116 "Not enough memory to intialize the file name"));
119 strcpy(this->fileName,filename);
121 formatType = getFormat(fileName);
151 if (formatType == FORMAT_PGM ||
152 formatType == FORMAT_PPM ||
153 formatType == FORMAT_JPEG ||
154 formatType == FORMAT_PNG)
159 #ifdef VISP_HAVE_FFMPEG
160 else if (formatType == FORMAT_AVI ||
161 formatType == FORMAT_MPEG ||
162 formatType == FORMAT_MOV)
172 else if (formatType == FORMAT_AVI ||
173 formatType == FORMAT_MPEG ||
174 formatType == FORMAT_MOV)
176 vpERROR_TRACE(
"To write video files the FFmpeg library has to be installed");
181 frameCount = firstFrame;
200 if (formatType == FORMAT_PGM ||
201 formatType == FORMAT_PPM ||
202 formatType == FORMAT_JPEG ||
203 formatType == FORMAT_PNG)
208 #ifdef VISP_HAVE_FFMPEG
209 else if (formatType == FORMAT_AVI ||
210 formatType == FORMAT_MPEG ||
211 formatType == FORMAT_MOV)
221 else if (formatType == FORMAT_AVI ||
222 formatType == FORMAT_MPEG ||
223 formatType == FORMAT_MOV)
225 vpERROR_TRACE(
"To write video files the FFmpeg library has to be installed");
230 frameCount = firstFrame;
247 vpERROR_TRACE(
"The video has to be open first with the open method");
252 if (formatType == FORMAT_PGM ||
253 formatType == FORMAT_PPM ||
254 formatType == FORMAT_JPEG ||
255 formatType == FORMAT_PNG)
257 char name[FILENAME_MAX];
259 sprintf(name,fileName,frameCount);
264 #ifdef VISP_HAVE_FFMPEG
286 vpERROR_TRACE(
"The video has to be open first with the open method");
290 if (formatType == FORMAT_PGM ||
291 formatType == FORMAT_PPM ||
292 formatType == FORMAT_JPEG ||
293 formatType == FORMAT_PNG)
295 char name[FILENAME_MAX];
297 sprintf(name,fileName,frameCount);
302 #ifdef VISP_HAVE_FFMPEG
320 vpERROR_TRACE(
"The video has to be open first with the open method");
323 #ifdef VISP_HAVE_FFMPEG
337 vpVideoWriter::vpVideoFormatType
338 vpVideoWriter::getFormat(
const char *filename)
340 std::string sfilename(filename);
342 std::string ext = vpVideoWriter::getExtension(sfilename);
344 if (ext.compare(
".PGM") == 0)
346 else if (ext.compare(
".pgm") == 0)
348 else if (ext.compare(
".PPM") == 0)
350 else if (ext.compare(
".ppm") == 0)
352 else if (ext.compare(
".JPG") == 0)
354 else if (ext.compare(
".jpg") == 0)
356 else if (ext.compare(
".JPEG") == 0)
358 else if (ext.compare(
".jpeg") == 0)
360 else if (ext.compare(
".PNG") == 0)
362 else if (ext.compare(
".png") == 0)
364 else if (ext.compare(
".AVI") == 0)
366 else if (ext.compare(
".avi") == 0)
368 else if (ext.compare(
".MPEG") == 0)
370 else if (ext.compare(
".mpeg") == 0)
372 else if (ext.compare(
".MPG") == 0)
374 else if (ext.compare(
".mpg") == 0)
376 else if (ext.compare(
".MOV") == 0)
378 else if (ext.compare(
".mov") == 0)
381 return FORMAT_UNKNOWN;
385 std::string vpVideoWriter::getExtension(
const std::string &filename)
388 size_t dot = filename.find_last_of(
".");
389 std::string ext = filename.substr(dot, filename.size()-1);
static void write(const vpImage< unsigned char > &I, const char *filename)
void setBitRate(const unsigned int rate)
unsigned int getWidth() const
bool saveFrame(vpImage< vpRGBa > &I)
error that can be emited by ViSP classes.
Error that can be emited by the vpImage class and its derivates.
This class interfaces the FFmpeg library to enable video stream reading or writing.
void saveFrame(vpImage< vpRGBa > &I)
void open(vpImage< vpRGBa > &I)
void setFileName(const char *filename)
unsigned int getHeight() const
bool openEncoder(const char *filename, unsigned int width, unsigned int height, AVCodecID codec=AV_CODEC_ID_MPEG1VIDEO)
void setFramerate(const int framerate)