Changeset 7216 in orxonox.OLD for branches/std/src/world_entities/recorder.cc
- Timestamp:
- Mar 12, 2006, 8:54:30 AM (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/std/src/world_entities/recorder.cc
r7193 r7216 54 54 55 55 LoadParam(root, "duration", this, Recorder, setStreamDuration); 56 56 57 LoadParam(root, "fps", this, Recorder, setFPS); 58 57 59 LoadParam(root, "name", this, Recorder, initVideo); 58 60 } … … 71 73 72 74 73 void Recorder::initVideo(const char*filename)75 void Recorder::initVideo(const std::string& filename) 74 76 { 75 77 frame_count = 0; … … 78 80 79 81 // auto detect the output format from the name, default is mpeg 80 output_format = guess_format(NULL, filename , NULL);82 output_format = guess_format(NULL, filename.c_str(), NULL); 81 83 if (!output_format) 82 84 { … … 93 95 94 96 format_context->oformat = output_format; 95 snprintf(format_context->filename, sizeof(format_context->filename), "%s", filename );97 snprintf(format_context->filename, sizeof(format_context->filename), "%s", filename.c_str()); 96 98 97 99 // add video stream using the default format codec and initialize the codec … … 104 106 105 107 // print some information 106 dump_format(format_context, 0, filename , 1);108 dump_format(format_context, 0, filename.c_str(), 1); 107 109 108 110 // now that all the parameters are set, we can open the … … 110 112 if(video_stream) 111 113 this->openVideo(); 112 114 113 115 // open the output file, if needed 114 116 if(!(output_format->flags & AVFMT_NOFILE)) 115 117 { 116 if(url_fopen(&format_context->pb, filename , URL_WRONLY) < 0)117 PRINTF(1)("Could not open %s\n", filename );118 if(url_fopen(&format_context->pb, filename.c_str(), URL_WRONLY) < 0) 119 PRINTF(1)("Could not open %s\n", filename.c_str()); 118 120 } 119 121 120 122 // write the stream header, if any 121 av_write_header(format_context); 123 av_write_header(format_context); 122 124 } 123 125 … … 129 131 av_free(buffer); 130 132 131 // write the trailer, if any 133 // write the trailer, if any 132 134 av_write_trailer(format_context); 133 135 134 136 // free the streams 135 137 for(int i = 0; i < format_context->nb_streams; i++) … … 175 177 176 178 void Recorder::allocPicture() 177 { 179 { 178 180 picture = avcodec_alloc_frame(); 179 181 if(!picture) … … 189 191 return; 190 192 } 191 avpicture_fill((AVPicture *)picture, picture_buf, 193 avpicture_fill((AVPicture *)picture, picture_buf, 192 194 codec_context->pix_fmt, width, height); 193 195 … … 211 213 if (!video_stream) 212 214 PRINTF(1)("Could not alloc stream\n"); 213 215 214 216 codec_context = video_stream->codec; 215 217 codec_context->codec_id = output_format->video_codec; … … 219 221 codec_context->bit_rate = 400000; 220 222 // resolution must be a multiple of two 221 codec_context->width = State::getResX(); 223 codec_context->width = State::getResX(); 222 224 codec_context->height = State::getResY(); 223 225 … … 229 231 // timebase should be 1/framerate and timestamp increments should be 230 232 // identically 1 231 codec_context->time_base.den = (int)stream_frame_rate; 233 codec_context->time_base.den = (int)stream_frame_rate; 232 234 codec_context->time_base.num = 1; 233 235 codec_context->gop_size = 12; // emit one intra frame every twelve frames at most … … 235 237 236 238 if (codec_context->codec_id == CODEC_ID_MPEG1VIDEO) 237 // needed to avoid using macroblocks in which some coeffs overflow 238 // this doesnt happen with normal video, it just happens here as the 239 // needed to avoid using macroblocks in which some coeffs overflow 240 // this doesnt happen with normal video, it just happens here as the 239 241 // motion of the chroma plane doesnt match the luma plane 240 242 codec_context->mb_decision=2; … … 275 277 { 276 278 int out_size, err; 277 279 278 280 codec_context = video_stream->codec; 279 281 280 282 if(frame_count >= stream_nb_frames) 281 283 { … … 287 289 this->fillYuvImage(); 288 290 289 291 290 292 if(format_context->oformat->flags & AVFMT_RAWPICTURE) 291 293 { … … 293 295 // futur for that 294 296 av_init_packet(&packet); 295 297 296 298 packet.flags |= PKT_FLAG_KEY; 297 299 packet.stream_index= video_stream->index; 298 300 packet.data= (uint8_t *)picture; 299 301 packet.size= sizeof(AVPicture); 300 302 301 303 err = av_write_frame(format_context, &packet); 302 304 } … … 309 311 { 310 312 av_init_packet(&packet); 311 313 312 314 packet.pts= av_rescale_q(codec_context->coded_frame->pts, codec_context->time_base, video_stream->time_base); 313 315 if(codec_context->coded_frame->key_frame) … … 316 318 packet.data= buffer; 317 319 packet.size= out_size; 318 320 319 321 // write the compressed frame in the media file 320 322 err = av_write_frame(format_context, &packet);
Note: See TracChangeset
for help on using the changeset viewer.