This removes the additional factor of FF_QP2LAMBDA (118) in use of
global_quality. The new scale is entirely codec dependent but should
resemble the H.26[345] quantisation parameter.
---
avconv.c | 5 ++---
avconv_opt.c | 2 +-
doc/APIchanges | 3 +++
doc/encoders.texi | 2 +-
libavcodec/a64multienc.c | 2 +-
libavcodec/aacpsy.c | 2 +-
libavcodec/asvenc.c | 5 ++---
libavcodec/avcodec.h | 3 ++-
libavcodec/dnxhdenc.c | 4 ++--
libavcodec/libfaac.c | 2 +-
libavcodec/libmp3lame.c | 2 +-
libavcodec/libschroedingerenc.c | 2 +-
libavcodec/libspeexenc.c | 3 +--
libavcodec/libtheoraenc.c | 2 +-
libavcodec/libtwolame.c | 3 +--
libavcodec/libvorbis.c | 2 +-
libavcodec/libwebpenc.c | 5 ++---
libavcodec/libx264.c | 4 ++--
libavcodec/libxavs.c | 4 ++--
libavcodec/libxvid.c | 6 +++---
libavcodec/mpegvideo_enc.c | 4 ++--
libavcodec/proresenc.c | 2 +-
libavcodec/qsvenc.c | 2 +-
libavcodec/vorbisenc.c | 2 +-
libavutil/avutil.h | 2 --
libavutil/frame.h | 2 +-
26 files changed, 37 insertions(+), 40 deletions(-)
diff --git a/avconv.c b/avconv.c
index 5c3133281..f82cfa92c 100644
--- a/avconv.c
+++ b/avconv.c
@@ -636,8 +636,7 @@ static void do_video_stats(OutputStream *ost, int
frame_size)
enc = ost->enc_ctx;
if (enc->codec_type == AVMEDIA_TYPE_VIDEO) {
frame_number = ost->frame_number;
- fprintf(vstats_file, "frame= %5d q= %2.1f ", frame_number,
- ost->quality / (float)FF_QP2LAMBDA);
+ fprintf(vstats_file, "frame= %5d q= %d ", frame_number, ost->quality);
#if FF_API_CODED_FRAME && FF_API_ERROR_FRAME
FF_DISABLE_DEPRECATION_WARNINGS
@@ -954,7 +953,7 @@ static void print_report(int is_last_report, int64_t
timer_start)
ost = output_streams[i];
enc = ost->enc_ctx;
if (!ost->stream_copy)
- q = ost->quality / (float) FF_QP2LAMBDA;
+ q = ost->quality;
if (vid && enc->codec_type == AVMEDIA_TYPE_VIDEO) {
snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), "q=%2.1f ",
q);
diff --git a/avconv_opt.c b/avconv_opt.c
index 4d7140dc4..c329d7f45 100644
--- a/avconv_opt.c
+++ b/avconv_opt.c
@@ -1088,7 +1088,7 @@ static OutputStream *new_output_stream(OptionsContext *o,
AVFormatContext *oc, e
MATCH_PER_STREAM_OPT(qscale, dbl, qscale, oc, st);
if (qscale >= 0) {
ost->enc_ctx->flags |= AV_CODEC_FLAG_QSCALE;
- ost->enc_ctx->global_quality = FF_QP2LAMBDA * qscale;
+ ost->enc_ctx->global_quality = qscale;
}
ost->max_muxing_queue_size = 128;
diff --git a/doc/APIchanges b/doc/APIchanges
index 7633c9918..8cade923e 100644
--- a/doc/APIchanges
+++ b/doc/APIchanges
@@ -13,6 +13,9 @@ libavutil: 2015-08-28
API changes, most recent first:
+2017-xx-xx - xxxxxxx - lavc 58.xx.x - avcodec.h
+ Change scale of AVCodecContext.global_quality.
+
2016-xx-xx - xxxxxxx - lavc 57.29.0 - avcodec.h
Add AV_PKT_DATA_SPHERICAL packet side data to export AVSphericalMapping
information from containers.
diff --git a/doc/encoders.texi b/doc/encoders.texi
index bc5b33660..5e100a340 100644
--- a/doc/encoders.texi
+++ b/doc/encoders.texi
@@ -483,7 +483,7 @@ Default is 4.
For lossy encoding, this controls image quality, 0 to 100. For lossless
encoding, this controls the effort and time spent at compressing more. The
default value is 75. Note that for usage via libavcodec, this option is called
-@var{global_quality} and must be multiplied by @var{FF_QP2LAMBDA}.
+@var{global_quality}.
@item -preset @var{type}
Configuration preset. This does some automatic settings based on the general
diff --git a/libavcodec/a64multienc.c b/libavcodec/a64multienc.c
index 5d8d16234..8c6ebca32 100644
--- a/libavcodec/a64multienc.c
+++ b/libavcodec/a64multienc.c
@@ -183,7 +183,7 @@ static av_cold int a64multi_encode_init(AVCodecContext
*avctx)
if (avctx->global_quality < 1) {
c->mc_lifetime = 4;
} else {
- c->mc_lifetime = avctx->global_quality /= FF_QP2LAMBDA;
+ c->mc_lifetime = avctx->global_quality;
}
av_log(avctx, AV_LOG_INFO, "charset lifetime set to %d frame(s)\n",
c->mc_lifetime);
diff --git a/libavcodec/aacpsy.c b/libavcodec/aacpsy.c
index 272be9f13..179c8f1ce 100644
--- a/libavcodec/aacpsy.c
+++ b/libavcodec/aacpsy.c
@@ -257,7 +257,7 @@ static av_cold void lame_window_init(AacPsyContext *ctx,
AVCodecContext *avctx)
AacPsyChannel *pch = &ctx->ch[i];
if (avctx->flags & AV_CODEC_FLAG_QSCALE)
- pch->attack_threshold = psy_vbr_map[avctx->global_quality /
FF_QP2LAMBDA].st_lrm;
+ pch->attack_threshold = psy_vbr_map[avctx->global_quality].st_lrm;
else
pch->attack_threshold = lame_calc_attack_threshold(avctx->bit_rate
/ avctx->channels / 1000);
diff --git a/libavcodec/asvenc.c b/libavcodec/asvenc.c
index ac7c317fa..19e5fb29c 100644
--- a/libavcodec/asvenc.c
+++ b/libavcodec/asvenc.c
@@ -294,10 +294,9 @@ FF_ENABLE_DEPRECATION_WARNINGS
ff_pixblockdsp_init(&a->pdsp, avctx);
if (avctx->global_quality == 0)
- avctx->global_quality = 4 * FF_QUALITY_SCALE;
+ avctx->global_quality = 4;
- a->inv_qscale = (32 * scale * FF_QUALITY_SCALE +
- avctx->global_quality / 2) / avctx->global_quality;
+ a->inv_qscale = (32 * scale + avctx->global_quality / 2) /
avctx->global_quality;
avctx->extradata = av_mallocz(8);
if (!avctx->extradata)
diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
index 95da50b0e..c4ff30099 100644
--- a/libavcodec/avcodec.h
+++ b/libavcodec/avcodec.h
@@ -1493,7 +1493,8 @@ typedef struct AVCodecContext {
/**
* Global quality for codecs which cannot change it per frame.
- * This should be proportional to MPEG-1/2/4 qscale.
+ * The unit is codec-dependent. For video it should be something like the
JPEG quality factor
+ * or H.26[345] quantisation parameter, with higher values indicating
lower encode quality.
* - encoding: Set by user.
* - decoding: unused
*/
diff --git a/libavcodec/dnxhdenc.c b/libavcodec/dnxhdenc.c
index 0c6c59cec..97b0eab83 100644
--- a/libavcodec/dnxhdenc.c
+++ b/libavcodec/dnxhdenc.c
@@ -1091,14 +1091,14 @@ encode_coding_unit:
#if FF_API_CODED_FRAME
FF_DISABLE_DEPRECATION_WARNINGS
- avctx->coded_frame->quality = ctx->qscale * FF_QP2LAMBDA;
+ avctx->coded_frame->quality = ctx->qscale;
FF_ENABLE_DEPRECATION_WARNINGS
#endif
sd = av_packet_new_side_data(pkt, AV_PKT_DATA_QUALITY_FACTOR, sizeof(int));
if (!sd)
return AVERROR(ENOMEM);
- *(int *)sd = ctx->qscale * FF_QP2LAMBDA;
+ *(int *)sd = ctx->qscale;
pkt->flags |= AV_PKT_FLAG_KEY;
*got_packet = 1;
diff --git a/libavcodec/libfaac.c b/libavcodec/libfaac.c
index 5cdbe2768..5b6e12af8 100644
--- a/libavcodec/libfaac.c
+++ b/libavcodec/libfaac.c
@@ -120,7 +120,7 @@ static av_cold int Faac_encode_init(AVCodecContext *avctx)
faac_cfg->bandWidth = avctx->cutoff;
if(avctx->flags & AV_CODEC_FLAG_QSCALE) {
faac_cfg->bitRate = 0;
- faac_cfg->quantqual = avctx->global_quality / FF_QP2LAMBDA;
+ faac_cfg->quantqual = avctx->global_quality;
}
faac_cfg->outputFormat = 1;
faac_cfg->inputFormat = FAAC_INPUT_16BIT;
diff --git a/libavcodec/libmp3lame.c b/libavcodec/libmp3lame.c
index e4d0e0010..3d5d10c36 100644
--- a/libavcodec/libmp3lame.c
+++ b/libavcodec/libmp3lame.c
@@ -113,7 +113,7 @@ static av_cold int mp3lame_encode_init(AVCodecContext
*avctx)
/* rate control */
if (avctx->flags & AV_CODEC_FLAG_QSCALE) { // VBR
lame_set_VBR(s->gfp, vbr_default);
- lame_set_VBR_quality(s->gfp, avctx->global_quality /
(float)FF_QP2LAMBDA);
+ lame_set_VBR_quality(s->gfp, avctx->global_quality);
} else {
if (avctx->bit_rate) {
if (s->abr) { // ABR
diff --git a/libavcodec/libschroedingerenc.c b/libavcodec/libschroedingerenc.c
index bf03cb78f..2242ed499 100644
--- a/libavcodec/libschroedingerenc.c
+++ b/libavcodec/libschroedingerenc.c
@@ -198,7 +198,7 @@ FF_ENABLE_DEPRECATION_WARNINGS
"rate_control",
SCHRO_ENCODER_RATE_CONTROL_CONSTANT_QUALITY);
- quality = avctx->global_quality / FF_QP2LAMBDA;
+ quality = avctx->global_quality;
if (quality > 10)
quality = 10;
schro_encoder_setting_set_double(p_schro_params->encoder,
diff --git a/libavcodec/libspeexenc.c b/libavcodec/libspeexenc.c
index f3a31e987..32d70857e 100644
--- a/libavcodec/libspeexenc.c
+++ b/libavcodec/libspeexenc.c
@@ -181,8 +181,7 @@ static av_cold int encode_init(AVCodecContext *avctx)
s->header.vbr = 1;
s->vad = 1; /* VAD is always implicitly activated for VBR */
speex_encoder_ctl(s->enc_state, SPEEX_SET_VBR, &s->header.vbr);
- s->vbr_quality = av_clipf(avctx->global_quality / (float)FF_QP2LAMBDA,
- 0.0f, 10.0f);
+ s->vbr_quality = av_clipf(avctx->global_quality, 0.0f, 10.0f);
speex_encoder_ctl(s->enc_state, SPEEX_SET_VBR_QUALITY,
&s->vbr_quality);
} else {
s->header.bitrate = avctx->bit_rate;
diff --git a/libavcodec/libtheoraenc.c b/libavcodec/libtheoraenc.c
index b329ed3b3..d7c672ea7 100644
--- a/libavcodec/libtheoraenc.c
+++ b/libavcodec/libtheoraenc.c
@@ -213,7 +213,7 @@ static av_cold int encode_init(AVCodecContext* avc_context)
* 0 <= p <=63
* an int value
*/
- t_info.quality = av_clipf(avc_context->global_quality /
(float)FF_QP2LAMBDA, 0, 10) * 6.3;
+ t_info.quality = av_clipf(avc_context->global_quality, 0, 10) *
6.3;
t_info.target_bitrate = 0;
} else {
t_info.target_bitrate = avc_context->bit_rate;
diff --git a/libavcodec/libtwolame.c b/libavcodec/libtwolame.c
index 714c30acd..834f74768 100644
--- a/libavcodec/libtwolame.c
+++ b/libavcodec/libtwolame.c
@@ -79,8 +79,7 @@ static av_cold int twolame_encode_init(AVCodecContext *avctx)
twolame_set_out_samplerate(s->glopts, avctx->sample_rate);
if (avctx->flags & AV_CODEC_FLAG_QSCALE || !avctx->bit_rate) {
twolame_set_VBR(s->glopts, TRUE);
- twolame_set_VBR_level(s->glopts,
- avctx->global_quality / (float) FF_QP2LAMBDA);
+ twolame_set_VBR_level(s->glopts, avctx->global_quality);
av_log(avctx, AV_LOG_WARNING,
"VBR in MP2 is a hack, use another codec that supports it.\n");
} else {
diff --git a/libavcodec/libvorbis.c b/libavcodec/libvorbis.c
index 86c1ed6a7..d33f0e8a6 100644
--- a/libavcodec/libvorbis.c
+++ b/libavcodec/libvorbis.c
@@ -96,7 +96,7 @@ static av_cold int libvorbis_setup(vorbis_info *vi,
AVCodecContext *avctx)
* NOTE: we use the oggenc range of -1 to 10 for global_quality for
* user convenience, but libvorbis uses -0.1 to 1.0.
*/
- float q = avctx->global_quality / (float)FF_QP2LAMBDA;
+ float q = avctx->global_quality;
/* default to 3 if the user did not set quality or bitrate */
if (!(avctx->flags & AV_CODEC_FLAG_QSCALE))
q = 3.0;
diff --git a/libavcodec/libwebpenc.c b/libavcodec/libwebpenc.c
index ef311b759..fa0a1b029 100644
--- a/libavcodec/libwebpenc.c
+++ b/libavcodec/libwebpenc.c
@@ -63,9 +63,8 @@ static av_cold int libwebp_encode_init(AVCodecContext *avctx)
int ret;
if (avctx->global_quality < 0)
- avctx->global_quality = 75 * FF_QP2LAMBDA;
- s->quality = av_clipf(avctx->global_quality / (float)FF_QP2LAMBDA,
- 0.0f, 100.0f);
+ avctx->global_quality = 75;
+ s->quality = av_clipf(avctx->global_quality, 0.0f, 100.0f);
if (avctx->compression_level < 0 || avctx->compression_level > 6) {
av_log(avctx, AV_LOG_WARNING, "invalid compression level: %d\n",
diff --git a/libavcodec/libx264.c b/libavcodec/libx264.c
index fddf1b382..3ccdb9393 100644
--- a/libavcodec/libx264.c
+++ b/libavcodec/libx264.c
@@ -308,11 +308,11 @@ FF_ENABLE_DEPRECATION_WARNINGS
sizeof(int));
if (!sd)
return AVERROR(ENOMEM);
- *(int *)sd = (pic_out.i_qpplus1 - 1) * FF_QP2LAMBDA;
+ *(int *)sd = pic_out.i_qpplus1 - 1;
#if FF_API_CODED_FRAME
FF_DISABLE_DEPRECATION_WARNINGS
- ctx->coded_frame->quality = (pic_out.i_qpplus1 - 1) * FF_QP2LAMBDA;
+ ctx->coded_frame->quality = pic_out.i_qpplus1 - 1;
FF_ENABLE_DEPRECATION_WARNINGS
#endif
}
diff --git a/libavcodec/libxavs.c b/libavcodec/libxavs.c
index b7a6c4166..e4e5e5ad8 100644
--- a/libavcodec/libxavs.c
+++ b/libavcodec/libxavs.c
@@ -211,14 +211,14 @@ FF_ENABLE_DEPRECATION_WARNINGS
#if FF_API_CODED_FRAME
FF_DISABLE_DEPRECATION_WARNINGS
- avctx->coded_frame->quality = (pic_out.i_qpplus1 - 1) * FF_QP2LAMBDA;
+ avctx->coded_frame->quality = pic_out.i_qpplus1 - 1;
FF_ENABLE_DEPRECATION_WARNINGS
#endif
sd = av_packet_new_side_data(pkt, AV_PKT_DATA_QUALITY_FACTOR, sizeof(int));
if (!sd)
return AVERROR(ENOMEM);
- *(int *)sd = (pic_out.i_qpplus1 - 1) * FF_QP2LAMBDA;
+ *(int *)sd = pic_out.i_qpplus1 - 1;
x4->out_frame_count++;
*got_packet = ret;
diff --git a/libavcodec/libxvid.c b/libavcodec/libxvid.c
index 1e8dc5d01..d7327d90a 100644
--- a/libavcodec/libxvid.c
+++ b/libavcodec/libxvid.c
@@ -820,7 +820,7 @@ static int xvid_encode_frame(AVCodecContext *avctx,
AVPacket *pkt,
/* Quant Setting */
if (x->qscale)
- xvid_enc_frame.quant = picture->quality / FF_QP2LAMBDA;
+ xvid_enc_frame.quant = picture->quality;
else
xvid_enc_frame.quant = 0;
@@ -849,13 +849,13 @@ static int xvid_encode_frame(AVCodecContext *avctx,
AVPacket *pkt,
sizeof(int));
if (!sd)
return AVERROR(ENOMEM);
- *(int *)sd = xvid_enc_stats.quant * FF_QP2LAMBDA;
+ *(int *)sd = xvid_enc_stats.quant;
*got_packet = 1;
#if FF_API_CODED_FRAME
FF_DISABLE_DEPRECATION_WARNINGS
- avctx->coded_frame->quality = xvid_enc_stats.quant * FF_QP2LAMBDA;
+ avctx->coded_frame->quality = xvid_enc_stats.quant;
if (xvid_enc_stats.type == XVID_TYPE_PVOP)
avctx->coded_frame->pict_type = AV_PICTURE_TYPE_P;
else if (xvid_enc_stats.type == XVID_TYPE_BVOP)
diff --git a/libavcodec/mpegvideo_enc.c b/libavcodec/mpegvideo_enc.c
index 40c044d70..f5ab4716a 100644
--- a/libavcodec/mpegvideo_enc.c
+++ b/libavcodec/mpegvideo_enc.c
@@ -1323,7 +1323,7 @@ static int estimate_best_b_count(MpegEncContext *s)
goto fail;
s->tmp_frames[0]->pict_type = AV_PICTURE_TYPE_I;
- s->tmp_frames[0]->quality = 1 * FF_QP2LAMBDA;
+ s->tmp_frames[0]->quality = 1;
out_size = encode_frame(c, s->tmp_frames[0]);
if (out_size < 0) {
@@ -1788,7 +1788,7 @@ FF_ENABLE_DEPRECATION_WARNINGS
sizeof(int));
if (!sd)
return AVERROR(ENOMEM);
- *(int *)sd = s->current_picture.f->quality;
+ *(int *)sd = s->current_picture.f->quality / FF_QP2LAMBDA;
if (CONFIG_MJPEG_ENCODER && s->out_format == FMT_MJPEG)
ff_mjpeg_encode_picture_trailer(&s->pb, s->header_bits);
diff --git a/libavcodec/proresenc.c b/libavcodec/proresenc.c
index e4842d299..f13cd1ef0 100644
--- a/libavcodec/proresenc.c
+++ b/libavcodec/proresenc.c
@@ -1185,7 +1185,7 @@ static av_cold int encode_init(AVCodecContext *avctx)
return AVERROR_INVALIDDATA;
}
- ctx->force_quant = avctx->global_quality / FF_QP2LAMBDA;
+ ctx->force_quant = avctx->global_quality;
if (!ctx->force_quant) {
if (!ctx->bits_per_mb) {
for (i = 0; i < NUM_MB_LIMITS - 1; i++)
diff --git a/libavcodec/qsvenc.c b/libavcodec/qsvenc.c
index d680fc8cb..9388d741b 100644
--- a/libavcodec/qsvenc.c
+++ b/libavcodec/qsvenc.c
@@ -433,7 +433,7 @@ static int init_video_param(AVCodecContext *avctx,
QSVEncContext *q)
q->param.mfx.MaxKbps = avctx->rc_max_rate / 1000;
break;
case MFX_RATECONTROL_CQP:
- quant = avctx->global_quality / FF_QP2LAMBDA;
+ quant = avctx->global_quality;
q->param.mfx.QPI = av_clip(quant * fabs(avctx->i_quant_factor) +
avctx->i_quant_offset, 0, 51);
q->param.mfx.QPP = av_clip(quant, 0, 51);
diff --git a/libavcodec/vorbisenc.c b/libavcodec/vorbisenc.c
index 35bdd57fb..b46752d5e 100644
--- a/libavcodec/vorbisenc.c
+++ b/libavcodec/vorbisenc.c
@@ -1179,7 +1179,7 @@ static av_cold int vorbis_encode_init(AVCodecContext
*avctx)
avctx->bit_rate = 0;
if (avctx->flags & AV_CODEC_FLAG_QSCALE)
- venc->quality = avctx->global_quality / (float)FF_QP2LAMBDA;
+ venc->quality = avctx->global_quality;
else
venc->quality = 3.0;
venc->quality *= venc->quality;
diff --git a/libavutil/avutil.h b/libavutil/avutil.h
index 2339fe3c9..496d3a59e 100644
--- a/libavutil/avutil.h
+++ b/libavutil/avutil.h
@@ -220,8 +220,6 @@ enum AVMediaType {
#define FF_QP2LAMBDA 118 ///< factor to convert from H.263 QP to lambda
#define FF_LAMBDA_MAX (256*128-1)
-#define FF_QUALITY_SCALE FF_LAMBDA_SCALE //FIXME maybe remove
-
/**
* @}
* @defgroup lavu_time Timestamp specific
diff --git a/libavutil/frame.h b/libavutil/frame.h
index 4052199fd..0191a9a83 100644
--- a/libavutil/frame.h
+++ b/libavutil/frame.h
@@ -240,7 +240,7 @@ typedef struct AVFrame {
int display_picture_number;
/**
- * quality (between 1 (good) and FF_LAMBDA_MAX (bad))
+ * quality (scale dependent on codec, higher is worse).
*/
int quality;
--
2.11.0
_______________________________________________
libav-devel mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-devel