Browse Source

Replace AV_PKT_DATA_QUALITY_FACTOR by AV_PKT_DATA_QUALITY_STATS

The stats are a superset of the quality factor, also allowing the picture type and encoder "PSNR" stats to be exported
This also replaces the native by fixed little endian order for the affected side data

AV_PKT_DATA_QUALITY_FACTOR is left as a synonym of AV_PKT_DATA_QUALITY_STATS

Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
tags/n2.8
Michael Niedermayer 10 years ago
parent
commit
c40ecffd31
13 changed files with 65 additions and 46 deletions
  1. +3
    -2
      doc/APIchanges
  2. +2
    -2
      ffmpeg.c
  3. +11
    -4
      libavcodec/avcodec.h
  4. +25
    -0
      libavcodec/avpacket.c
  5. +1
    -4
      libavcodec/dnxhdenc.c
  6. +2
    -0
      libavcodec/internal.h
  7. +1
    -5
      libavcodec/libx264.c
  8. +1
    -4
      libavcodec/libxavs.c
  9. +13
    -12
      libavcodec/libxvid.c
  10. +1
    -5
      libavcodec/mpegvideo_enc.c
  11. +1
    -4
      libavcodec/svq1enc.c
  12. +2
    -2
      libavcodec/version.h
  13. +2
    -2
      libavformat/dump.c

+ 3
- 2
doc/APIchanges View File

@@ -15,8 +15,9 @@ libavutil: 2014-08-09

API changes, most recent first:

2015-xx-xx - xxxxxxx - lavc 56.33.0 - avcodec.h
Add AV_PKT_DATA_QUALITY_FACTOR to export the quality value of an AVPacket.
2015-xx-xx - xxxxxxx - lavc 56.51.100 - avcodec.h
Add AV_PKT_DATA_QUALITY_STATS to export the quality value, PSNR, and pict_type
of an AVPacket.

2015-07-16 - xxxxxxxx - lavc 56.49.100
Add av_codec_get_codec_properties(), FF_CODEC_PROPERTY_LOSSLESS


+ 2
- 2
ffmpeg.c View File

