48 #include <visp/vpDebug.h>
49 #include <visp/vpVideoWriter.h>
60 #ifdef VISP_HAVE_FFMPEG
62 #if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(54,51,110) // libavcodec 54.51.100
63 codec = CODEC_ID_MPEG1VIDEO;
65 codec = AV_CODEC_ID_MPEG1VIDEO;
78 #ifdef VISP_HAVE_FFMPEG
100 strcpy(this->fileName,filename);
102 formatType = getFormat(fileName);
132 if (formatType == FORMAT_PGM ||
133 formatType == FORMAT_PPM ||
134 formatType == FORMAT_JPEG ||
135 formatType == FORMAT_PNG)
140 #ifdef VISP_HAVE_FFMPEG
141 else if (formatType == FORMAT_AVI ||
142 formatType == FORMAT_MPEG ||
143 formatType == FORMAT_MOV)
153 else if (formatType == FORMAT_AVI ||
154 formatType == FORMAT_MPEG ||
155 formatType == FORMAT_MOV)
157 vpERROR_TRACE(
"To write video files the FFmpeg library has to be installed");
162 frameCount = firstFrame;
181 if (formatType == FORMAT_PGM ||
182 formatType == FORMAT_PPM ||
183 formatType == FORMAT_JPEG ||
184 formatType == FORMAT_PNG)
189 #ifdef VISP_HAVE_FFMPEG
190 else if (formatType == FORMAT_AVI ||
191 formatType == FORMAT_MPEG ||
192 formatType == FORMAT_MOV)
202 else if (formatType == FORMAT_AVI ||
203 formatType == FORMAT_MPEG ||
204 formatType == FORMAT_MOV)
206 vpERROR_TRACE(
"To write video files the FFmpeg library has to be installed");
211 frameCount = firstFrame;
228 vpERROR_TRACE(
"The video has to be open first with the open method");
233 if (formatType == FORMAT_PGM ||
234 formatType == FORMAT_PPM ||
235 formatType == FORMAT_JPEG ||
236 formatType == FORMAT_PNG)
238 char name[FILENAME_MAX];
240 sprintf(name,fileName,frameCount);
245 #ifdef VISP_HAVE_FFMPEG
267 vpERROR_TRACE(
"The video has to be open first with the open method");
271 if (formatType == FORMAT_PGM ||
272 formatType == FORMAT_PPM ||
273 formatType == FORMAT_JPEG ||
274 formatType == FORMAT_PNG)
276 char name[FILENAME_MAX];
278 sprintf(name,fileName,frameCount);
283 #ifdef VISP_HAVE_FFMPEG
301 vpERROR_TRACE(
"The video has to be open first with the open method");
304 #ifdef VISP_HAVE_FFMPEG
318 vpVideoWriter::vpVideoFormatType
319 vpVideoWriter::getFormat(
const char *filename)
321 std::string sfilename(filename);
323 std::string ext = vpVideoWriter::getExtension(sfilename);
325 if (ext.compare(
".PGM") == 0)
327 else if (ext.compare(
".pgm") == 0)
329 else if (ext.compare(
".PPM") == 0)
331 else if (ext.compare(
".ppm") == 0)
333 else if (ext.compare(
".JPG") == 0)
335 else if (ext.compare(
".jpg") == 0)
337 else if (ext.compare(
".JPEG") == 0)
339 else if (ext.compare(
".jpeg") == 0)
341 else if (ext.compare(
".PNG") == 0)
343 else if (ext.compare(
".png") == 0)
345 else if (ext.compare(
".AVI") == 0)
347 else if (ext.compare(
".avi") == 0)
349 else if (ext.compare(
".MPEG") == 0)
351 else if (ext.compare(
".mpeg") == 0)
353 else if (ext.compare(
".MPG") == 0)
355 else if (ext.compare(
".mpg") == 0)
357 else if (ext.compare(
".MOV") == 0)
359 else if (ext.compare(
".mov") == 0)
362 return FORMAT_UNKNOWN;
366 std::string vpVideoWriter::getExtension(
const std::string &filename)
369 size_t dot = filename.find_last_of(
".");
370 std::string ext = filename.substr(dot, filename.size()-1);
static void write(const vpImage< unsigned char > &I, const char *filename)
unsigned int getWidth() const
void setBitRate(const unsigned int bit_rate)
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)