Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 6681 in orxonox.OLD for branches/avi_play


Ignore:
Timestamp:
Jan 24, 2006, 11:15:16 PM (19 years ago)
Author:
hdavid
Message:

branches/avi_play: RGB→YUV faster

Location:
branches/avi_play/src/world_entities
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/avi_play/src/world_entities/recorder.cc

    r6663 r6681  
    3333  av_register_all();
    3434
     35  // Default values
     36  stream_duration = 10;
     37  stream_frame_rate = 20;
     38
    3539  this->loadParams(root);
    3640
     
    4953  WorldEntity::loadParams(root);
    5054
     55  LoadParam(root, "duration", this, Recorder, setStreamDuration);
     56  LoadParam(root, "fps", this, Recorder, setFPS);
    5157  LoadParam(root, "name", this, Recorder, initVideo);
    5258}
    5359
    5460
     61void Recorder::setStreamDuration(float duration)
     62{
     63  this->stream_duration = duration;
     64}
     65
     66
     67void Recorder::setFPS(float fps)
     68{
     69  this->stream_frame_rate = fps;
     70}
     71
     72
    5573void Recorder::initVideo(const char* filename)
    5674{
    5775  frame_count = 0;
    58   time = 0; 
     76  time = 0;
     77  stream_nb_frames = (int)(stream_duration * stream_frame_rate);
    5978
    6079  // auto detect the output format from the name, default is mpeg
     
    172191  avpicture_fill((AVPicture *)picture, picture_buf,
    173192                  codec_context->pix_fmt, width, height);
     193
     194
     195
     196  RGB_frame = avcodec_alloc_frame();
     197
     198  // Determine required buffer size and allocate buffer
     199  size = avpicture_get_size(PIX_FMT_RGB24, width, height);
     200  picture_buf = new uint8_t[size];
     201
     202  // Assign appropriate parts of buffer to image planes in RGB_frame
     203  avpicture_fill((AVPicture *)RGB_frame, picture_buf, PIX_FMT_RGB24, width, height);
    174204}
    175205
     
    199229  // timebase should be 1/framerate and timestamp increments should be
    200230  // identically 1
    201   codec_context->time_base.den = STREAM_FRAME_RATE
     231  codec_context->time_base.den = (int)stream_frame_rate
    202232  codec_context->time_base.num = 1;
    203233  codec_context->gop_size = 12;  // emit one intra frame every twelve frames at most
    204   codec_context->pix_fmt = STREAM_PIX_FMT;
     234  codec_context->pix_fmt = PIX_FMT_YUV420P;
    205235
    206236  if (codec_context->codec_id == CODEC_ID_MPEG1VIDEO)
     
    221251{
    222252  time += dt;
    223   if(time < 1/STREAM_FRAME_RATE)
     253  if(time < 1/stream_frame_rate)
    224254    return;
    225255  else
     
    232262      video_pts = 0.0;
    233263
    234   if (!video_stream || video_pts >= STREAM_DURATION)
     264  if (!video_stream || video_pts >= stream_duration)
    235265  {
    236266    this->toList(OM_DEAD);
     
    248278  codec_context = video_stream->codec;
    249279 
    250   if(frame_count >= STREAM_NB_FRAMES)
     280  if(frame_count >= stream_nb_frames)
    251281  {
    252282    /* no more frame to compress. The codec has a latency of a few
     
    315345  glReadPixels(0, 0, width, height, GL_RGB, GL_UNSIGNED_BYTE, outputImage);
    316346
    317   /*
    318   RGB to YUV Conversion
    319  
    320   Y  =      (0.257 * R) + (0.504 * G) + (0.098 * B) + 16
    321  
    322   Cr = V =  (0.439 * R) - (0.368 * G) - (0.071 * B) + 128
    323  
    324   Cb = U = -(0.148 * R) - (0.291 * G) + (0.439 * B) + 128
    325   */
    326 
    327   // Conversion RGB -> YUV 420
    328   // not right yet
    329 
    330   // Y
    331   int i = 0, x, y;
    332   for(y=height-1;y>=0;y--)
    333   {
    334     for(x=0;x<width;x++)
     347  int i = 0;
     348  for(int y=height-1;y>=0;y--)
     349  {
     350    for(int x=0;x<width*3;x++)
    335351    {
    336       picture->data[0][y*width+x] = (0.257 * outputImage[i]) + (0.504 * outputImage[i+1]) + (0.098 * outputImage[i+2]) + 16;
    337       i += 3;
     352      RGB_frame->data[0][y*width*3+x] = outputImage[i];
     353      i++;
    338354    }
    339355  }
    340   i=0;
    341 
    342   // Cb and Cr
    343   for(y=height/2-1;y>=0;y--)
    344   {
    345     for(x=0;x<width/2;x++)
    346     {
    347       picture->data[1][y*width/2+x] = -(0.148 * outputImage[i]) - (0.291 * outputImage[i+1]) + (0.439 * outputImage[i+2]) + 128;
    348       picture->data[2][y*width/2+x] = (0.439 * outputImage[i]) - (0.368 * outputImage[i+1]) - (0.071 * outputImage[i+2]) + 128;
    349       i+=6;
    350 
    351       if(x+1 == width/2)
    352         i+=3*width;
    353     }
    354   }
     356
     357
     358  img_convert((AVPicture*)picture, PIX_FMT_YUV420P, (AVPicture*)RGB_frame,
     359              PIX_FMT_RGB24, width, height);
    355360
    356361  // Clear the allocated memory.
  • branches/avi_play/src/world_entities/recorder.h

    r6663 r6681  
    66#ifndef _RECORDER_H
    77#define _RECORDER_H
    8 
    9 #define STREAM_DURATION   40.0
    10 #define STREAM_FRAME_RATE 20
    11 #define STREAM_NB_FRAMES  ((int)(STREAM_DURATION * STREAM_FRAME_RATE))
    12 #define STREAM_PIX_FMT PIX_FMT_YUV420P
    13 
    148
    159#include <SDL.h>
     
    4741    float time;
    4842
     43    float stream_duration;
     44    float stream_frame_rate;
     45    int stream_nb_frames;
     46
     47AVFrame* RGB_frame;
    4948  public:
    5049    Recorder (const TiXmlElement* root = NULL);
     
    6463    void writeVideoFrame();
    6564    void fillYuvImage();
     65
     66    void setStreamDuration(float duration);
     67    void setFPS(float fps);
    6668};
    6769
Note: See TracChangeset for help on using the changeset viewer.