Index: /branches/avi_play/src/world_entities/recorder.cc
===================================================================
--- /branches/avi_play/src/world_entities/recorder.cc	(revision 6680)
+++ /branches/avi_play/src/world_entities/recorder.cc	(revision 6681)
@@ -33,4 +33,8 @@
   av_register_all();
 
+  // Default values
+  stream_duration = 10;
+  stream_frame_rate = 20;
+
   this->loadParams(root);
 
@@ -49,12 +53,27 @@
   WorldEntity::loadParams(root);
 
+  LoadParam(root, "duration", this, Recorder, setStreamDuration);
+  LoadParam(root, "fps", this, Recorder, setFPS);
   LoadParam(root, "name", this, Recorder, initVideo);
 }
 
 
+void Recorder::setStreamDuration(float duration)
+{
+  this->stream_duration = duration;
+}
+
+
+void Recorder::setFPS(float fps)
+{
+  this->stream_frame_rate = fps;
+}
+
+
 void Recorder::initVideo(const char* filename)
 {
   frame_count = 0;
-  time = 0;  
+  time = 0;
+  stream_nb_frames = (int)(stream_duration * stream_frame_rate);
 
   // auto detect the output format from the name, default is mpeg
@@ -172,4 +191,15 @@
   avpicture_fill((AVPicture *)picture, picture_buf, 
                   codec_context->pix_fmt, width, height);
+
+
+
+  RGB_frame = avcodec_alloc_frame();
+
+  // Determine required buffer size and allocate buffer
+  size = avpicture_get_size(PIX_FMT_RGB24, width, height);
+  picture_buf = new uint8_t[size];
+
+  // Assign appropriate parts of buffer to image planes in RGB_frame
+  avpicture_fill((AVPicture *)RGB_frame, picture_buf, PIX_FMT_RGB24, width, height);
 }
 
@@ -199,8 +229,8 @@
   // timebase should be 1/framerate and timestamp increments should be
   // identically 1
-  codec_context->time_base.den = STREAM_FRAME_RATE;  
+  codec_context->time_base.den = (int)stream_frame_rate;  
   codec_context->time_base.num = 1;
   codec_context->gop_size = 12;  // emit one intra frame every twelve frames at most
-  codec_context->pix_fmt = STREAM_PIX_FMT;
+  codec_context->pix_fmt = PIX_FMT_YUV420P;
 
   if (codec_context->codec_id == CODEC_ID_MPEG1VIDEO)
@@ -221,5 +251,5 @@
 {
   time += dt;
-  if(time < 1/STREAM_FRAME_RATE)
+  if(time < 1/stream_frame_rate)
     return;
   else
@@ -232,5 +262,5 @@
       video_pts = 0.0;
 
-  if (!video_stream || video_pts >= STREAM_DURATION)
+  if (!video_stream || video_pts >= stream_duration)
   {
     this->toList(OM_DEAD);
@@ -248,5 +278,5 @@
   codec_context = video_stream->codec;
   
-  if(frame_count >= STREAM_NB_FRAMES)
+  if(frame_count >= stream_nb_frames)
   {
     /* no more frame to compress. The codec has a latency of a few
@@ -315,42 +345,17 @@
   glReadPixels(0, 0, width, height, GL_RGB, GL_UNSIGNED_BYTE, outputImage);
 
-  /*
-  RGB to YUV Conversion
-  
-  Y  =      (0.257 * R) + (0.504 * G) + (0.098 * B) + 16
-  
-  Cr = V =  (0.439 * R) - (0.368 * G) - (0.071 * B) + 128
-  
-  Cb = U = -(0.148 * R) - (0.291 * G) + (0.439 * B) + 128
-  */
-
-  // Conversion RGB -> YUV 420
-  // not right yet
-
-  // Y
-  int i = 0, x, y;
-  for(y=height-1;y>=0;y--)
-  {
-    for(x=0;x<width;x++)
+  int i = 0;
+  for(int y=height-1;y>=0;y--)
+  {
+    for(int x=0;x<width*3;x++)
     {
-      picture->data[0][y*width+x] = (0.257 * outputImage[i]) + (0.504 * outputImage[i+1]) + (0.098 * outputImage[i+2]) + 16;
-      i += 3;
+      RGB_frame->data[0][y*width*3+x] = outputImage[i];
+      i++;
     }
   }
-  i=0;
-
-  // Cb and Cr
-  for(y=height/2-1;y>=0;y--)
-  {
-    for(x=0;x<width/2;x++)
-    {
-      picture->data[1][y*width/2+x] = -(0.148 * outputImage[i]) - (0.291 * outputImage[i+1]) + (0.439 * outputImage[i+2]) + 128;
-      picture->data[2][y*width/2+x] = (0.439 * outputImage[i]) - (0.368 * outputImage[i+1]) - (0.071 * outputImage[i+2]) + 128;
-      i+=6;
-
-      if(x+1 == width/2)
-        i+=3*width;
-    }
-  }
+
+
+  img_convert((AVPicture*)picture, PIX_FMT_YUV420P, (AVPicture*)RGB_frame,
+              PIX_FMT_RGB24, width, height);
 
   // Clear the allocated memory.
Index: /branches/avi_play/src/world_entities/recorder.h
===================================================================
--- /branches/avi_play/src/world_entities/recorder.h	(revision 6680)
+++ /branches/avi_play/src/world_entities/recorder.h	(revision 6681)
@@ -6,10 +6,4 @@
 #ifndef _RECORDER_H
 #define _RECORDER_H
-
-#define STREAM_DURATION   40.0
-#define STREAM_FRAME_RATE 20
-#define STREAM_NB_FRAMES  ((int)(STREAM_DURATION * STREAM_FRAME_RATE))
-#define STREAM_PIX_FMT PIX_FMT_YUV420P
-
 
 #include <SDL.h>
@@ -47,4 +41,9 @@
     float time;
 
+    float stream_duration;
+    float stream_frame_rate;
+    int stream_nb_frames;
+
+AVFrame* RGB_frame;
   public:
     Recorder (const TiXmlElement* root = NULL);
@@ -64,4 +63,7 @@
     void writeVideoFrame();
     void fillYuvImage();
+
+    void setStreamDuration(float duration);
+    void setFPS(float fps);
 };
 
