Index: branches/avi_play/src/lib/graphics/importer/media_container.cc
===================================================================
--- branches/avi_play/src/lib/graphics/importer/media_container.cc	(revision 6350)
+++ branches/avi_play/src/lib/graphics/importer/media_container.cc	(revision 6353)
@@ -125,5 +125,5 @@
   buffer=new uint8_t[num_bytes];
 
-  // Assign appropriate parts of buffer to image planes in pFrameRGB
+  // Assign appropriate parts of buffer to image planes in RGB_frame
   avpicture_fill((AVPicture *)RGB_frame, buffer, PIX_FMT_RGB24, codec_context->width, codec_context->height);
 
@@ -155,6 +155,4 @@
 GLuint MediaContainer::getNextFrame()
 {
-  //if (glIsTexture(texture))
-  //  glDeleteTextures(1, &texture);
 
   // get next frame
@@ -189,4 +187,6 @@
                  ((AVPicture*)RGB_frame)->linesize[0], 
                   codec_context->width*sizeof(uint8_t)*3);
+
+        //avcodec_flush_buffers(codec_context); 
 
         surface = SDL_CreateRGBSurfaceFrom(data, codec_context->width,
@@ -228,5 +228,5 @@
                         GL_UNSIGNED_BYTE,
                         surface->pixels);
-        glBindTexture(GL_TEXTURE_2D, 0);
+        glBindTexture(GL_TEXTURE_2D, 0);      
         
         return texture;
@@ -235,5 +235,5 @@
       {
         av_free_packet(&packet);
-        this->getNextFrame();
+        return this->getNextFrame();
       }
     }
@@ -241,5 +241,5 @@
     {
       av_free_packet(&packet);
-      this->getNextFrame();
+      return this->getNextFrame();
     }
   }
Index: branches/avi_play/src/lib/graphics/importer/movie_player.cc
===================================================================
--- branches/avi_play/src/lib/graphics/importer/movie_player.cc	(revision 6350)
+++ branches/avi_play/src/lib/graphics/importer/movie_player.cc	(revision 6353)
@@ -18,5 +18,5 @@
 /* this is for debug output. It just says, that all calls to PRINT() belong to the DEBUG_MODULE_MEDIA module
    For more information refere to https://www.orxonox.net/cgi-bin/trac.cgi/wiki/DebugOutput
-*//*
+*/
 #define DEBUG_MODULE_MEDIA
 
@@ -29,18 +29,14 @@
 
 
-//
-// Default constructor
-//
 MoviePlayer::MoviePlayer(const char* filename)
 {
-  media_container = new MediaContainer(filename);
-
   this->init();
+
+  if (filename != NULL)
+    this->loadMovie(filename);
 }
 
 MoviePlayer::MoviePlayer()
 {
-  media_container = new MediaContainer();
-
   this->init();
 }