@@ -669,9 +669,9 @@ static void write_frame(AVFormatContext *s, AVPacket *pkt, OutputStream *ost)
ost->frame_number++;
}
if (avctx->codec_type == AVMEDIA_TYPE_VIDEO) {
uint8_t *sd = av_packet_get_side_data(pkt, AV_PKT_DATA_QUALITY_FACTOR,
uint8_t *sd = av_packet_get_side_data(pkt, AV_PKT_DATA_QUALITY_STATS,
NULL);
ost->quality = sd ? *(int *)sd : -1;
ost->quality = sd ? AV_RL32(sd) : -1;
}

if (bsfc)


+ 11
- 4
libavcodec/avcodec.h View File

@@ -1055,11 +1055,16 @@ enum AVPacketSideDataType {
AV_PKT_DATA_AUDIO_SERVICE_TYPE,

/**
* This side data contains an integer value representing the quality
* factor of the compressed frame. Allowed range is between 1 (good)
* and FF_LAMBDA_MAX (bad).
* This side data contains quality related information from the encoder.
* @code
* u32le quality factor of the compressed frame. Allowed range is between 1 (good) and FF_LAMBDA_MAX (bad).
* u8 picture type
* u8 error count
* u16 reserved
* u64le[error count] sum of squared differences between encoder in and output
* @endcode
*/
AV_PKT_DATA_QUALITY_FACTOR,
AV_PKT_DATA_QUALITY_STATS,

/**
* Recommmends skipping the specified number of samples
@@ -1126,6 +1131,8 @@ enum AVPacketSideDataType {
AV_PKT_DATA_METADATA_UPDATE,
};

#define AV_PKT_DATA_QUALITY_FACTOR AV_PKT_DATA_QUALITY_STATS //DEPRECATED

typedef struct AVPacketSideData {
uint8_t *data;
int size;


+ 25
- 0
libavcodec/avpacket.c View File

@@ -602,3 +602,28 @@ void av_packet_rescale_ts(AVPacket *pkt, AVRational src_tb, AVRational dst_tb)
if (pkt->convergence_duration > 0)
pkt->convergence_duration = av_rescale_q(pkt->convergence_duration, src_tb, dst_tb);
}

int ff_side_data_set_encoder_stats(AVPacket *pkt, int quality, int64_t *error, int error_count, int pict_type)
{
uint8_t *side_data;
int side_data_size;
int i;

side_data = av_packet_get_side_data(pkt, AV_PKT_DATA_QUALITY_STATS, &side_data_size);
if (!side_data) {
side_data_size = 4+4+8*error_count;
side_data = av_packet_new_side_data(pkt, AV_PKT_DATA_QUALITY_STATS,
side_data_size);
}

if (!side_data || side_data_size < 4+4+8*error_count)
return AVERROR(ENOMEM);

AV_WL32(side_data , quality );
side_data[4] = pict_type;
side_data[5] = error_count;
for (i = 0; i<error_count; i++)
AV_WL64(side_data+8 + 8*i , error[i]);

return 0;
}

+ 1
- 4
libavcodec/dnxhdenc.c View File

@@ -1115,10 +1115,7 @@ FF_DISABLE_DEPRECATION_WARNINGS
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;
ff_side_data_set_encoder_stats(pkt, ctx->qscale * FF_QP2LAMBDA, NULL, 0, 0);

pkt->flags |= AV_PKT_FLAG_KEY;
*got_packet = 1;


+ 2
- 0
libavcodec/internal.h View File

@@ -298,4 +298,6 @@ int ff_get_format(AVCodecContext *avctx, const enum AVPixelFormat *fmt);
*/
int ff_decode_frame_props(AVCodecContext *avctx, AVFrame *frame);

int ff_side_data_set_encoder_stats(AVPacket *pkt, int quality, int64_t *error, int error_count, int pict_type);

#endif /* AVCODEC_INTERNAL_H */

+ 1
- 5
libavcodec/libx264.c View File

@@ -307,11 +307,7 @@ FF_ENABLE_DEPRECATION_WARNINGS

pkt->flags |= AV_PKT_FLAG_KEY*pic_out.b_keyframe;
if (ret) {
uint8_t *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;
ff_side_data_set_encoder_stats(pkt, (pic_out.i_qpplus1 - 1) * FF_QP2LAMBDA, NULL, 0, 0);

#if FF_API_CODED_FRAME
FF_DISABLE_DEPRECATION_WARNINGS


+ 1
- 4
libavcodec/libxavs.c View File

@@ -208,10 +208,7 @@ FF_DISABLE_DEPRECATION_WARNINGS
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;
ff_side_data_set_encoder_stats(pkt, (pic_out.i_qpplus1 - 1) * FF_QP2LAMBDA, NULL, 0, 0);

x4->out_frame_count++;
*got_packet = ret;


+ 13
- 12
libavcodec/libxvid.c View File

@@ -771,27 +771,28 @@ static int xvid_encode_frame(AVCodecContext *avctx, AVPacket *pkt,
}

if (xerr > 0) {
uint8_t *sd = av_packet_new_side_data(pkt, AV_PKT_DATA_QUALITY_FACTOR,
sizeof(int));
if (!sd)
return AVERROR(ENOMEM);
*(int *)sd = xvid_enc_stats.quant * FF_QP2LAMBDA;
int pict_type;

*got_packet = 1;

#if FF_API_CODED_FRAME
FF_DISABLE_DEPRECATION_WARNINGS
avctx->coded_frame->quality = xvid_enc_stats.quant * FF_QP2LAMBDA;
if (xvid_enc_stats.type == XVID_TYPE_PVOP)
avctx->coded_frame->pict_type = AV_PICTURE_TYPE_P;
pict_type = AV_PICTURE_TYPE_P;
else if (xvid_enc_stats.type == XVID_TYPE_BVOP)
avctx->coded_frame->pict_type = AV_PICTURE_TYPE_B;
pict_type = AV_PICTURE_TYPE_B;
else if (xvid_enc_stats.type == XVID_TYPE_SVOP)
avctx->coded_frame->pict_type = AV_PICTURE_TYPE_S;
pict_type = AV_PICTURE_TYPE_S;
else
avctx->coded_frame->pict_type = AV_PICTURE_TYPE_I;
pict_type = AV_PICTURE_TYPE_I;

#if FF_API_CODED_FRAME
FF_DISABLE_DEPRECATION_WARNINGS
avctx->coded_frame->pict_type = pict_type;
avctx->coded_frame->quality = xvid_enc_stats.quant * FF_QP2LAMBDA;
FF_ENABLE_DEPRECATION_WARNINGS
#endif

ff_side_data_set_encoder_stats(pkt, xvid_enc_stats.quant * FF_QP2LAMBDA, NULL, 0, pict_type);

if (xvid_enc_frame.out_flags & XVID_KEYFRAME) {
#if FF_API_CODED_FRAME
FF_DISABLE_DEPRECATION_WARNINGS


+ 1
- 5
libavcodec/mpegvideo_enc.c View File

@@ -1786,11 +1786,7 @@ vbv_retry:

frame_end(s);

sd = av_packet_new_side_data(pkt, AV_PKT_DATA_QUALITY_FACTOR,
sizeof(int));
if (!sd)
return AVERROR(ENOMEM);
*(int *)sd = s->current_picture.f->quality;
ff_side_data_set_encoder_stats(pkt, s->current_picture.f->quality, NULL, 0, s->pict_type);

if (CONFIG_MJPEG_ENCODER && s->out_format == FMT_MJPEG)
ff_mjpeg_encode_picture_trailer(&s->pb, s->header_bits);


+ 1
- 4
libavcodec/svq1enc.c View File

@@ -618,10 +618,7 @@ FF_DISABLE_DEPRECATION_WARNINGS
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 = pict->quality;
ff_side_data_set_encoder_stats(pkt, pict->quality, NULL, 0, s->pict_type);

svq1_write_header(s, s->pict_type);
for (i = 0; i < 3; i++)


+ 2
- 2
libavcodec/version.h View File

@@ -29,8 +29,8 @@
#include "libavutil/version.h"

#define LIBAVCODEC_VERSION_MAJOR 56
#define LIBAVCODEC_VERSION_MINOR 50
#define LIBAVCODEC_VERSION_MICRO 101
#define LIBAVCODEC_VERSION_MINOR 51
#define LIBAVCODEC_VERSION_MICRO 100

#define LIBAVCODEC_VERSION_INT AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \
LIBAVCODEC_VERSION_MINOR, \


+ 2
- 2
libavformat/dump.c View File

@@ -377,8 +377,8 @@ static void dump_sidedata(void *ctx, AVStream *st, const char *indent)
av_log(ctx, AV_LOG_INFO, "audio service type: ");
dump_audioservicetype(ctx, &sd);
break;
case AV_PKT_DATA_QUALITY_FACTOR:
av_log(ctx, AV_LOG_INFO, "quality factor: %d", *(int *)sd.data);
case AV_PKT_DATA_QUALITY_STATS:
av_log(ctx, AV_LOG_INFO, "quality factor: %d", AV_RL32(sd.data));
break;
default:
av_log(ctx, AV_LOG_WARNING,


Loading…
Cancel
Save