comparison mpeg12.c @ 4158:47d1b5261f17 libavcodec

add option to set mpeg1/2 gop timecode start, and drop frame flag timecode flag
author bcoudurier
date Tue, 07 Nov 2006 13:45:08 +0000
parents 93baab5a86d2
children aeb1b0d99013
comparison
equal deleted inserted replaced
4157:bb0431100529 4158:47d1b5261f17
238 avctx->profile = s->chroma_format == CHROMA_420 ? 4 : 0; 238 avctx->profile = s->chroma_format == CHROMA_420 ? 4 : 0;
239 239
240 if(avctx->level == FF_LEVEL_UNKNOWN) 240 if(avctx->level == FF_LEVEL_UNKNOWN)
241 avctx->level = s->chroma_format == CHROMA_420 ? 8 : 5; 241 avctx->level = s->chroma_format == CHROMA_420 ? 8 : 5;
242 242
243 if((avctx->flags2 & CODEC_FLAG2_DROP_FRAME_TIMECODE) && s->frame_rate_index != 4){
244 av_log(avctx, AV_LOG_ERROR, "Drop frame time code only allowed with 1001/30000 fps\n");
245 return -1;
246 }
247
243 return 0; 248 return 0;
244 } 249 }
245 250
246 static void put_header(MpegEncContext *s, int header) 251 static void put_header(MpegEncContext *s, int header)
247 { 252 {
344 put_bits(&s->pb, 2, 0); // frame_rate_ext_n 349 put_bits(&s->pb, 2, 0); // frame_rate_ext_n
345 put_bits(&s->pb, 5, 0); // frame_rate_ext_d 350 put_bits(&s->pb, 5, 0); // frame_rate_ext_d
346 } 351 }
347 352
348 put_header(s, GOP_START_CODE); 353 put_header(s, GOP_START_CODE);
349 put_bits(&s->pb, 1, 0); /* do drop frame */ 354 put_bits(&s->pb, 1, !!(s->avctx->flags & CODEC_FLAG2_DROP_FRAME_TIMECODE)); /* drop frame flag */
350 /* time code : we must convert from the real frame rate to a 355 /* time code : we must convert from the real frame rate to a
351 fake mpeg frame rate in case of low frame rate */ 356 fake mpeg frame rate in case of low frame rate */
352 fps = (framerate.num + framerate.den/2)/ framerate.den; 357 fps = (framerate.num + framerate.den/2)/ framerate.den;
353 time_code = s->current_picture_ptr->coded_picture_number; 358 time_code = s->current_picture_ptr->coded_picture_number + s->avctx->timecode_frame_start;
354 359
355 s->gop_picture_number = time_code; 360 s->gop_picture_number = s->current_picture_ptr->coded_picture_number;
361 if (s->avctx->flags2 & CODEC_FLAG2_DROP_FRAME_TIMECODE) {
362 /* only works for NTSC 29.97 */
363 int d = time_code / 17982;
364 int m = time_code % 17982;
365 //if (m < 2) m += 2; /* not needed since -2,-1 / 2 in C returns 0 */
366 time_code += 18 * d + 2 * ((m - 2) / 1798);
367 }
356 put_bits(&s->pb, 5, (uint32_t)((time_code / (fps * 3600)) % 24)); 368 put_bits(&s->pb, 5, (uint32_t)((time_code / (fps * 3600)) % 24));
357 put_bits(&s->pb, 6, (uint32_t)((time_code / (fps * 60)) % 60)); 369 put_bits(&s->pb, 6, (uint32_t)((time_code / (fps * 60)) % 60));
358 put_bits(&s->pb, 1, 1); 370 put_bits(&s->pb, 1, 1);
359 put_bits(&s->pb, 6, (uint32_t)((time_code / fps) % 60)); 371 put_bits(&s->pb, 6, (uint32_t)((time_code / fps) % 60));
360 put_bits(&s->pb, 6, (uint32_t)((time_code % fps))); 372 put_bits(&s->pb, 6, (uint32_t)((time_code % fps)));