Originally committed as revision 6933 to svn://svn.ffmpeg.org/ffmpeg/trunktags/v0.5
| @@ -370,6 +370,7 @@ typedef struct RcOverride{ | |||||
| #define CODEC_FLAG2_BRDO 0x00000400 ///< b-frame rate-distortion optimization | #define CODEC_FLAG2_BRDO 0x00000400 ///< b-frame rate-distortion optimization | ||||
| #define CODEC_FLAG2_INTRA_VLC 0x00000800 ///< use MPEG-2 intra VLC table | #define CODEC_FLAG2_INTRA_VLC 0x00000800 ///< use MPEG-2 intra VLC table | ||||
| #define CODEC_FLAG2_MEMC_ONLY 0x00001000 ///< only do ME/MC (I frames -> ref, P frame -> ME+MC) | #define CODEC_FLAG2_MEMC_ONLY 0x00001000 ///< only do ME/MC (I frames -> ref, P frame -> ME+MC) | ||||
| #define CODEC_FLAG2_DROP_FRAME_TIMECODE 0x00002000 ///< timecode is in drop frame format | |||||
| /* Unsupported options : | /* Unsupported options : | ||||
| * Syntax Arithmetic coding (SAC) | * Syntax Arithmetic coding (SAC) | ||||
| @@ -2057,6 +2058,13 @@ typedef struct AVCodecContext { | |||||
| * - decoding: unused. | * - decoding: unused. | ||||
| */ | */ | ||||
| int max_partition_order; | int max_partition_order; | ||||
| /** | |||||
| * GOP timecode frame start number, in non drop frame format | |||||
| * - encoding: set by user. | |||||
| * - decoding: unused. | |||||
| */ | |||||
| int64_t timecode_frame_start; | |||||
| } AVCodecContext; | } AVCodecContext; | ||||
| /** | /** | ||||
| @@ -240,6 +240,11 @@ static int encode_init(AVCodecContext *avctx) | |||||
| if(avctx->level == FF_LEVEL_UNKNOWN) | if(avctx->level == FF_LEVEL_UNKNOWN) | ||||
| avctx->level = s->chroma_format == CHROMA_420 ? 8 : 5; | avctx->level = s->chroma_format == CHROMA_420 ? 8 : 5; | ||||
| if((avctx->flags2 & CODEC_FLAG2_DROP_FRAME_TIMECODE) && s->frame_rate_index != 4){ | |||||
| av_log(avctx, AV_LOG_ERROR, "Drop frame time code only allowed with 1001/30000 fps\n"); | |||||
| return -1; | |||||
| } | |||||
| return 0; | return 0; | ||||
| } | } | ||||
| @@ -346,13 +351,20 @@ static void mpeg1_encode_sequence_header(MpegEncContext *s) | |||||
| } | } | ||||
| put_header(s, GOP_START_CODE); | put_header(s, GOP_START_CODE); | ||||
| put_bits(&s->pb, 1, 0); /* do drop frame */ | |||||
| put_bits(&s->pb, 1, !!(s->avctx->flags & CODEC_FLAG2_DROP_FRAME_TIMECODE)); /* drop frame flag */ | |||||
| /* time code : we must convert from the real frame rate to a | /* time code : we must convert from the real frame rate to a | ||||
| fake mpeg frame rate in case of low frame rate */ | fake mpeg frame rate in case of low frame rate */ | ||||
| fps = (framerate.num + framerate.den/2)/ framerate.den; | fps = (framerate.num + framerate.den/2)/ framerate.den; | ||||
| time_code = s->current_picture_ptr->coded_picture_number; | |||||
| s->gop_picture_number = time_code; | |||||
| time_code = s->current_picture_ptr->coded_picture_number + s->avctx->timecode_frame_start; | |||||
| s->gop_picture_number = s->current_picture_ptr->coded_picture_number; | |||||
| if (s->avctx->flags2 & CODEC_FLAG2_DROP_FRAME_TIMECODE) { | |||||
| /* only works for NTSC 29.97 */ | |||||
| int d = time_code / 17982; | |||||
| int m = time_code % 17982; | |||||
| //if (m < 2) m += 2; /* not needed since -2,-1 / 2 in C returns 0 */ | |||||
| time_code += 18 * d + 2 * ((m - 2) / 1798); | |||||
| } | |||||
| put_bits(&s->pb, 5, (uint32_t)((time_code / (fps * 3600)) % 24)); | put_bits(&s->pb, 5, (uint32_t)((time_code / (fps * 3600)) % 24)); | ||||
| put_bits(&s->pb, 6, (uint32_t)((time_code / (fps * 60)) % 60)); | put_bits(&s->pb, 6, (uint32_t)((time_code / (fps * 60)) % 60)); | ||||
| put_bits(&s->pb, 1, 1); | put_bits(&s->pb, 1, 1); | ||||
| @@ -722,6 +722,8 @@ static const AVOption options[]={ | |||||
| {"prediction_order_method", NULL, OFFSET(prediction_order_method), FF_OPT_TYPE_INT, -1, INT_MIN, INT_MAX, A|E}, | {"prediction_order_method", NULL, OFFSET(prediction_order_method), FF_OPT_TYPE_INT, -1, INT_MIN, INT_MAX, A|E}, | ||||
| {"min_partition_order", NULL, OFFSET(min_partition_order), FF_OPT_TYPE_INT, -1, INT_MIN, INT_MAX, A|E}, | {"min_partition_order", NULL, OFFSET(min_partition_order), FF_OPT_TYPE_INT, -1, INT_MIN, INT_MAX, A|E}, | ||||
| {"max_partition_order", NULL, OFFSET(max_partition_order), FF_OPT_TYPE_INT, -1, INT_MIN, INT_MAX, A|E}, | {"max_partition_order", NULL, OFFSET(max_partition_order), FF_OPT_TYPE_INT, -1, INT_MIN, INT_MAX, A|E}, | ||||
| {"timecode_frame_start", NULL, OFFSET(timecode_frame_start), FF_OPT_TYPE_INT, 0, 0, INT_MAX, V|E}, | |||||
| {"drop_frame_timecode", NULL, 0, FF_OPT_TYPE_CONST, CODEC_FLAG2_DROP_FRAME_TIMECODE, INT_MIN, INT_MAX, V|E, "flags2"}, | |||||
| {NULL}, | {NULL}, | ||||
| }; | }; | ||||