diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h index 2a27d8d53b..5677c0bce5 100644 --- a/libavcodec/avcodec.h +++ b/libavcodec/avcodec.h @@ -561,7 +561,6 @@ typedef struct RcOverride{ #define CODEC_FLAG_BITEXACT 0x00800000 ///< Use only bitexact stuff (except (I)DCT). /* Fx : Flag for h263+ extra options */ #define CODEC_FLAG_AC_PRED 0x01000000 ///< H.263 advanced intra coding / MPEG-4 AC prediction -#define CODEC_FLAG_CBP_RD 0x04000000 ///< Use rate distortion optimization for cbp. #define CODEC_FLAG_LOOP_FILTER 0x00000800 ///< loop filter #define CODEC_FLAG_INTERLACED_ME 0x20000000 ///< interlaced motion estimation #define CODEC_FLAG_CLOSED_GOP 0x80000000 @@ -569,6 +568,7 @@ typedef struct RcOverride{ #define CODEC_FLAG2_NO_OUTPUT 0x00000004 ///< Skip bitstream encoding. #define CODEC_FLAG2_LOCAL_HEADER 0x00000008 ///< Place global headers at every keyframe instead of in extradata. #if FF_API_MPV_GLOBAL_OPTS +#define CODEC_FLAG_CBP_RD 0x04000000 ///< Use rate distortion optimization for cbp. #define CODEC_FLAG_QP_RD 0x08000000 ///< Use rate distortion optimization for qp selectioon. #define CODEC_FLAG2_STRICT_GOP 0x00000002 ///< Strictly enforce GOP size. #define CODEC_FLAG2_SKIP_RD 0x00004000 ///< RD optimal MB level residual skipping diff --git a/libavcodec/h263.h b/libavcodec/h263.h index d26cf636eb..2a1ae4839d 100644 --- a/libavcodec/h263.h +++ b/libavcodec/h263.h @@ -148,7 +148,7 @@ static inline int get_p_cbp(MpegEncContext * s, int motion_x, int motion_y){ int cbp, i; - if(s->flags & CODEC_FLAG_CBP_RD){ + if (s->mpv_flags & FF_MPV_FLAG_CBP_RD) { int best_cbpy_score= INT_MAX; int best_cbpc_score= INT_MAX; int cbpc = (-1), cbpy= (-1); diff --git a/libavcodec/mpeg4videoenc.c b/libavcodec/mpeg4videoenc.c index c2d4626dad..e6b015a431 100644 --- a/libavcodec/mpeg4videoenc.c +++ b/libavcodec/mpeg4videoenc.c @@ -430,7 +430,7 @@ static inline int get_b_cbp(MpegEncContext * s, DCTELEM block[6][64], { int cbp = 0, i; - if (s->flags & CODEC_FLAG_CBP_RD) { + if (s->mpv_flags & FF_MPV_FLAG_CBP_RD) { int score = 0; const int lambda = s->lambda2 >> (FF_LAMBDA_SHIFT - 6); diff --git a/libavcodec/mpegvideo.h b/libavcodec/mpegvideo.h index 26c88b000c..4ec419034f 100644 --- a/libavcodec/mpegvideo.h +++ b/libavcodec/mpegvideo.h @@ -702,6 +702,7 @@ typedef struct MpegEncContext { #define FF_MPV_FLAG_SKIP_RD 0x0001 #define FF_MPV_FLAG_STRICT_GOP 0x0002 #define FF_MPV_FLAG_QP_RD 0x0004 +#define FF_MPV_FLAG_CBP_RD 0x0008 #define FF_MPV_OFFSET(x) offsetof(MpegEncContext, x) #define FF_MPV_OPT_FLAGS (AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM) @@ -709,7 +710,8 @@ typedef struct MpegEncContext { { "mpv_flags", "Flags common for all mpegvideo-based encoders.", FF_MPV_OFFSET(mpv_flags), AV_OPT_TYPE_FLAGS, { 0 }, INT_MIN, INT_MAX, FF_MPV_OPT_FLAGS, "mpv_flags" },\ { "skip_rd", "RD optimal MB level residual skipping", 0, AV_OPT_TYPE_CONST, { FF_MPV_FLAG_SKIP_RD }, 0, 0, FF_MPV_OPT_FLAGS, "mpv_flags" },\ { "strict_gop", "Strictly enforce gop size", 0, AV_OPT_TYPE_CONST, { FF_MPV_FLAG_STRICT_GOP }, 0, 0, FF_MPV_OPT_FLAGS, "mpv_flags" },\ -{ "qp_rd", "Use rate distortion optimization for qp selection", 0, AV_OPT_TYPE_CONST, { FF_MPV_FLAG_QP_RD }, 0, 0, FF_MPV_OPT_FLAGS, "mpv_flags" }, +{ "qp_rd", "Use rate distortion optimization for qp selection", 0, AV_OPT_TYPE_CONST, { FF_MPV_FLAG_QP_RD }, 0, 0, FF_MPV_OPT_FLAGS, "mpv_flags" },\ +{ "cbp_rd", "use rate distortion optimization for CBP", 0, AV_OPT_TYPE_CONST, { FF_MPV_FLAG_CBP_RD }, 0, 0, FF_MPV_OPT_FLAGS, "mpv_flags" }, extern const AVOption ff_mpv_generic_options[]; diff --git a/libavcodec/mpegvideo_enc.c b/libavcodec/mpegvideo_enc.c index bb348137aa..e6e6a95b48 100644 --- a/libavcodec/mpegvideo_enc.c +++ b/libavcodec/mpegvideo_enc.c @@ -495,7 +495,12 @@ av_cold int ff_MPV_encode_init(AVCodecContext *avctx) return -1; } - if ((s->flags & CODEC_FLAG_CBP_RD) && !avctx->trellis) { +#if FF_API_MPV_GLOBAL_OPTS + if (s->flags & CODEC_FLAG_CBP_RD) + s->mpv_flags |= FF_MPV_FLAG_CBP_RD; +#endif + + if ((s->mpv_flags & FF_MPV_FLAG_CBP_RD) && !avctx->trellis) { av_log(avctx, AV_LOG_ERROR, "CBP RD needs trellis quant\n"); return -1; } @@ -1998,7 +2003,7 @@ static av_always_inline void encode_mb_internal(MpegEncContext *s, for (i = 4; i < mb_block_count; i++) dct_single_coeff_elimination(s, i, s->chroma_elim_threshold); - if (s->flags & CODEC_FLAG_CBP_RD) { + if (s->mpv_flags & FF_MPV_FLAG_CBP_RD) { for (i = 0; i < mb_block_count; i++) { if (s->block_last_index[i] == -1) s->coded_score[i] = INT_MAX / 256; diff --git a/libavcodec/options.c b/libavcodec/options.c index de5b42a147..6b5b148516 100644 --- a/libavcodec/options.c +++ b/libavcodec/options.c @@ -97,8 +97,8 @@ static const AVOption options[]={ {"global_header", "place global headers in extradata instead of every keyframe", 0, AV_OPT_TYPE_CONST, {.dbl = CODEC_FLAG_GLOBAL_HEADER }, INT_MIN, INT_MAX, V|A|E, "flags"}, {"bitexact", "use only bitexact stuff (except (i)dct)", 0, AV_OPT_TYPE_CONST, {.dbl = CODEC_FLAG_BITEXACT }, INT_MIN, INT_MAX, A|V|S|D|E, "flags"}, {"aic", "h263 advanced intra coding / mpeg4 ac prediction", 0, AV_OPT_TYPE_CONST, {.dbl = CODEC_FLAG_AC_PRED }, INT_MIN, INT_MAX, V|E, "flags"}, -{"cbp", "use rate distortion optimization for cbp", 0, AV_OPT_TYPE_CONST, {.dbl = CODEC_FLAG_CBP_RD }, INT_MIN, INT_MAX, V|E, "flags"}, #if FF_API_MPV_GLOBAL_OPTS +{"cbp", "Deprecated, use mpegvideo private options instead", 0, AV_OPT_TYPE_CONST, {.dbl = CODEC_FLAG_CBP_RD }, INT_MIN, INT_MAX, V|E, "flags"}, {"qprd", "Deprecated, use mpegvideo private options instead", 0, AV_OPT_TYPE_CONST, {.dbl = CODEC_FLAG_QP_RD }, INT_MIN, INT_MAX, V|E, "flags"}, #endif {"ilme", "interlaced motion estimation", 0, AV_OPT_TYPE_CONST, {.dbl = CODEC_FLAG_INTERLACED_ME }, INT_MIN, INT_MAX, V|E, "flags"},