@@ -48,15 +44,36 @@
 MoviePlayer::~MoviePlayer()
 {
-  delete media_container;
+  delete material;
+  delete model;
+
+  if (glIsTexture(texture))
+    glDeleteTextures(1, &texture);
+  SDL_FreeSurface(surface);
+
+  // Free the RGB image
+  delete [] buffer;
+  av_free(RGB_frame);
+
+  // Free the frame
+  av_free(frame);
+
+  // Close the codec
+  avcodec_close(codec_context);
+
+  // Close the video file
+  av_close_input_file(format_context);
 }
 
 void MoviePlayer::init()
 {
+  // set the class id for the base object
+  this->setClassID(CL_MOVIE_PLAYER, "MoviePlayer");
+
   status = STOP;
   timer = 0;
+  frame_number = 0;
   speed = 1;
 
   material = new Material;
-
   material->setDiffuseMap("maps/radialTransparency.png");
 
@@ -71,10 +88,221 @@
 void MoviePlayer::loadMovie(const char* filename)
 {
-  media_container->loadMedia(filename);
-}
-
-void MoviePlayer::printInformation()
-{
-  media_container->printMediaInformation();
+  // register all formats and codecs
+  av_register_all();
+
+  // Open video file
+  if (av_open_input_file(&format_context, filename, NULL, 0, NULL) !=0 )
+    PRINTF(1)("Could not open %s\n", filename);
+
+  // Retrieve stream information
+  if (av_find_stream_info(format_context) < 0)
+    PRINTF(1)("Could not find stream information in %s\n", filename);
+
+  // Find the first video stream and take it
+  video_stream = -1;
+  for(int i = 0; i < format_context->nb_streams; i++)
+  {
+    // NOTE: different code for the 0.4.9-pre1 release of ffmpeg (tardis)
+    // if(format_context->streams[i]->codec.codec_type == CODEC_TYPE_VIDEO)
+    if(format_context->streams[i]->codec->codec_type == CODEC_TYPE_VIDEO)
+    {
+      video_stream = i;
+      break;
+    }
+  }
+
+  if(video_stream == -1)
+    PRINTF(1)("Could not find a video stream in %s\n", filename);
+
+  // Get a pointer to the codec context for the video stream
+  // NOTE: different code for the 0.4.9-pre1 release of ffmpeg (tardis)
+  // codec_context = &format_context->streams[video_stream]->codec;
+  codec_context = format_context->streams[video_stream]->codec;
+
+  // Find the decoder for the video stream
+  codec = avcodec_find_decoder(codec_context->codec_id);
+  if (codec == NULL)
+    PRINTF(1)("Could not find codec\n");
+
+  // Open codec
+  if (avcodec_open(codec_context, codec) < 0)
+    PRINTF(1)("Could not open codec\n");
+
+  // Allocate video frame
+  frame = avcodec_alloc_frame();
+  RGB_frame = avcodec_alloc_frame();
+
+  // Determine required buffer size and allocate buffer
+  num_bytes = avpicture_get_size(PIX_FMT_RGB24, codec_context->width, codec_context->height);
+  buffer=new uint8_t[num_bytes];
+
+  // Assign appropriate parts of buffer to image planes in RGB_frame
+  avpicture_fill((AVPicture *)RGB_frame, buffer, PIX_FMT_RGB24, codec_context->width, codec_context->height);
+
+  // Calculate fps
+  fps = av_q2d(format_context->streams[video_stream]->r_frame_rate);
+
+  // duration
+  duration = format_context->duration / 1000000LL;
+
+  // create texture
+  glGenTextures(1, &texture);
+  glBindTexture(GL_TEXTURE_2D, texture);
+  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
+  glTexImage2D(GL_TEXTURE_2D,
+              0,
+              GL_RGB,
+              0, 0,
+              0,
+              GL_RGB,
+              GL_UNSIGNED_BYTE,
+              NULL);
+  glBindTexture(GL_TEXTURE_2D, 0);
+}
+
+void MoviePlayer::getNextFrame()
+{
+  // get next frame
+  if(av_read_frame(format_context, &packet) >= 0)
+  {
+    // Is this a packet from the video stream?
+    if(packet.stream_index == video_stream)
+    {
+      int frame_finished;
+      // Decode video frame
+      avcodec_decode_video(codec_context, frame, &frame_finished,
+                           packet.data, packet.size);
+
+      // Free the packet that was allocated by av_read_frame
+      av_free_packet(&packet);
+      
+      // Did we get a video frame?
+      if(frame_finished)
+      {
+        frame_number++;
+        //PRINTF(0)("frame_number: %i\n", frame_number);
+        // Conversion from YUV to RGB
+        // Most codecs return images in YUV 420 format
+        // (one luminance and two chrominance channels, with the chrominance
+        // channels samples at half the spatial resolution of the luminance channel)
+        img_convert((AVPicture*)RGB_frame, PIX_FMT_RGB24, (AVPicture*)frame,
+                    codec_context->pix_fmt, codec_context->width, codec_context->height);
+
+        data = 0;
+        data = new uint8_t[codec_context->width*codec_context->height*3*sizeof(uint8_t)];
+        for(int i = 0; i < codec_context->height; i++)
+          memcpy(&data[i*codec_context->width*3], ((AVPicture*)RGB_frame)->data[0]+i *
+                 ((AVPicture*)RGB_frame)->linesize[0],
+                 codec_context->width*sizeof(uint8_t)*3);
+
+//avcodec_flush_buffers(codec_context);
+
+        surface = SDL_CreateRGBSurfaceFrom(data, codec_context->width,
+                                           codec_context->height,24,
+                                           codec_context->width*sizeof(uint8_t)*3,
+#if SDL_BYTEORDER == SDL_LIL_ENDIAN // OpenGL RGBA masks
+                                           0x000000FF,
+                                           0x0000FF00,
+                                           0x00FF0000,
+                                           0
+#else
+                                           0xFF000000,
+                                           0x00FF0000,
+                                           0x0000FF00,
+                                           0
+#endif
+                                            );
+
+        glBindTexture(GL_TEXTURE_2D, texture);
+        // update the texture
+        glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0,
+                          surface->w, surface->h,
+                          GL_RGB, GL_UNSIGNED_BYTE,
+                          surface->pixels);
+        // build the MipMaps
+        gluBuild2DMipmaps(GL_TEXTURE_2D,
+                        GL_RGB,
+                        surface->w,
+                        surface->h,
+                        GL_RGB,
+                        GL_UNSIGNED_BYTE,
+                        surface->pixels);
+        glBindTexture(GL_TEXTURE_2D, 0);
+      }
+      else
+      {
+        av_free_packet(&packet);
+        this->getNextFrame();
+      }
+    }
+    else
+    {
+      av_free_packet(&packet);
+      this->getNextFrame();
+    }
+  }
+  else
+    this->stop();
+}
+
+void MoviePlayer::skipFrame(int frames)
+{
+  
+  while(frames != 0)
+  {
+    if(av_read_frame(format_context, &packet) < 0)
+      break;
+    if(packet.stream_index == video_stream)
+    {
+      int frame_finished;
+      // We have to decode the frame to not get ugly fragments
+      avcodec_decode_video(codec_context, frame, &frame_finished,
+                            packet.data, packet.size);
+        
+      // Did we get a video frame?
+      if(frame_finished)
+      {
+        frames--;
+        frame_number++;
+      }
+    }
+    av_free_packet(&packet);
+  }
+  
+  this->getNextFrame();
+
+}
+
+void MoviePlayer::gotoFrame(int frames)
+{
+  // seek doesnt work for the first two frames
+  // you will get ugly fragments
+  if(frames < 2)
+  {
+    // go to the begin of the video
+    av_seek_frame(format_context, video_stream, 0, AVSEEK_FLAG_BACKWARD);
+    frame_number = 0;
+  }
+  else
+  {
+    // seeks to the nearest keyframe
+    // NOTE: there is only about every 5s a keyframe!
+    av_seek_frame(format_context, video_stream, frames, AVSEEK_FLAG_BACKWARD);
+    
+    // go from the keyframe to the exact position
+    codec_context->hurry_up = 1;
+    do {
+      av_read_frame(format_context, &packet);
+      if(packet.pts >= frames-1)
+        break;
+      int frame_finished;
+      avcodec_decode_video(codec_context, frame, &frame_finished, packet.data, packet.size);
+      av_free_packet(&packet);
+    } while(1);
+    codec_context->hurry_up = 0;
+  
+    frame_number = frames;
+  }
 }
 
