ViSP  2.6.2
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 - 2012 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 
87 {
88  closeStream();
89  delete packet;
90 }
91 
101 bool vpFFMPEG::openStream(const char *filename, vpFFMPEGColorType color_type)
102 {
103  this->color_type = color_type;
104 
105  av_register_all();
106 #if LIBAVFORMAT_VERSION_INT < AV_VERSION_INT(53,0,0) // libavformat 52.84.0
107  if (av_open_input_file (&pFormatCtx, filename, NULL, 0, NULL) != 0)
108 #else
109  if (avformat_open_input (&pFormatCtx, filename, NULL, NULL) != 0) // libavformat 53.4.0
110 #endif
111  {
112  vpTRACE("Couldn't open file ");
113  return false;
114  }
115 
116 #if LIBAVFORMAT_VERSION_INT < AV_VERSION_INT(53,21,0) // libavformat 53.21.0
117  if (av_find_stream_info (pFormatCtx) < 0)
118 #else
119  if (avformat_find_stream_info (pFormatCtx, NULL) < 0)
120 #endif
121  return false;
122 
123  videoStream = 0;
124  bool found_codec = false;
125 
126  /*
127  * Detect streams types
128  */
129  for (unsigned int i = 0; i < pFormatCtx->nb_streams; i++)
130  {
131 #if LIBAVUTIL_VERSION_INT < AV_VERSION_INT(51,0,0)
132  if(pFormatCtx->streams[i]->codec->codec_type==CODEC_TYPE_VIDEO) // avutil 50.33.0
133 #else
134  if(pFormatCtx->streams[i]->codec->codec_type==AVMEDIA_TYPE_VIDEO) // avutil 51.9.1
135 #endif
136  {
137  videoStream = i;
138  found_codec= true;
139  break;
140  }
141  }
142 
143  if (found_codec)
144  {
145  pCodecCtx = pFormatCtx->streams[videoStream]->codec;
146  pCodec = avcodec_find_decoder(pCodecCtx->codec_id);
147 
148  if (pCodec == NULL)
149  {
150  vpTRACE("unsuported codec");
151  return false; // Codec not found
152  }
153 
154 #if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(53,35,0) // libavcodec 53.35.0
155  if (avcodec_open (pCodecCtx, pCodec) < 0)
156 #else
157  if (avcodec_open2 (pCodecCtx, pCodec, NULL) < 0)
158 #endif
159  {
160  vpTRACE("Could not open codec");
161  return false; // Could not open codec
162  }
163 
164  pFrame = avcodec_alloc_frame();
165 
166  if (color_type == vpFFMPEG::COLORED)
167  {
168  pFrameRGB=avcodec_alloc_frame();
169 
170  if (pFrameRGB == NULL)
171  return false;
172 
173  numBytes = avpicture_get_size (PIX_FMT_RGB24,pCodecCtx->width,pCodecCtx->height);
174  }
175 
176  else if (color_type == vpFFMPEG::GRAY_SCALED)
177  {
178  pFrameGRAY=avcodec_alloc_frame();
179 
180  if (pFrameGRAY == NULL)
181  return false;
182 
183  numBytes = avpicture_get_size (PIX_FMT_GRAY8,pCodecCtx->width,pCodecCtx->height);
184  }
185 
186  /*
187  * Determine required buffer size and allocate buffer
188  */
189  width = pCodecCtx->width ;
190  height = pCodecCtx->height ;
191  buffer = (uint8_t *) malloc (sizeof (uint8_t) * (size_t)numBytes);
192  }
193  else
194  {
195  vpTRACE("Didn't find a video stream");
196  return false;
197  }
198 
199  if (color_type == vpFFMPEG::COLORED)
200  avpicture_fill((AVPicture *)pFrameRGB, buffer, PIX_FMT_RGB24, pCodecCtx->width, pCodecCtx->height);
201 
202  else if (color_type == vpFFMPEG::GRAY_SCALED)
203  avpicture_fill((AVPicture *)pFrameGRAY, buffer, PIX_FMT_GRAY8, pCodecCtx->width, pCodecCtx->height);
204 
205  streamWasOpen = true;
206 
207  return true;
208 }
209 
218 {
219  if (color_type == vpFFMPEG::COLORED)
220  img_convert_ctx= sws_getContext(pCodecCtx->width, pCodecCtx->height, pCodecCtx->pix_fmt, pCodecCtx->width,pCodecCtx->height,PIX_FMT_RGB24, SWS_BICUBIC, NULL, NULL, NULL);
221 
222  else if (color_type == vpFFMPEG::GRAY_SCALED)
223  img_convert_ctx= sws_getContext(pCodecCtx->width, pCodecCtx->height, pCodecCtx->pix_fmt, pCodecCtx->width,pCodecCtx->height,PIX_FMT_GRAY8, SWS_BICUBIC, NULL, NULL, NULL);
224 
225  int ret = av_seek_frame(pFormatCtx, (int)videoStream, 0, AVSEEK_FLAG_ANY) ;
226  if (ret < 0 )
227  {
228  vpTRACE("Error rewinding stream for full indexing") ;
229  return false ;
230  }
231  avcodec_flush_buffers(pCodecCtx) ;
232 
233  int frame_no = 0 ;
234  int frameFinished ;
235 
236  while (av_read_frame (pFormatCtx, packet) >= 0)
237  {
238  if (packet->stream_index == (int)videoStream)
239  {
240 #if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(52,72,2)
241  ret = avcodec_decode_video(pCodecCtx, pFrame,
242  &frameFinished, packet->data, packet->size);
243 #else
244  ret = avcodec_decode_video2(pCodecCtx, pFrame, &frameFinished, packet); // libavcodec >= 52.72.2 (0.6)
245 #endif
246  if (frameFinished)
247  {
248  if (ret < 0 )
249  {
250  vpTRACE("Unable to decode video picture");
251  }
252  index.push_back(packet->dts);
253  frame_no++ ;
254  }
255  }
256  }
257 
258  frameNumber = index.size();
259  av_free_packet(packet);
260 
261  streamWasInitialized = true;
262 
263  return true;
264 }
265 
266 
275 bool vpFFMPEG::getFrame(vpImage<vpRGBa> &I, unsigned int frame)
276 {
277 
278  if (frame < frameNumber && streamWasInitialized== true)
279  {
280  int64_t targetPts = index[frame];
281  av_seek_frame(pFormatCtx, (int)videoStream,targetPts, AVSEEK_FLAG_ANY);
282  }
283  else
284  {
285  vpTRACE("Couldn't get a frame");
286  return false;
287  }
288 
289  avcodec_flush_buffers(pCodecCtx) ;
290 
291  int frameFinished ;
292 
293  while (av_read_frame (pFormatCtx, packet) >= 0)
294  {
295  if (packet->stream_index == (int)videoStream)
296  {
297 #if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(52,72,2)
298  avcodec_decode_video(pCodecCtx, pFrame,
299  &frameFinished, packet->data, packet->size);
300 #else
301  avcodec_decode_video2(pCodecCtx, pFrame, &frameFinished, packet); // libavcodec >= 52.72.2 (0.6)
302 #endif
303  if (frameFinished)
304  {
305  if (color_type == vpFFMPEG::COLORED)
306  sws_scale(img_convert_ctx, pFrame->data, pFrame->linesize, 0, pCodecCtx->height, pFrameRGB->data, pFrameRGB->linesize);
307  else if (color_type == vpFFMPEG::GRAY_SCALED)
308  sws_scale(img_convert_ctx, pFrame->data, pFrame->linesize, 0, pCodecCtx->height, pFrameGRAY->data, pFrameGRAY->linesize);
309 
310  copyBitmap(I);
311  break;
312  }
313  }
314  }
315 
316  av_free_packet(packet);
317  return true;
318 }
319 
320 
329 {
330  int frameFinished ;
331 
332  if (streamWasInitialized == false)
333  {
334  vpTRACE("Couldn't get a frame. The parameters have to be initialized before ");
335  return false;
336  }
337 
338  while (av_read_frame (pFormatCtx, packet) >= 0)
339  {
340  if (packet->stream_index == (int)videoStream)
341  {
342 #if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(52,72,2)
343  avcodec_decode_video(pCodecCtx, pFrame,
344  &frameFinished, packet->data, packet->size);
345 #else
346  avcodec_decode_video2(pCodecCtx, pFrame, &frameFinished, packet); // libavcodec >= 52.72.2 (0.6)
347 #endif
348  if (frameFinished)
349  {
350  if (color_type == vpFFMPEG::COLORED)
351  sws_scale(img_convert_ctx, pFrame->data, pFrame->linesize, 0, pCodecCtx->height, pFrameRGB->data, pFrameRGB->linesize);
352  else if (color_type == vpFFMPEG::GRAY_SCALED)
353  sws_scale(img_convert_ctx, pFrame->data, pFrame->linesize, 0, pCodecCtx->height, pFrameGRAY->data, pFrameGRAY->linesize);
354 
355  copyBitmap(I);
356  break;
357  }
358  }
359  }
360  av_free_packet(packet);
361  return true;
362 }
363 
372 bool vpFFMPEG::getFrame(vpImage<unsigned char> &I, unsigned int frame)
373 {
374 
375  if (frame < frameNumber && streamWasInitialized== true)
376  {
377  int64_t targetPts = index[frame];
378  av_seek_frame(pFormatCtx,(int)videoStream,targetPts, AVSEEK_FLAG_ANY);
379  }
380  else
381  {
382  vpTRACE("Couldn't get a frame");
383  return false;
384  }
385 
386  avcodec_flush_buffers(pCodecCtx) ;
387 
388  int frameFinished ;
389 
390  while (av_read_frame (pFormatCtx, packet) >= 0)
391  {
392  if (packet->stream_index == (int)videoStream)
393  {
394 #if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(52,72,2)
395  avcodec_decode_video(pCodecCtx, pFrame,
396  &frameFinished, packet->data, packet->size);
397 #else
398  avcodec_decode_video2(pCodecCtx, pFrame, &frameFinished, packet); // libavcodec >= 52.72.2 (0.6)
399 #endif
400  if (frameFinished)
401  {
402  if (color_type == vpFFMPEG::COLORED)
403  sws_scale(img_convert_ctx, pFrame->data, pFrame->linesize, 0, pCodecCtx->height, pFrameRGB->data, pFrameRGB->linesize);
404  else if (color_type == vpFFMPEG::GRAY_SCALED)
405  sws_scale(img_convert_ctx, pFrame->data, pFrame->linesize, 0, pCodecCtx->height, pFrameGRAY->data, pFrameGRAY->linesize);
406 
407  copyBitmap(I);
408  break;
409  }
410  }
411  }
412 
413  av_free_packet(packet);
414  return true;
415 }
416 
417 
426 {
427  int frameFinished ;
428 
429  if (streamWasInitialized == false)
430  {
431  vpTRACE("Couldn't get a frame. The parameters have to be initialized before ");
432  return false;
433  }
434 
435  while (av_read_frame (pFormatCtx, packet) >= 0)
436  {
437  if (packet->stream_index == (int)videoStream)
438  {
439 #if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(52,72,2)
440  avcodec_decode_video(pCodecCtx, pFrame,
441  &frameFinished, packet->data, packet->size);
442 #else
443  avcodec_decode_video2(pCodecCtx, pFrame, &frameFinished, packet); // libavcodec >= 52.72.2 (0.6)
444 #endif
445  if (frameFinished)
446  {
447  if (color_type == vpFFMPEG::COLORED)
448  sws_scale(img_convert_ctx, pFrame->data, pFrame->linesize, 0, pCodecCtx->height, pFrameRGB->data, pFrameRGB->linesize);
449  else if (color_type == vpFFMPEG::GRAY_SCALED)
450  sws_scale(img_convert_ctx, pFrame->data, pFrame->linesize, 0, pCodecCtx->height, pFrameGRAY->data, pFrameGRAY->linesize);
451 
452  copyBitmap(I);
453  break;
454  }
455  }
456  }
457  av_free_packet(packet);
458  return true;
459 }
460 
461 
470 void vpFFMPEG::copyBitmap(vpImage<vpRGBa> &I)
471 {
472  if(height < 0 || width < 0){
473  throw vpException(vpException::dimensionError, "width or height negative.");
474  }
475  I.resize((unsigned int)height, (unsigned int)width);
476 
477  unsigned char* line;
478  unsigned char* beginOutput = (unsigned char*)I.bitmap;
479  unsigned char* output = NULL;
480 
481  if (color_type == COLORED)
482  {
483  unsigned char* input = (unsigned char*)pFrameRGB->data[0];
484  int widthStep = pFrameRGB->linesize[0];
485  for(int i=0 ; i < height ; i++)
486  {
487  line = input;
488  output = beginOutput + 4 * width * i;
489  for(int j=0 ; j < width ; j++)
490  {
491  *(output++) = *(line);
492  *(output++) = *(line+1);
493  *(output++) = *(line+2);
494  *(output++) = 0;
495 
496  line+=3;
497  }
498  //go to the next line
499  input+=widthStep;
500  }
501  }
502 
503  else if (color_type == GRAY_SCALED)
504  {
505  unsigned char* input = (unsigned char*)pFrameGRAY->data[0];
506  int widthStep = pFrameGRAY->linesize[0];
507  for(int i=0 ; i < height ; i++)
508  {
509  line = input;
510  output = beginOutput + 4 * width * i;
511  for(int j=0 ; j < width ; j++)
512  {
513  *output++ = *(line);
514  *output++ = *(line);
515  *output++ = *(line);
516  *output++ = *(line);;
517 
518  line++;
519  }
520  //go to the next line
521  input+=widthStep;
522  }
523  }
524 }
525 
534 void vpFFMPEG::copyBitmap(vpImage<unsigned char> &I)
535 {
536  if(height < 0 || width < 0){
537  throw vpException(vpException::dimensionError, "width or height negative.");
538  }
539  I.resize((unsigned int)height, (unsigned int)width);
540 
541  unsigned char* line;
542  unsigned char* beginOutput = (unsigned char*)I.bitmap;
543  unsigned char* output = NULL;
544 
545  if (color_type == GRAY_SCALED)
546  {
547  unsigned char* input = (unsigned char*)pFrameGRAY->data[0];
548  int widthStep = pFrameGRAY->linesize[0];
549  for(int i=0 ; i < height ; i++)
550  {
551  line = input;
552  output = beginOutput + width * i;
553  for(int j=0 ; j < width ; j++)
554  {
555  *(output++) = *(line);
556 
557  line++;
558  }
559  //go to the next line
560  input+=widthStep;
561  }
562  }
563 
564  if (color_type == COLORED)
565  {
566  unsigned char* input = (unsigned char*)pFrameRGB->data[0];
567  int widthStep = pFrameRGB->linesize[0];
568  for (int i = 0 ; i < height ; i++)
569  {
570  vpImageConvert::RGBToGrey(input + i*widthStep, beginOutput + i*width, (unsigned int)width, 1, false);
571  }
572  }
573 }
574 
579 {
580  if (streamWasOpen)
581  {
582  av_free(buffer);
583 
584  if (color_type == vpFFMPEG::COLORED)
585  av_free(pFrameRGB);
586 
587  else if (color_type == vpFFMPEG::GRAY_SCALED)
588  av_free(pFrameGRAY);
589 
590  // Free the YUV frame
591  av_free(pFrame);
592 
593  // Close the codec
594  avcodec_close(pCodecCtx);
595 
596  // Close the video file
597 #if LIBAVFORMAT_VERSION_INT < AV_VERSION_INT(53,17,0) // libavformat 53.17.0
598  av_close_input_file(pFormatCtx);
599 #else
600  avformat_close_input(&pFormatCtx);
601 #endif
602  }
603  streamWasOpen = false;
604 
605  if (encoderWasOpened)
606  {
607  if(f!=NULL) endWrite();
608 
609  if(buffer!=NULL) delete[] buffer;
610 
611  if(outbuf != NULL) delete[] outbuf;
612 
613  if(picture_buf != NULL) delete[] picture_buf;
614 
615  av_free(pFrameRGB);
616  av_free(pFrame);
617  avcodec_close(pCodecCtx);
618  }
619 
620  encoderWasOpened = false;
621 
622  if(streamWasInitialized){
623  sws_freeContext (img_convert_ctx);
624  }
625  streamWasInitialized = false;
626 }
627 
642 bool vpFFMPEG::openEncoder(const char *filename, unsigned int width, unsigned int height, CodecID codec)
643 {
644  av_register_all();
645 
646  /* find the mpeg1 video encoder */
647  pCodec = avcodec_find_encoder(codec);
648  if (pCodec == NULL) {
649  fprintf(stderr, "codec not found\n");
650  return false;
651  }
652 
653 #if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(53,5,0) // libavcodev 53.5.0
654  pCodecCtx = avcodec_alloc_context();
655 #else
656  pCodecCtx = avcodec_alloc_context3(NULL);
657 #endif
658  pFrame = avcodec_alloc_frame();
659  pFrameRGB = avcodec_alloc_frame();
660 
661  /* put sample parameters */
662  pCodecCtx->bit_rate = (int)bit_rate;
663  /* resolution must be a multiple of two */
664  pCodecCtx->width = (int)width;
665  pCodecCtx->height = (int)height;
666  this->width = (int)width;
667  this->height = (int)height;
668  /* frames per second */
669  pCodecCtx->time_base= (AVRational){1,25};
670  pCodecCtx->gop_size = 10; /* emit one intra frame every ten frames */
671  pCodecCtx->max_b_frames=1;
672  pCodecCtx->pix_fmt = PIX_FMT_YUV420P;
673 
674  /* open it */
675 #if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(53,35,0) // libavcodev 53.35.0
676  if (avcodec_open (pCodecCtx, pCodec) < 0) {
677 #else
678  if (avcodec_open2 (pCodecCtx, pCodec, NULL) < 0) {
679 #endif
680  fprintf(stderr, "could not open codec\n");
681  exit(1);
682  }
683 
684  /* the codec gives us the frame size, in samples */
685 
686  f = fopen(filename, "wb");
687  if (!f) {
688  fprintf(stderr, "could not open %s\n", filename);
689  return false;
690  }
691 
692  outbuf_size = 100000;
693  outbuf = new uint8_t[outbuf_size];
694 
695  numBytes = avpicture_get_size (PIX_FMT_YUV420P,pCodecCtx->width,pCodecCtx->height);
696  picture_buf = new uint8_t[numBytes];
697  avpicture_fill((AVPicture *)pFrame, picture_buf, PIX_FMT_YUV420P, pCodecCtx->width, pCodecCtx->height);
698 
699  numBytes = avpicture_get_size (PIX_FMT_RGB24,pCodecCtx->width,pCodecCtx->height);
700  buffer = new uint8_t[numBytes];
701  avpicture_fill((AVPicture *)pFrameRGB, buffer, PIX_FMT_RGB24, pCodecCtx->width, pCodecCtx->height);
702 
703  img_convert_ctx= sws_getContext(pCodecCtx->width, pCodecCtx->height, PIX_FMT_RGB24, pCodecCtx->width,pCodecCtx->height,PIX_FMT_YUV420P, SWS_BICUBIC, NULL, NULL, NULL);
704 
705  encoderWasOpened = true;
706 
707  return true;
708 }
709 
710 
719 {
720  if (encoderWasOpened == false)
721  {
722  vpTRACE("Couldn't save a frame. The parameters have to be initialized before ");
723  return false;
724  }
725 
726  writeBitmap(I);
727  sws_scale(img_convert_ctx, pFrameRGB->data, pFrameRGB->linesize, 0, pCodecCtx->height, pFrame->data, pFrame->linesize);
728  out_size = avcodec_encode_video(pCodecCtx, outbuf, outbuf_size, pFrame);
729  fwrite(outbuf, 1, (size_t)out_size, f);
730  fflush(stdout);
731  return true;
732 }
733 
734 
743 {
744  if (encoderWasOpened == false)
745  {
746  vpTRACE("Couldn't save a frame. The parameters have to be initialized before ");
747  return false;
748  }
749 
750  writeBitmap(I);
751  sws_scale(img_convert_ctx, pFrameRGB->data, pFrameRGB->linesize, 0, pCodecCtx->height, pFrame->data, pFrame->linesize);
752  out_size = avcodec_encode_video(pCodecCtx, outbuf, outbuf_size, pFrame);
753  fwrite(outbuf, 1, (size_t)out_size, f);
754  fflush(stdout);
755  return true;
756 }
757 
764 {
765  if (encoderWasOpened == false)
766  {
767  vpTRACE("Couldn't save a frame. The parameters have to be initialized before ");
768  return false;
769  }
770 
771  while (out_size != 0)
772  {
773  out_size = avcodec_encode_video(pCodecCtx, outbuf, outbuf_size, NULL);
774  fwrite(outbuf, 1, (size_t)out_size, f);
775  }
776 
777  /*The end of a mpeg file*/
778  outbuf[0] = 0x00;
779  outbuf[1] = 0x00;
780  outbuf[2] = 0x01;
781  outbuf[3] = 0xb7;
782  fwrite(outbuf, 1, 4, f);
783  fclose(f);
784  f = NULL;
785  return true;
786 }
787 
791 void vpFFMPEG::writeBitmap(vpImage<vpRGBa> &I)
792 {
793  unsigned char* beginInput = (unsigned char*)I.bitmap;
794  unsigned char* input = NULL;
795  unsigned char* output = NULL;
796  unsigned char* beginOutput = (unsigned char*)pFrameRGB->data[0];
797  int widthStep = pFrameRGB->linesize[0];
798 
799  for(int i=0 ; i < height ; i++)
800  {
801  input = beginInput + 4 * i * width;
802  output = beginOutput + i * widthStep;
803  for(int j=0 ; j < width ; j++)
804  {
805  *(output++) = *(input);
806  *(output++) = *(input+1);
807  *(output++) = *(input+2);
808 
809  input+=4;
810  }
811  }
812 }
813 
814 
818 void vpFFMPEG::writeBitmap(vpImage<unsigned char> &I)
819 {
820  unsigned char* beginInput = (unsigned char*)I.bitmap;
821  unsigned char* input = NULL;
822  unsigned char* output = NULL;
823  unsigned char* beginOutput = (unsigned char*)pFrameRGB->data[0];
824  int widthStep = pFrameRGB->linesize[0];
825 
826  for(int i=0 ; i < height ; i++)
827  {
828  input = beginInput + i * width;
829  output = beginOutput + i * widthStep;
830  for(int j=0 ; j < width ; j++)
831  {
832  *(output++) = *(input);
833  *(output++) = *(input);
834  *(output++) = *(input);
835 
836  input++;
837  }
838  }
839 }
840 
841 #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:718
bool getFrame(vpImage< vpRGBa > &I, unsigned int frameNumber)
Definition: vpFFMPEG.cpp:275
void resize(const unsigned int height, const unsigned int width)
set the size of the image
Definition: vpImage.h:530
vpFFMPEG()
Definition: vpFFMPEG.cpp:67
bool openEncoder(const char *filename, unsigned int width, unsigned int height, CodecID codec=CODEC_ID_MPEG1VIDEO)
Definition: vpFFMPEG.cpp:642
bool openStream(const char *filename, vpFFMPEGColorType color_type)
Definition: vpFFMPEG.cpp:101
~vpFFMPEG()
Definition: vpFFMPEG.cpp:86
vpFFMPEGColorType
Definition: vpFFMPEG.h:157
void closeStream()
Definition: vpFFMPEG.cpp:578
bool acquire(vpImage< vpRGBa > &I)
Definition: vpFFMPEG.cpp:328
bool initStream()
Definition: vpFFMPEG.cpp:217
bool endWrite()
Definition: vpFFMPEG.cpp:763