Changeset 6681 in orxonox.OLD for branches/avi_play/src
- Timestamp:
- Jan 24, 2006, 11:15:16 PM (19 years ago)
- Location:
- branches/avi_play/src/world_entities
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/avi_play/src/world_entities/recorder.cc
r6663 r6681 33 33 av_register_all(); 34 34 35 // Default values 36 stream_duration = 10; 37 stream_frame_rate = 20; 38 35 39 this->loadParams(root); 36 40 … … 49 53 WorldEntity::loadParams(root); 50 54 55 LoadParam(root, "duration", this, Recorder, setStreamDuration); 56 LoadParam(root, "fps", this, Recorder, setFPS); 51 57 LoadParam(root, "name", this, Recorder, initVideo); 52 58 } 53 59 54 60 61 void Recorder::setStreamDuration(float duration) 62 { 63 this->stream_duration = duration; 64 } 65 66 67 void Recorder::setFPS(float fps) 68 { 69 this->stream_frame_rate = fps; 70 } 71 72 55 73 void Recorder::initVideo(const char* filename) 56 74 { 57 75 frame_count = 0; 58 time = 0; 76 time = 0; 77 stream_nb_frames = (int)(stream_duration * stream_frame_rate); 59 78 60 79 // auto detect the output format from the name, default is mpeg … … 172 191 avpicture_fill((AVPicture *)picture, picture_buf, 173 192 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); 174 204 } 175 205 … … 199 229 // timebase should be 1/framerate and timestamp increments should be 200 230 // identically 1 201 codec_context->time_base.den = STREAM_FRAME_RATE;231 codec_context->time_base.den = (int)stream_frame_rate; 202 232 codec_context->time_base.num = 1; 203 233 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; 205 235 206 236 if (codec_context->codec_id == CODEC_ID_MPEG1VIDEO) … … 221 251 { 222 252 time += dt; 223 if(time < 1/ STREAM_FRAME_RATE)253 if(time < 1/stream_frame_rate) 224 254 return; 225 255 else … … 232 262 video_pts = 0.0; 233 263 234 if (!video_stream || video_pts >= STREAM_DURATION)264 if (!video_stream || video_pts >= stream_duration) 235 265 { 236 266 this->toList(OM_DEAD); … … 248 278 codec_context = video_stream->codec; 249 279 250 if(frame_count >= STREAM_NB_FRAMES)280 if(frame_count >= stream_nb_frames) 251 281 { 252 282 /* no more frame to compress. The codec has a latency of a few … … 315 345 glReadPixels(0, 0, width, height, GL_RGB, GL_UNSIGNED_BYTE, outputImage); 316 346 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++) 335 351 { 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++; 338 354 } 339 355 } 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); 355 360 356 361 // Clear the allocated memory. -
branches/avi_play/src/world_entities/recorder.h
r6663 r6681 6 6 #ifndef _RECORDER_H 7 7 #define _RECORDER_H 8 9 #define STREAM_DURATION 40.010 #define STREAM_FRAME_RATE 2011 #define STREAM_NB_FRAMES ((int)(STREAM_DURATION * STREAM_FRAME_RATE))12 #define STREAM_PIX_FMT PIX_FMT_YUV420P13 14 8 15 9 #include <SDL.h> … … 47 41 float time; 48 42 43 float stream_duration; 44 float stream_frame_rate; 45 int stream_nb_frames; 46 47 AVFrame* RGB_frame; 49 48 public: 50 49 Recorder (const TiXmlElement* root = NULL); … … 64 63 void writeVideoFrame(); 65 64 void fillYuvImage(); 65 66 void setStreamDuration(float duration); 67 void setFPS(float fps); 66 68 }; 67 69
Note: See TracChangeset
for help on using the changeset viewer.