@@ -83,9 +311,8 @@
   status = PLAY;
   timer = 0;
-  fps = media_container->getFPS();
-
-  media_container->gotoFrame(start_time * fps);
-
-   PRINTF(0)("start (start_time: %0.2f)\n", start_time * fps);
+
+  this->gotoFrame(start_time * fps);
+
+   PRINTF(0)("start\n");
 }
 
@@ -111,5 +338,4 @@
 {
   status = STOP;
-  texture = NULL;
 
   PRINTF(0)("stop\n");
@@ -120,19 +346,15 @@
   if(status == PLAY)
   {
-    current_frame = media_container->getFrameNumber();
     timer += dt;
     actual_frame = timer * fps * speed;
 
-    if(actual_frame != current_frame)
+    if(actual_frame != frame_number)
     {
-      if(actual_frame - current_frame == 1)
-        texture = media_container->getNextFrame();
+      if(actual_frame - frame_number == 1)
+        this->getNextFrame();
       else
-        texture = media_container->skipFrame(actual_frame - current_frame - 1);
+        this->skipFrame(actual_frame - frame_number - 1);
     }   
-    //PRINTF(0)("frame_number: %i\n", media_container->getFrameNumber());
-
-    if(texture == NULL && current_frame != 0)
-      this->stop();
+    //PRINTF(0)("frame_number: %i\n", frame_number);
   }
 }
