Commit ec8f56ef authored by Michael Niedermayer's avatar Michael Niedermayer

Merge commit 'a75c2eb2'

* commit 'a75c2eb2':
  lavc: make rc_eq into private options of mpegvideo encoders

Conflicts:
	libavcodec/options_table.h
Merged-by: 's avatarMichael Niedermayer <michaelni@gmx.at>
parents 17a065cf a75c2eb2
...@@ -2299,12 +2299,13 @@ typedef struct AVCodecContext { ...@@ -2299,12 +2299,13 @@ typedef struct AVCodecContext {
int rc_override_count; int rc_override_count;
RcOverride *rc_override; RcOverride *rc_override;
#if FF_API_MPV_OPT
/** /**
* rate control equation * @deprecated use encoder private options instead
* - encoding: Set by user
* - decoding: unused
*/ */
attribute_deprecated
const char *rc_eq; const char *rc_eq;
#endif
/** /**
* maximum bitrate * maximum bitrate
......
...@@ -660,6 +660,8 @@ typedef struct MpegEncContext { ...@@ -660,6 +660,8 @@ typedef struct MpegEncContext {
float rc_qmod_amp; float rc_qmod_amp;
int rc_qmod_freq; int rc_qmod_freq;
char *rc_eq;
/* temp buffers for rate control */ /* temp buffers for rate control */
float *cplx_tab, *bits_tab; float *cplx_tab, *bits_tab;
...@@ -708,7 +710,12 @@ typedef struct MpegEncContext { ...@@ -708,7 +710,12 @@ typedef struct MpegEncContext {
{"qsquish", "how to keep quantizer between qmin and qmax (0 = clip, 1 = use differentiable function)", \ {"qsquish", "how to keep quantizer between qmin and qmax (0 = clip, 1 = use differentiable function)", \
FF_MPV_OFFSET(rc_qsquish), AV_OPT_TYPE_FLOAT, {.dbl = 0 }, 0, 99, FF_MPV_OPT_FLAGS}, \ FF_MPV_OFFSET(rc_qsquish), AV_OPT_TYPE_FLOAT, {.dbl = 0 }, 0, 99, FF_MPV_OPT_FLAGS}, \
{"rc_qmod_amp", "experimental quantizer modulation", FF_MPV_OFFSET(rc_qmod_amp), AV_OPT_TYPE_FLOAT, {.dbl = 0 }, -FLT_MAX, FLT_MAX, FF_MPV_OPT_FLAGS}, \ {"rc_qmod_amp", "experimental quantizer modulation", FF_MPV_OFFSET(rc_qmod_amp), AV_OPT_TYPE_FLOAT, {.dbl = 0 }, -FLT_MAX, FLT_MAX, FF_MPV_OPT_FLAGS}, \
{"rc_qmod_freq", "experimental quantizer modulation", FF_MPV_OFFSET(rc_qmod_freq), AV_OPT_TYPE_INT, {.i64 = 0 }, INT_MIN, INT_MAX, FF_MPV_OPT_FLAGS}, {"rc_qmod_freq", "experimental quantizer modulation", FF_MPV_OFFSET(rc_qmod_freq), AV_OPT_TYPE_INT, {.i64 = 0 }, INT_MIN, INT_MAX, FF_MPV_OPT_FLAGS}, \
{"rc_eq", "Set rate control equation. When computing the expression, besides the standard functions " \
"defined in the section 'Expression Evaluation', the following functions are available: " \
"bits2qp(bits), qp2bits(qp). Also the following constants are available: iTex pTex tex mv " \
"fCode iCount mcVar var isI isP isB avgQP qComp avgIITex avgPITex avgPPTex avgBPTex avgTex.", \
FF_MPV_OFFSET(rc_eq), AV_OPT_TYPE_STRING, .flags = FF_MPV_OPT_FLAGS },
extern const AVOption ff_mpv_generic_options[]; extern const AVOption ff_mpv_generic_options[];
......
...@@ -958,6 +958,13 @@ av_cold int ff_mpv_encode_init(AVCodecContext *avctx) ...@@ -958,6 +958,13 @@ av_cold int ff_mpv_encode_init(AVCodecContext *avctx)
s->rc_qmod_amp = avctx->rc_qmod_amp; s->rc_qmod_amp = avctx->rc_qmod_amp;
if (avctx->rc_qmod_freq) if (avctx->rc_qmod_freq)
s->rc_qmod_freq = avctx->rc_qmod_freq; s->rc_qmod_freq = avctx->rc_qmod_freq;
if (avctx->rc_eq) {
av_freep(&s->rc_eq);
s->rc_eq = av_strdup(avctx->rc_eq);
if (!s->rc_eq)
return AVERROR(ENOMEM);
}
FF_ENABLE_DEPRECATION_WARNINGS FF_ENABLE_DEPRECATION_WARNINGS
#endif #endif
......
...@@ -27,6 +27,7 @@ ...@@ -27,6 +27,7 @@
#include "avcodec.h" #include "avcodec.h"
#include "internal.h" #include "internal.h"
#include "libavutil/avassert.h" #include "libavutil/avassert.h"
#include "libavutil/internal.h"
#include "libavutil/mem.h" #include "libavutil/mem.h"
#include "libavutil/opt.h" #include "libavutil/opt.h"
#include <float.h> /* FLT_MIN, FLT_MAX */ #include <float.h> /* FLT_MIN, FLT_MAX */
...@@ -200,17 +201,21 @@ int avcodec_copy_context(AVCodecContext *dest, const AVCodecContext *src) ...@@ -200,17 +201,21 @@ int avcodec_copy_context(AVCodecContext *dest, const AVCodecContext *src)
dest->internal = NULL; dest->internal = NULL;
/* reallocate values that should be allocated separately */ /* reallocate values that should be allocated separately */
dest->rc_eq = NULL;
dest->extradata = NULL; dest->extradata = NULL;
dest->intra_matrix = NULL; dest->intra_matrix = NULL;
dest->inter_matrix = NULL; dest->inter_matrix = NULL;
dest->rc_override = NULL; dest->rc_override = NULL;
dest->subtitle_header = NULL; dest->subtitle_header = NULL;
#if FF_API_MPV_OPT
FF_DISABLE_DEPRECATION_WARNINGS
dest->rc_eq = NULL;
if (src->rc_eq) { if (src->rc_eq) {
dest->rc_eq = av_strdup(src->rc_eq); dest->rc_eq = av_strdup(src->rc_eq);
if (!dest->rc_eq) if (!dest->rc_eq)
return AVERROR(ENOMEM); return AVERROR(ENOMEM);
} }
FF_ENABLE_DEPRECATION_WARNINGS
#endif
#define alloc_and_copy_or_fail(obj, size, pad) \ #define alloc_and_copy_or_fail(obj, size, pad) \
if (src->obj && size > 0) { \ if (src->obj && size > 0) { \
...@@ -237,7 +242,11 @@ fail: ...@@ -237,7 +242,11 @@ fail:
av_freep(&dest->intra_matrix); av_freep(&dest->intra_matrix);
av_freep(&dest->inter_matrix); av_freep(&dest->inter_matrix);
av_freep(&dest->extradata); av_freep(&dest->extradata);
#if FF_API_MPV_OPT
FF_DISABLE_DEPRECATION_WARNINGS
av_freep(&dest->rc_eq); av_freep(&dest->rc_eq);
FF_ENABLE_DEPRECATION_WARNINGS
#endif
return AVERROR(ENOMEM); return AVERROR(ENOMEM);
} }
......
...@@ -180,11 +180,9 @@ static const AVOption avcodec_options[] = { ...@@ -180,11 +180,9 @@ static const AVOption avcodec_options[] = {
{"rc_qmod_freq", "deprecated, use encoder private options instead", OFFSET(rc_qmod_freq), AV_OPT_TYPE_INT, {.i64 = DEFAULT }, INT_MIN, INT_MAX, V|E}, {"rc_qmod_freq", "deprecated, use encoder private options instead", OFFSET(rc_qmod_freq), AV_OPT_TYPE_INT, {.i64 = DEFAULT }, INT_MIN, INT_MAX, V|E},
#endif #endif
{"rc_override_count", NULL, OFFSET(rc_override_count), AV_OPT_TYPE_INT, {.i64 = DEFAULT }, INT_MIN, INT_MAX}, {"rc_override_count", NULL, OFFSET(rc_override_count), AV_OPT_TYPE_INT, {.i64 = DEFAULT }, INT_MIN, INT_MAX},
{"rc_eq", "Set rate control equation. When computing the expression, besides the standard functions " #if FF_API_MPV_OPT
"defined in the section 'Expression Evaluation', the following functions are available: " {"rc_eq", "deprecated, use encoder private options instead", OFFSET(rc_eq), AV_OPT_TYPE_STRING, {.str = NULL}, CHAR_MIN, CHAR_MAX, V|E},
"bits2qp(bits), qp2bits(qp). Also the following constants are available: iTex pTex tex mv " #endif
"fCode iCount mcVar var isI isP isB avgQP qComp avgIITex avgPITex avgPPTex avgBPTex avgTex.",
OFFSET(rc_eq), AV_OPT_TYPE_STRING, {.str = NULL}, CHAR_MIN, CHAR_MAX, V|E},
{"maxrate", "maximum bitrate (in bits/s). Used for VBV together with bufsize.", OFFSET(rc_max_rate), AV_OPT_TYPE_INT, {.i64 = DEFAULT }, 0, INT_MAX, V|A|E}, {"maxrate", "maximum bitrate (in bits/s). Used for VBV together with bufsize.", OFFSET(rc_max_rate), AV_OPT_TYPE_INT, {.i64 = DEFAULT }, 0, INT_MAX, V|A|E},
{"minrate", "minimum bitrate (in bits/s). Most useful in setting up a CBR encode. It is of little use otherwise.", {"minrate", "minimum bitrate (in bits/s). Most useful in setting up a CBR encode. It is of little use otherwise.",
OFFSET(rc_min_rate), AV_OPT_TYPE_INT, {.i64 = DEFAULT }, INT_MIN, INT_MAX, V|A|E}, OFFSET(rc_min_rate), AV_OPT_TYPE_INT, {.i64 = DEFAULT }, INT_MIN, INT_MAX, V|A|E},
......
...@@ -138,11 +138,11 @@ av_cold int ff_rate_control_init(MpegEncContext *s) ...@@ -138,11 +138,11 @@ av_cold int ff_rate_control_init(MpegEncContext *s)
} }
res = av_expr_parse(&rcc->rc_eq_eval, res = av_expr_parse(&rcc->rc_eq_eval,
s->avctx->rc_eq ? s->avctx->rc_eq : "tex^qComp", s->rc_eq ? s->rc_eq : "tex^qComp",
const_names, func1_names, func1, const_names, func1_names, func1,
NULL, NULL, 0, s->avctx); NULL, NULL, 0, s->avctx);
if (res < 0) { if (res < 0) {
av_log(s->avctx, AV_LOG_ERROR, "Error parsing rc_eq \"%s\"\n", s->avctx->rc_eq); av_log(s->avctx, AV_LOG_ERROR, "Error parsing rc_eq \"%s\"\n", s->rc_eq);
return res; return res;
} }
...@@ -399,7 +399,7 @@ static double get_qscale(MpegEncContext *s, RateControlEntry *rce, ...@@ -399,7 +399,7 @@ static double get_qscale(MpegEncContext *s, RateControlEntry *rce,
bits = av_expr_eval(rcc->rc_eq_eval, const_values, rce); bits = av_expr_eval(rcc->rc_eq_eval, const_values, rce);
if (isnan(bits)) { if (isnan(bits)) {
av_log(s->avctx, AV_LOG_ERROR, "Error evaluating rc_eq \"%s\"\n", s->avctx->rc_eq); av_log(s->avctx, AV_LOG_ERROR, "Error evaluating rc_eq \"%s\"\n", s->rc_eq);
return -1; return -1;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment