Index: branches/avi_play/src/lib/graphics/importer/media_container.cc
===================================================================
--- branches/avi_play/src/lib/graphics/importer/media_container.cc	(revision 6057)
+++ branches/avi_play/src/lib/graphics/importer/media_container.cc	(revision 6068)
@@ -41,6 +41,4 @@
 
   current_frame = 0;
-  num_frames = 0;
-	frames_left = true;
 
   if (filename != NULL)
@@ -54,4 +52,7 @@
 MediaContainer::~MediaContainer()
 {
+  // Free the RGB image
+  delete [] buffer;
+  av_free(RGB_frame);
 
   /* Free the frame */
@@ -66,5 +67,5 @@
 }
 
-/*GLuint MediaContainer::getFrame(int frame_number)
+GLuint MediaContainer::getFrame(int frame_number)
 {
 
@@ -73,32 +74,66 @@
 GLuint MediaContainer::getNextFrame()
 {
-
-}*/
-
-SDL_Surface* MediaContainer::getFrame(int frame_number)
-{
-
-}
-
-SDL_Surface* MediaContainer::getNextFrame()
-{
-	/* get next frame */
-	if(av_read_frame(format_context, &packet) >= 0)
-	{
-		frames_left = true;
-		current_frame++;
-		PRINTF(1)("current_frame: %i\n", current_frame);
-
-
-		/* work with the frame */
-		/* packet -> SDL_Surface */
-
-
-
-
-	}
-	else
-		frames_left = false;
-
+  /* get next frame */
+  if(av_read_frame(format_context, &packet) >= 0)
+  {
+    //this->printPacketInformation();
+
+    /* 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);
+
+      // Did we get a video frame?
+      if(frame_finished)
+      {
+        current_frame++;
+        PRINTF(1)("current_frame: %i\n", current_frame);
+
+        // Convert the image from its native format to RGB
+        img_convert((AVPicture*)RGB_frame, PIX_FMT_RGB24, (AVPicture*)frame, codec_context->pix_fmt,
+					codec_context->width, codec_context->height);
+			
+        // save frame
+        this->saveCurrentFrame();
+
+
+        /* RGB_picture -> texture */
+
+
+        return texture;
+      }
+    }
+    // Free the packet that was allocated by av_read_frame
+    av_free_packet(&packet);
+  }
+  else
+    return NULL;
+}
+
+void MediaContainer::saveCurrentFrame()
+{
+  FILE *file;
+  char filename[32];
+  int  y;
+
+  picture = (AVPicture*)RGB_frame;
+
+  // Open file
+  sprintf(filename, "frame%i.ppm", current_frame);
+  file = fopen(filename, "wb");
+  if(file == NULL)
+  	return;
+
+  // Write header
+  fprintf(file, "P6\n%d %d\n255\n", codec_context->width, codec_context->height);
+  // Write pixel data
+  for(y = 0; y < codec_context->height; y++)
+    fwrite(picture->data[0]+y * picture->linesize[0], 1, codec_context->width*3, file);
+  // Close file
+  fclose(file);
+
+  PRINTF(1)("created file: %s\n", filename);
 }
 
@@ -144,5 +179,16 @@
   /* Open codec */
   if (avcodec_open(codec_context, codec) < 0)
-    PRINTF(1)("Could not open codec\n");	
+    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 pFrameRGB
+  avpicture_fill((AVPicture *)RGB_frame, buffer, PIX_FMT_RGB24, codec_context->width, codec_context->height);	
 
 }
@@ -150,10 +196,10 @@
 int MediaContainer::getHeight()
 {
-	return codec_context->height;
+  return codec_context->height;
 }
 
 int MediaContainer::getWidth()
 {
-	return codec_context->width;
+  return codec_context->width;
 }
 
@@ -168,35 +214,46 @@
 }
 