@@ -162,3 +384,34 @@
   return this->status;
 }
-*/
+
+void MoviePlayer::printInformation()
+{
+  PRINTF(0)("========================\n");
+  PRINTF(0)("========================\n");
+  PRINTF(0)("=    MEDIACONTAINER    =\n");
+  PRINTF(0)("========================\n");
+  PRINTF(0)("========================\n");
+  PRINTF(0)("=    AVFormatContext   =\n");
+  PRINTF(0)("========================\n");
+  PRINTF(0)("filename: %s\n", format_context->filename);
+  PRINTF(0)("nb_streams: %i\n", format_context->nb_streams);
+  PRINTF(0)("duration: (%02d:%02d:%02d)\n", duration/3600, (duration%3600)/60, duration%60);
+  PRINTF(0)("file_size: %ikb\n", format_context->file_size/1024);
+  PRINTF(0)("bit_rate: %ikb/s\n", format_context->bit_rate/1000);
+  PRINTF(0)("nb_frames: %i\n", format_context->streams[video_stream]->nb_frames);
+  PRINTF(0)("r_frame_rate: %i\n", format_context->streams[video_stream]->r_frame_rate.num);
+  PRINTF(0)("fps: %0.2f\n", av_q2d(format_context->streams[video_stream]->r_frame_rate));
+  PRINTF(0)("========================\n");
+  PRINTF(0)("=    AVCodecContext    =\n");
+  PRINTF(0)("========================\n");
+  PRINTF(0)("width: %i\n", codec_context->width);
+  PRINTF(0)("height: %i\n", codec_context->height);
+  PRINTF(0)("time_base.den: %i\n", codec_context->time_base.den);
+  PRINTF(0)("time_base.num: %i\n", codec_context->time_base.num);
+  PRINTF(0)("========================\n");
+  PRINTF(0)("=       AVCodec        =\n");
+  PRINTF(0)("========================\n");
+  PRINTF(0)("codec name: %s\n", codec->name);
+  PRINTF(0)("========================\n");
+  PRINTF(0)("========================\n");
+}
Index: branches/avi_play/src/lib/graphics/importer/movie_player.h
===================================================================
--- branches/avi_play/src/lib/graphics/importer/movie_player.h	(revision 6350)
+++ branches/avi_play/src/lib/graphics/importer/movie_player.h	(revision 6353)
@@ -4,12 +4,18 @@
 
 */
-/*
+
 #ifndef _MOVIE_PLAYER
 #define _MOVIE_PLAYER
 
+#include <SDL.h>
+
+#ifdef HAVE_AVFORMAT_H
+  #include <avformat.h>
+#else
+  #include <ffmpeg/avformat.h>
+#endif
+
 #include "glincl.h"
-//#include "sdlincl.h"
 
-#include "media_container.h"
 #include "light.h"
 #include "texture.h"
@@ -32,9 +38,20 @@
 private:
 
-  MediaContainer* media_container;
   Model* model;
   Material* material;
 
+  AVFormatContext* format_context;
+  AVCodecContext* codec_context;
+  AVCodec* codec;
+  AVFrame* frame;
+  AVPacket packet;
+  AVFrame* RGB_frame;
+
+  SDL_Surface* surface;
   GLuint texture;
+  uint8_t* data;
+  uint8_t* buffer;
+  int num_bytes;
+  int video_stream;
 
   MP_STATUS status;	
@@ -42,6 +59,7 @@
   float timer;
   int actual_frame;
-  int current_frame;
-  float fps;  
+  int frame_number;
+  float fps;
+  int duration;  
 
 public:
@@ -51,5 +69,4 @@
   ~MoviePlayer();
 
-  void init();
   void loadMovie(const char* filename);
 
@@ -67,4 +84,11 @@
   void printInformation();
 
+private:
+  
+  void init();
+  void getNextFrame();
+  void skipFrame(int frames);
+  void gotoFrame(int frame);
+
 };
 
@@ -72,3 +96,2 @@
 
 #endif // _MOVIE_PLAYER
-*/
