ViSP  2.7.0
vpFFMPEG.cpp
1 /****************************************************************************
2  *
3  * $Id: vpImagePoint.h 2359 2009-11-24 15:09:25Z nmelchio $
4  *
5  * This file is part of the ViSP software.
6  * Copyright (C) 2005 - 2013 by INRIA. All rights reserved.
7  *
8  * This software is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License
10  * ("GPL") version 2 as published by the Free Software Foundation.
11  * See the file LICENSE.txt at the root directory of this source
12  * distribution for additional information about the GNU GPL.
13  *
14  * For using ViSP with software that can not be combined with the GNU
15  * GPL, please contact INRIA about acquiring a ViSP Professional
16  * Edition License.
17  *
18  * See http://www.irisa.fr/lagadic/visp/visp.html for more information.
19  *
20  * This software was developed at:
21  * INRIA Rennes - Bretagne Atlantique
22  * Campus Universitaire de Beaulieu
23  * 35042 Rennes Cedex
24  * France
25  * http://www.irisa.fr/lagadic
26  *
27  * If you have questions regarding the use of this file, please contact
28  * INRIA at visp@inria.fr
29  *
30  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
31  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
32  *
33  *
34  * Description:
35  * Class that manages the FFMPEG library.
36  *
37  * Authors:
38  * Nicolas Melchior
39  * Fabien Spindler
40  *
41  *****************************************************************************/
42 
48 #include <stdio.h>
49 
50 #include <visp/vpConfig.h>
51 #include <visp/vpDebug.h>
52 #include <visp/vpFFMPEG.h>
53 #include <visp/vpImageConvert.h>
54 
55 #ifdef VISP_HAVE_FFMPEG
56 
57 extern "C"
58 {
59 //#include <avcodec.h>
60 #include <avformat.h>
61 #include <swscale.h>
62 }
63 
68 {
69  frameNumber = 0;
70  width = -1;
71  height = -1;
72  buffer = NULL;
73  streamWasOpen = false;
74  streamWasInitialized = false;
75  bit_rate = 500000;
76  outbuf = NULL;
77  picture_buf = NULL;
78  f = NULL;
79  encoderWasOpened = false;
80  packet = new AVPacket;
81 
82  pFormatCtx = NULL;
83 }
84 
89 {
90  closeStream();
91  delete packet;
92 }
93 
103 bool vpFFMPEG::openStream(const char *filename, vpFFMPEGColorType color_type)
104 {
105  this->color_type = color_type;
106 
107  av_register_all();
108 #if LIBAVFORMAT_VERSION_INT < AV_VERSION_INT(53,0,0) // libavformat 52.84.0
109  if (av_open_input_file (&pFormatCtx, filename, NULL, 0, NULL) != 0)
110 #else
111  if (avformat_open_input (&pFormatCtx, filename, NULL, NULL) != 0) // libavformat 53.4.0
112 #endif
113  {
114  vpTRACE("Couldn't open file ");
115  return false;
116  }
117 
118 #if LIBAVFORMAT_VERSION_INT < AV_VERSION_INT(53,21,0) // libavformat 53.21.0
119  if (av_find_stream_info (pFormatCtx) < 0)
120 #else
121  if (avformat_find_stream_info (pFormatCtx, NULL) < 0)
122 #endif
123  return false;
124 
125  videoStream = 0;
126  bool found_codec = false;
127 
128  /*
129  * Detect streams types
130  */
131  for (unsigned int i = 0; i < pFormatCtx->nb_streams; i++)
132  {
133 #if LIBAVUTIL_VERSION_INT < AV_VERSION_INT(51,0,0)
134  if(pFormatCtx->streams[i]->codec->codec_type==CODEC_TYPE_VIDEO) // avutil 50.33.0
135 #else
136  if(pFormatCtx->streams[i]->codec->codec_type==AVMEDIA_TYPE_VIDEO) // avutil 51.9.1
137 #endif
138  {
139  videoStream = i;
140  found_codec= true;
141  break;
142  }
143  }
144 
145  if (found_codec)
146  {
147  pCodecCtx = pFormatCtx->streams[videoStream]->codec;
148  pCodec = avcodec_find_decoder(pCodecCtx->codec_id);
149 
150  if (pCodec == NULL)
151  {
152  vpTRACE("unsuported codec");
153  return false; // Codec not found
154  }
155 
156 #if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(53,35,0) // libavcodec 53.35.0
157  if (avcodec_open (pCodecCtx, pCodec) < 0)
158 #else
159  if (avcodec_open2 (pCodecCtx, pCodec, NULL) < 0)
160 #endif
161  {
162  vpTRACE("Could not open codec");
163  return false; // Could not open codec
164  }
165 
166  pFrame = avcodec_alloc_frame();
167 
168  if (color_type == vpFFMPEG::COLORED)
169  {
170  pFrameRGB=avcodec_alloc_frame();
171 
172  if (pFrameRGB == NULL)
173  return false;
174 
175  numBytes = avpicture_get_size (PIX_FMT_RGB24,pCodecCtx->width,pCodecCtx->height);
176  }
177 
178  else if (color_type == vpFFMPEG::GRAY_SCALED)
179  {
180  pFrameGRAY=avcodec_alloc_frame();
181 
182  if (pFrameGRAY == NULL)
183  return false;
184 
185  numBytes = avpicture_get_size (PIX_FMT_GRAY8,pCodecCtx->width,pCodecCtx->height);
186  }
187 
188  /*
189  * Determine required buffer size and allocate buffer
190  */
191  width = pCodecCtx->width ;
192  height = pCodecCtx->height ;
193  buffer = (uint8_t *) malloc ((unsigned int)(sizeof (uint8_t)) * (unsigned int)numBytes);
194  }
195  else
196  {
197  vpTRACE("Didn't find a video stream");
198  return false;
199  }
200 
201  if (color_type == vpFFMPEG::COLORED)
202  avpicture_fill((AVPicture *)pFrameRGB, buffer, PIX_FMT_RGB24, pCodecCtx->width, pCodecCtx->height);
203 
204  else if (color_type == vpFFMPEG::GRAY_SCALED)
205  avpicture_fill((AVPicture *)pFrameGRAY, buffer, PIX_FMT_GRAY8, pCodecCtx->width, pCodecCtx->height);
206 
207  streamWasOpen = true;
208 
209  return true;
210 }
211 
220 {
221  if (color_type == vpFFMPEG::COLORED)
222  img_convert_ctx= sws_getContext(pCodecCtx->width, pCodecCtx->height, pCodecCtx->pix_fmt, pCodecCtx->width,pCodecCtx->height,PIX_FMT_RGB24, SWS_BICUBIC, NULL, NULL, NULL);
223 
224  else if (color_type == vpFFMPEG::GRAY_SCALED)
225  img_convert_ctx= sws_getContext(pCodecCtx->width, pCodecCtx->height, pCodecCtx->pix_fmt, pCodecCtx->width,pCodecCtx->height,PIX_FMT_GRAY8, SWS_BICUBIC, NULL, NULL, NULL);
226 
227  int ret = av_seek_frame(pFormatCtx, (int)videoStream, 0, AVSEEK_FLAG_ANY) ;
228  if (ret < 0 )
229  {
230  vpTRACE("Error rewinding stream for full indexing") ;
231  return false ;
232  }
233  avcodec_flush_buffers(pCodecCtx) ;
234 
235  int frame_no = 0 ;
236  int frameFinished ;
237 
238  while (av_read_frame (pFormatCtx, packet) >= 0)
239  {
240  if (packet->stream_index == (int)videoStream)
241  {
242 #if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(52,72,2)
243  ret = avcodec_decode_video(pCodecCtx, pFrame,
244  &frameFinished, packet->data, packet->size);
245 #else
246  ret = avcodec_decode_video2(pCodecCtx, pFrame, &frameFinished, packet); // libavcodec >= 52.72.2 (0.6)
247 #endif
248  if (frameFinished)
249  {
250  if (ret < 0 )
251  {
252  vpTRACE("Unable to decode video picture");
253  }
254  index.push_back(packet->dts);
255  frame_no++ ;
256  }
257  }
258  }
259 
260  frameNumber = index.size();
261  av_free_packet(packet);
262 
263  streamWasInitialized = true;
264 
265  return true;
266 }
267 
268 
277 bool vpFFMPEG::getFrame(vpImage<vpRGBa> &I, unsigned int frame)
278 {
279 
280  if (frame < frameNumber && streamWasInitialized== true)
281  {
282  int64_t targetPts = index[frame];
283  av_seek_frame(pFormatCtx, (int)videoStream,targetPts, AVSEEK_FLAG_ANY);
284  }
285  else
286  {
287  vpTRACE("Couldn't get a frame");
288  return false;
289  }
290 
291  avcodec_flush_buffers(pCodecCtx) ;
292 
293  int frameFinished ;
294 
295  while (av_read_frame (pFormatCtx, packet) >= 0)
296  {
297  if (packet->stream_index == (int)videoStream)
298  {
299 #if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(52,72,2)
300  avcodec_decode_video(pCodecCtx, pFrame,
301  &frameFinished, packet->data, packet->size);
302 #else
303  avcodec_decode_video2(pCodecCtx, pFrame, &frameFinished, packet); // libavcodec >= 52.72.2 (0.6)
304 #endif
305  if (frameFinished)
306  {
307  if (color_type == vpFFMPEG::COLORED)
308  sws_scale(img_convert_ctx, pFrame->data, pFrame->linesize, 0, pCodecCtx->height, pFrameRGB->data, pFrameRGB->linesize);
309  else if (color_type == vpFFMPEG::GRAY_SCALED)
310  sws_scale(img_convert_ctx, pFrame->data, pFrame->linesize, 0, pCodecCtx->height, pFrameGRAY->data, pFrameGRAY->linesize);
311 
312  copyBitmap(I);
313  break;
314  }
315  }
316  }
317 
318  av_free_packet(packet);
319  return true;
320 }
321 
322 
331 {
332  int frameFinished ;
333 
334  if (streamWasInitialized == false)
335  {
336  vpTRACE("Couldn't get a frame. The parameters have to be initialized before ");
337  return false;
338  }
339 
340  while (av_read_frame (pFormatCtx, packet) >= 0)
341  {
342  if (packet->stream_index == (int)videoStream)
343  {
344 #if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(52,72,2)
345  avcodec_decode_video(pCodecCtx, pFrame,
346  &frameFinished, packet->data, packet->size);
347 #else
348  avcodec_decode_video2(pCodecCtx, pFrame, &frameFinished, packet); // libavcodec >= 52.72.2 (0.6)
349 #endif
350  if (frameFinished)
351  {
352  if (color_type == vpFFMPEG::COLORED)
353  sws_scale(img_convert_ctx, pFrame->data, pFrame->linesize, 0, pCodecCtx->height, pFrameRGB->data, pFrameRGB->linesize);
354  else if (color_type == vpFFMPEG::GRAY_SCALED)
355  sws_scale(img_convert_ctx, pFrame->data, pFrame->linesize, 0, pCodecCtx->height, pFrameGRAY->data, pFrameGRAY->linesize);
356 
357  copyBitmap(I);
358  break;
359  }
360  }
361  }
362  av_free_packet(packet);
363  return true;
364 }
365 
374 bool vpFFMPEG::getFrame(vpImage<unsigned char> &I, unsigned int frame)
375 {
376 
377  if (frame < frameNumber && streamWasInitialized== true)
378  {
379  int64_t targetPts = index[frame];
380  av_seek_frame(pFormatCtx,(int)videoStream,targetPts, AVSEEK_FLAG_ANY);
381  }
382  else
383  {
384  vpTRACE("Couldn't get a frame");
385  return false;
386  }
387 
388  avcodec_flush_buffers(pCodecCtx) ;
389 
390  int frameFinished ;
391 
392  while (av_read_frame (pFormatCtx, packet) >= 0)
393  {
394  if (packet->stream_index == (int)videoStream)
395  {
396 #if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(52,72,2)
397  avcodec_decode_video(pCodecCtx, pFrame,
398  &frameFinished, packet->data, packet->size);
399 #else
400  avcodec_decode_video2(pCodecCtx, pFrame, &frameFinished, packet); // libavcodec >= 52.72.2 (0.6)
401 #endif
402  if (frameFinished)
403  {
404  if (color_type == vpFFMPEG::COLORED)
405  sws_scale(img_convert_ctx, pFrame->data, pFrame->linesize, 0, pCodecCtx->height, pFrameRGB->data, pFrameRGB->linesize);
406  else if (color_type == vpFFMPEG::GRAY_SCALED)
407  sws_scale(img_convert_ctx, pFrame->data, pFrame->linesize, 0, pCodecCtx->height, pFrameGRAY->data, pFrameGRAY->linesize);
408 
409  copyBitmap(I);
410  break;
411  }
412  }
413  }
414 
415  av_free_packet(packet);
416  return true;
417 }
418 
419 
428 {
429  int frameFinished ;
430 
431  if (streamWasInitialized == false)
432  {
433  vpTRACE("Couldn't get a frame. The parameters have to be initialized before ");
434  return false;
435  }
436 
437  while (av_read_frame (pFormatCtx, packet) >= 0)
438  {
439  if (packet->stream_index == (int)videoStream)
440  {
441 #if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(52,72,2)
442  avcodec_decode_video(pCodecCtx, pFrame,
443  &frameFinished, packet->data, packet->size);
444 #else
445  avcodec_decode_video2(pCodecCtx, pFrame, &frameFinished, packet); // libavcodec >= 52.72.2 (0.6)
446 #endif
447  if (frameFinished)
448  {
449  if (color_type == vpFFMPEG::COLORED)
450  sws_scale(img_convert_ctx, pFrame->data, pFrame->linesize, 0, pCodecCtx->height, pFrameRGB->data, pFrameRGB->linesize);
451  else if (color_type == vpFFMPEG::GRAY_SCALED)
452  sws_scale(img_convert_ctx, pFrame->data, pFrame->linesize, 0, pCodecCtx->height, pFrameGRAY->data, pFrameGRAY->linesize);
453 
454  copyBitmap(I);
455  break;
456  }
457  }
458  }
459  av_free_packet(packet);
460  return true;
461 }
462 
463 
472 void vpFFMPEG::copyBitmap(vpImage<vpRGBa> &I)
473 {
474  if(height < 0 || width < 0){
475  throw vpException(vpException::dimensionError, "width or height negative.");
476  }
477  I.resize((unsigned int)height, (unsigned int)width);
478 
479  unsigned char* line;
480  unsigned char* beginOutput = (unsigned char*)I.bitmap;
481  unsigned char* output = NULL;
482 
483  if (color_type == COLORED)
484  {
485  unsigned char* input = (unsigned char*)pFrameRGB->data[0];
486  int widthStep = pFrameRGB->linesize[0];
487  for(int i=0 ; i < height ; i++)
488  {
489  line = input;
490  output = beginOutput + 4 * width * i;
491  for(int j=0 ; j < width ; j++)
492  {
493  *(output++) = *(line);
494  *(output++) = *(line+1);
495  *(output++) = *(line+2);
496  *(output++) = 0;
497 
498  line+=3;
499  }
500  //go to the next line
501  input+=widthStep;
502  }
503  }
504 
505  else if (color_type == GRAY_SCALED)
506  {
507  unsigned char* input = (unsigned char*)pFrameGRAY->data[0];
508  int widthStep = pFrameGRAY->linesize[0];
509  for(int i=0 ; i < height ; i++)
510  {
511  line = input;
512  output = beginOutput + 4 * width * i;
513  for(int j=0 ; j < width ; j++)
514  {
515  *output++ = *(line);
516  *output++ = *(line);
517  *output++ = *(line);
518  *output++ = *(line);;
519 
520  line++;
521  }
522  //go to the next line
523  input+=widthStep;
524  }
525  }
526 }
527 
536 void vpFFMPEG::copyBitmap(vpImage<unsigned char> &I)
537 {
538  if(height < 0 || width < 0){
539  throw vpException(vpException::dimensionError, "width or height negative.");
540  }
541  I.resize((unsigned int)height, (unsigned int)width);
542 
543  unsigned char* line;
544  unsigned char* beginOutput = (unsigned char*)I.bitmap;
545  unsigned char* output = NULL;
546 
547  if (color_type == GRAY_SCALED)
548  {
549  unsigned char* input = (unsigned char*)pFrameGRAY->data[0];
550  int widthStep = pFrameGRAY->linesize[0];
551  for(int i=0 ; i < height ; i++)
552  {
553  line = input;
554  output = beginOutput + width * i;
555  for(int j=0 ; j < width ; j++)
556  {
557  *(output++) = *(line);
558 
559  line++;
560  }
561  //go to the next line
562  input+=widthStep;
563  }
564  }
565 
566  if (color_type == COLORED)
567  {
568  unsigned char* input = (unsigned char*)pFrameRGB->data[0];
569  int widthStep = pFrameRGB->linesize[0];
570  for (int i = 0 ; i < height ; i++)
571  {
572  vpImageConvert::RGBToGrey(input + i*widthStep, beginOutput + i*width, (unsigned int)width, 1, false);
573  }
574  }
575 }
576 
581 {
582  if (streamWasOpen)
583  {
584  av_free(buffer);
585 
586  if (color_type == vpFFMPEG::COLORED)
587  av_free(pFrameRGB);
588 
589  else if (color_type == vpFFMPEG::GRAY_SCALED)
590  av_free(pFrameGRAY);
591 
592  // Free the YUV frame
593  av_free(pFrame);
594 
595  // Close the codec
596  avcodec_close(pCodecCtx);
597 
598  // Close the video file
599 #if LIBAVFORMAT_VERSION_INT < AV_VERSION_INT(53,17,0) // libavformat 53.17.0
600  av_close_input_file(pFormatCtx);
601 #else
602  avformat_close_input(&pFormatCtx);
603 #endif
604  }
605  streamWasOpen = false;
606 
607  if (encoderWasOpened)
608  {
609  if(f!=NULL) endWrite();
610 
611  if(buffer!=NULL) delete[] buffer;
612 
613  if(outbuf != NULL) delete[] outbuf;
614 
615  if(picture_buf != NULL) delete[] picture_buf;
616 
617  av_free(pFrameRGB);
618  av_free(pFrame);
619  avcodec_close(pCodecCtx);
620  }
621 
622  encoderWasOpened = false;
623 
624  if(streamWasInitialized){
625  sws_freeContext (img_convert_ctx);
626  }
627  streamWasInitialized = false;
628 }
629 
644 bool vpFFMPEG::openEncoder(const char *filename, unsigned int width, unsigned int height, CodecID codec)
645 {
646  av_register_all();
647 
648  /* find the mpeg1 video encoder */
649  pCodec = avcodec_find_encoder(codec);
650  if (pCodec == NULL) {
651  fprintf(stderr, "codec not found\n");
652  return false;
653  }
654 
655 #if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(53,5,0) // libavcodev 53.5.0
656  pCodecCtx = avcodec_alloc_context();
657 #else
658  pCodecCtx = avcodec_alloc_context3(NULL);
659 #endif
660  pFrame = avcodec_alloc_frame();
661  pFrameRGB = avcodec_alloc_frame();
662 
663  /* put sample parameters */
664  pCodecCtx->bit_rate = (int)bit_rate;
665  /* resolution must be a multiple of two */
666  pCodecCtx->width = (int)width;
667  pCodecCtx->height = (int)height;
668  this->width = (int)width;
669  this->height = (int)height;
670  /* frames per second */
671  pCodecCtx->time_base= (AVRational){1,25};
672  pCodecCtx->gop_size = 10; /* emit one intra frame every ten frames */
673  pCodecCtx->max_b_frames=1;
674  pCodecCtx->pix_fmt = PIX_FMT_YUV420P;
675 
676  /* open it */
677 #if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(53,35,0) // libavcodev 53.35.0
678  if (avcodec_open (pCodecCtx, pCodec) < 0) {
679 #else
680  if (avcodec_open2 (pCodecCtx, pCodec, NULL) < 0) {
681 #endif
682  fprintf(stderr, "could not open codec\n");
683  exit(1);
684  }
685 
686  /* the codec gives us the frame size, in samples */
687 
688  f = fopen(filename, "wb");
689  if (!f) {
690  fprintf(stderr, "could not open %s\n", filename);
691  return false;
692  }
693 
694  outbuf_size = 100000;
695  outbuf = new uint8_t[outbuf_size];
696 
697  numBytes = avpicture_get_size (PIX_FMT_YUV420P,pCodecCtx->width,pCodecCtx->height);
698  picture_buf = new uint8_t[numBytes];
699  avpicture_fill((AVPicture *)pFrame, picture_buf, PIX_FMT_YUV420P, pCodecCtx->width, pCodecCtx->height);
700 
701  numBytes = avpicture_get_size (PIX_FMT_RGB24,pCodecCtx->width,pCodecCtx->height);
702  buffer = new uint8_t[numBytes];
703  avpicture_fill((AVPicture *)pFrameRGB, buffer, PIX_FMT_RGB24, pCodecCtx->width, pCodecCtx->height);
704 
705  img_convert_ctx= sws_getContext(pCodecCtx->width, pCodecCtx->height, PIX_FMT_RGB24, pCodecCtx->width,pCodecCtx->height,PIX_FMT_YUV420P, SWS_BICUBIC, NULL, NULL, NULL);
706 
707  encoderWasOpened = true;
708 
709  return true;
710 }
711 
712 
721 {
722  if (encoderWasOpened == false)
723  {
724  vpTRACE("Couldn't save a frame. The parameters have to be initialized before ");
725  return false;
726  }
727 
728  writeBitmap(I);
729  sws_scale(img_convert_ctx, pFrameRGB->data, pFrameRGB->linesize, 0, pCodecCtx->height, pFrame->data, pFrame->linesize);
730  out_size = avcodec_encode_video(pCodecCtx, outbuf, outbuf_size, pFrame);
731  fwrite(outbuf, 1, (size_t)out_size, f);
732  fflush(stdout);
733  return true;
734 }
735 
736 
745 {
746  if (encoderWasOpened == false)
747  {
748  vpTRACE("Couldn't save a frame. The parameters have to be initialized before ");
749  return false;
750  }
751 
752  writeBitmap(I);
753  sws_scale(img_convert_ctx, pFrameRGB->data, pFrameRGB->linesize, 0, pCodecCtx->height, pFrame->data, pFrame->linesize);
754  out_size = avcodec_encode_video(pCodecCtx, outbuf, outbuf_size, pFrame);
755  fwrite(outbuf, 1, (size_t)out_size, f);
756  fflush(stdout);
757  return true;
758 }
759 
766 {
767  if (encoderWasOpened == false)
768  {
769  vpTRACE("Couldn't save a frame. The parameters have to be initialized before ");
770  return false;
771  }
772 
773  while (out_size != 0)
774  {
775  out_size = avcodec_encode_video(pCodecCtx, outbuf, outbuf_size, NULL);
776  fwrite(outbuf, 1, (size_t)out_size, f);
777  }
778 
779  /*The end of a mpeg file*/
780  outbuf[0] = 0x00;
781  outbuf[1] = 0x00;
782  outbuf[2] = 0x01;
783  outbuf[3] = 0xb7;
784  fwrite(outbuf, 1, 4, f);
785  fclose(f);
786  f = NULL;
787  return true;
788 }
789 
793 void vpFFMPEG::writeBitmap(vpImage<vpRGBa> &I)
794 {
795  unsigned char* beginInput = (unsigned char*)I.bitmap;
796  unsigned char* input = NULL;
797  unsigned char* output = NULL;
798  unsigned char* beginOutput = (unsigned char*)pFrameRGB->data[0];
799  int widthStep = pFrameRGB->linesize[0];
800 
801  for(int i=0 ; i < height ; i++)
802  {
803  input = beginInput + 4 * i * width;
804  output = beginOutput + i * widthStep;
805  for(int j=0 ; j < width ; j++)
806  {
807  *(output++) = *(input);
808  *(output++) = *(input+1);
809  *(output++) = *(input+2);
810 
811  input+=4;
812  }
813  }
814 }
815 
816 
820 void vpFFMPEG::writeBitmap(vpImage<unsigned char> &I)
821 {
822  unsigned char* beginInput = (unsigned char*)I.bitmap;
823  unsigned char* input = NULL;
824  unsigned char* output = NULL;
825  unsigned char* beginOutput = (unsigned char*)pFrameRGB->data[0];
826  int widthStep = pFrameRGB->linesize[0];
827 
828  for(int i=0 ; i < height ; i++)
829  {
830  input = beginInput + i * width;
831  output = beginOutput + i * widthStep;
832  for(int j=0 ; j < width ; j++)
833  {
834  *(output++) = *(input);
835  *(output++) = *(input);
836  *(output++) = *(input);
837 
838  input++;
839  }
840  }
841 }
842 
843 #endif
static void RGBToGrey(unsigned char *rgb, unsigned char *grey, unsigned int size)
#define vpTRACE
Definition: vpDebug.h:401
Type * bitmap
points toward the bitmap
Definition: vpImage.h:115
bool saveFrame(vpImage< vpRGBa > &I)
Definition: vpFFMPEG.cpp:720
bool getFrame(vpImage< vpRGBa > &I, unsigned int frameNumber)
Definition: vpFFMPEG.cpp:277
void resize(const unsigned int height, const unsigned int width)
set the size of the image
Definition: vpImage.h:530
error that can be emited by ViSP classes.
Definition: vpException.h:75
vpFFMPEG()
Definition: vpFFMPEG.cpp:67
bool openEncoder(const char *filename, unsigned int width, unsigned int height, CodecID codec=CODEC_ID_MPEG1VIDEO)
Definition: vpFFMPEG.cpp:644
bool openStream(const char *filename, vpFFMPEGColorType color_type)
Definition: vpFFMPEG.cpp:103
~vpFFMPEG()
Definition: vpFFMPEG.cpp:88
vpFFMPEGColorType
Definition: vpFFMPEG.h:157
void closeStream()
Definition: vpFFMPEG.cpp:580
bool acquire(vpImage< vpRGBa > &I)
Definition: vpFFMPEG.cpp:330
bool initStream()
Definition: vpFFMPEG.cpp:219
bool endWrite()
Definition: vpFFMPEG.cpp:765