-bool MediaContainer::framesLeft()
-{
-	return frames_left;
-}
-
 void MediaContainer::printMediaInformation()
 {
-	PRINTF(1)("========================\n");
-	PRINTF(1)("========================\n");
-	PRINTF(1)("=    MEDIACONTAINER    =\n");
-	PRINTF(1)("========================\n");
-	PRINTF(1)("========================\n");
-	PRINTF(1)("=    AVFormatContext   =\n");
-	PRINTF(1)("========================\n");
-	PRINTF(1)("filename: %s\n", format_context->filename);
-	PRINTF(1)("nb_streams: %i\n", format_context->nb_streams);
-	PRINTF(1)("duration: %fs\n", format_context->duration/1000000.);
-	PRINTF(1)("file_size: %ikb\n", format_context->file_size/1024);
-	PRINTF(1)("bit_rate: %ikb/s\n", format_context->bit_rate/1000);
-	PRINTF(1)("nb_frames: %i\n", format_context->streams[video_stream]->nb_frames);
-	//PRINTF(1)("r_frame_rate: %ifps\n", format_context->streams[video_stream]->r_frame_rate.num);
-	PRINTF(1)("========================\n");
-	PRINTF(1)("=    AVCodecContext    =\n");
-	PRINTF(1)("========================\n");
-	PRINTF(1)("width: %i\n", codec_context->width);
-	PRINTF(1)("height: %i\n", codec_context->height);
-	PRINTF(1)("========================\n");
-	PRINTF(1)("=       AVCodec        =\n");
-	PRINTF(1)("========================\n");
-	PRINTF(1)("codec name: %s\n", codec->name);
-	PRINTF(1)("========================\n");
-	PRINTF(1)("========================\n");
-}
+  PRINTF(1)("========================\n");
+  PRINTF(1)("========================\n");
+  PRINTF(1)("=    MEDIACONTAINER    =\n");
+  PRINTF(1)("========================\n");
+  PRINTF(1)("========================\n");
+  PRINTF(1)("=    AVFormatContext   =\n");
+  PRINTF(1)("========================\n");
+  PRINTF(1)("filename: %s\n", format_context->filename);
+  PRINTF(1)("nb_streams: %i\n", format_context->nb_streams);
+  PRINTF(1)("duration: %fs\n", format_context->duration/1000000.);
+  PRINTF(1)("file_size: %ikb\n", format_context->file_size/1024);
+  PRINTF(1)("bit_rate: %ikb/s\n", format_context->bit_rate/1000);
+  PRINTF(1)("nb_frames: %i\n", format_context->streams[video_stream]->nb_frames);
+  PRINTF(1)("r_frame_rate: %i\n", format_context->streams[video_stream]->r_frame_rate.num);
+  PRINTF(1)("========================\n");
+  PRINTF(1)("=    AVCodecContext    =\n");
+  PRINTF(1)("========================\n");
+  PRINTF(1)("width: %i\n", codec_context->width);
+  PRINTF(1)("height: %i\n", codec_context->height);
+  PRINTF(1)("========================\n");
+  PRINTF(1)("=       AVCodec        =\n");
+  PRINTF(1)("========================\n");
+  PRINTF(1)("codec name: %s\n", codec->name);
+  PRINTF(1)("========================\n");
+  PRINTF(1)("========================\n");
+}
+
+void MediaContainer::printPacketInformation()
+{
+  PRINTF(1)("========================\n");
+  PRINTF(1)("========================\n");
+  PRINTF(1)("=       AVPacket       =\n");
+  PRINTF(1)("========================\n");
+  PRINTF(1)("pts: %i\n", packet.pts);
+  PRINTF(1)("dts: %i\n", packet.dts);
+  PRINTF(1)("size: %i\n", packet.size);
+  PRINTF(1)("stream_index: %i\n", packet.stream_index);
+  PRINTF(1)("duration: %i\n", packet.duration);
+  PRINTF(1)("pos: %i\n", packet.pos);
+  PRINTF(1)("========================\n");
+  PRINTF(1)("========================\n");
+}
Index: branches/avi_play/src/lib/graphics/importer/media_container.h
===================================================================
--- branches/avi_play/src/lib/graphics/importer/media_container.h	(revision 6057)
+++ branches/avi_play/src/lib/graphics/importer/media_container.h	(revision 6068)
@@ -24,7 +24,4 @@
 using namespace std;
 
