Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 6260 in orxonox.OLD for branches/avi_play/src


Ignore:
Timestamp:
Dec 22, 2005, 5:08:39 PM (19 years ago)
Author:
hdavid
Message:

branches\avi_play: MediaContainer::getFrame(int frame_number) works

Location:
branches/avi_play/src
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/avi_play/src/lib/graphics/importer/media_container.cc

    r6254 r6260  
    7575}
    7676
    77 SDL_Surface* MediaContainer::getFrame(float time_stamp)
    78 {
    79   if (time_stamp != AV_NOPTS_VALUE)
     77SDL_Surface* MediaContainer::getFrame(int frame_number)
     78{
     79  // seek doesnt work for the first two frames
     80  // you will get ugly fragments
     81  if(frame_number < 2)
     82    return this->getNextFrame();
     83  else
    8084  {
    81     /* add the stream start time */
    82     //time_stamp += AV_NOPTS_VALUE;
    83     //PRINTF(1)("starttime %f\n", format_context->start_time);
    84     //time_stamp += format_context->start_time;
    85     int err = av_seek_frame(format_context, video_stream, time_stamp, AVSEEK_FLAG_BACKWARD);
    86     if (err < 0)
    87     {
    88       PRINTF(1)("could not seek to position %f\n", time_stamp);
    89       return NULL;
    90     }
    91 
     85    // seeks to the nearest keyframe
     86    // NOTE: there is only about every 5s a keyframe!
     87    av_seek_frame(format_context, video_stream, frame_number, AVSEEK_FLAG_BACKWARD);
     88   
     89    // go from the keyframe to the exact position
     90    codec_context->hurry_up = 1;
     91    do {
     92      av_read_frame(format_context, &packet);
     93      if(packet.pts >= frame_number-1)
     94        break;
     95      int frame_finished;
     96      avcodec_decode_video(codec_context, frame, &frame_finished, packet.data, packet.size);
     97      av_free_packet(&packet);
     98    } while(1);
     99    codec_context->hurry_up = 0;
     100 
    92101    return this->getNextFrame();
    93102  }
    94 
    95   return this->getNextFrame();
    96103}
    97104
     
    114121      if(frame_finished)
    115122      {
    116         //PRINTF(1)("frame_number: %i\n", this->getFrameNumber());
     123        PRINTF(1)("frame_number: %i\n", this->getFrameNumber());
    117124        // Conversion from YUV to RGB
    118125        // Most codecs return images in YUV 420 format
     
    128135        data = new uint8_t[codec_context->width*codec_context->height*3*sizeof(uint8_t)];
    129136        for(int i = 0; i < codec_context->height; i++)
    130           memcpy(&data[i*codec_context->width*3], picture->data[0]+i * picture->linesize[0],codec_context->width*sizeof(uint8_t)*3);
     137          memcpy(&data[i*codec_context->width*3], picture->data[0]+i *
     138                 picture->linesize[0],codec_context->width*sizeof(uint8_t)*3);
    131139
    132140        surface = SDL_CreateRGBSurfaceFrom(data, codec_context->width,
     
    285293  PRINTF(1)("nb_frames: %i\n", format_context->streams[video_stream]->nb_frames);
    286294  PRINTF(1)("r_frame_rate: %i\n", format_context->streams[video_stream]->r_frame_rate.num);
    287   PRINTF(1)("FPS: %f\n", av_q2d(format_context->streams[video_stream]->r_frame_rate));
     295  PRINTF(1)("fps: %0.2f\n", av_q2d(format_context->streams[video_stream]->r_frame_rate));
    288296  PRINTF(1)("========================\n");
    289297  PRINTF(1)("=    AVCodecContext    =\n");
  • branches/avi_play/src/lib/graphics/importer/media_container.h

    r6254 r6260  
    5252  ~MediaContainer();
    5353
    54   SDL_Surface* getFrame(float time_stamp);
     54  SDL_Surface* getFrame(int frame_number);
    5555  SDL_Surface* getNextFrame();
    5656  vector<SDL_Surface*> getFrameList();
  • branches/avi_play/src/subprojects/importer/multitex.cc

    r6254 r6260  
    5454  fps = movie->getFPS();
    5555
    56   float start_time = atoi(argv[2]);
     56  int start_time = atoi(argv[2]);
    5757
    5858  // print information about the media file
Note: See TracChangeset for help on using the changeset viewer.