-/* Forward Declaration */
-struct SDL_Surface;
-
 class MediaContainer : public BaseObject
 {
@@ -32,16 +29,19 @@
 private:
 
-	int current_frame;
-	int num_frames;
+  int current_frame;
+  int num_frames;
+  GLuint texture;
 
-	AVFormatContext* format_context;
-	AVCodecContext* codec_context;
-	AVCodec* codec;
-	AVFrame* frame;
-	AVPacket packet;
+  AVFormatContext* format_context;
+  AVCodecContext* codec_context;
+  AVCodec* codec;
+  AVFrame* frame;
+  AVPacket packet;
+  AVPicture* picture;
+  AVFrame* RGB_frame;
 	
-	int num_bytes;
-	int video_stream;
-	bool frames_left;
+  int num_bytes;
+  uint8_t *buffer;
+  int video_stream;
 
 public:
@@ -50,20 +50,18 @@
   ~MediaContainer();
 
-	//GLuint getFrame(int frame_number);
-	SDL_Surface* getFrame(int frame_number);
-	//GLuint getNextFrame();
-	SDL_Surface* getNextFrame();
-	void loadMedia(const char* filename);
+  GLuint getFrame(int frame_number);
+  GLuint getNextFrame();
+  void loadMedia(const char* filename);
 	
-	int getHeight();
-	int getWidth();
-	int getFrameRate();
-	void getStream(/* stream */);
+  int getHeight();
+  int getWidth();
+  int getFrameRate();
+  void getStream(/* stream */);
 
-	bool framesLeft();
-
-	/* prints some information about the
-	   media file for debug reasons */
-	void printMediaInformation();
+  /* prints some information about the
+     media file for debug reasons */
+  void printMediaInformation();
+  void printPacketInformation();
+  void saveCurrentFrame();
 
 };
Index: branches/avi_play/src/subprojects/importer/importer.cc
===================================================================
--- branches/avi_play/src/subprojects/importer/importer.cc	(revision 6057)
+++ branches/avi_play/src/subprojects/importer/importer.cc	(revision 6068)
@@ -35,30 +35,12 @@
   movie = new MediaContainer(argv[1]);
 
-	// print information about the media file
-	movie->printMediaInformation();	
+  // print information about the media file
+  movie->printMediaInformation();
 
-/*
-  ResourceManager::getInstance()->addImageDir("./");
+  SDL_Delay(1000);
 
-  for (int i = 0; i < argc; i++)
-  {
-    printf("%s\n", argv[i]);
-  }
-  ResourceManager::getInstance()->addImageDir("");
+  // get the frame and save it as an image
+  //while(movie->getNextFrame() != NULL);	
 
-
-  if (argc>=3)
-    obj = new OBJModel (argv[1], atof(argv[2]));
-  else if (argc>=2)
-    obj = new OBJModel(argv[1]);
-  else
-    obj = new PrimitiveModel(PRIM_CYLINDER);
-
-  ResourceManager::getInstance()->debug();
-
-  LightManager* lightMan = LightManager::getInstance();
-  lightMan->setAmbientColor(.1,.1,.1);
-  (new Light())->setAbsCoor(5.0, 10.0, 40.0);
-  (new Light())->setAbsCoor(-10, -20, -100);*/
 }
 
@@ -78,13 +60,10 @@
 void Framework::moduleTick(float dt)
 {
-	if(movie->framesLeft())
-		movie->getNextFrame();
+  while(movie->getNextFrame() != NULL);	
 }
 
 void Framework::moduleDraw(void) const
 {
-  //obj->draw();
 
-  //LightManager::getInstance()->draw();
 }
 
Index: branches/avi_play/src/subprojects/importer/multitex.cc
===================================================================
--- branches/avi_play/src/subprojects/importer/multitex.cc	(revision 6057)
+++ branches/avi_play/src/subprojects/importer/multitex.cc	(revision 6068)
@@ -76,5 +76,5 @@
           obj = new PrimitiveModel(PRIM_CUBE, 10.0);
           break;
-	case SDLK_2:
+        case SDLK_2:
           obj = new PrimitiveModel(PRIM_SPHERE, 10.0);
           break;
