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
Unified · Split
| @@ -15,8 +15,9 @@ libavutil: 2014-08-09 · 14 unmodified lines | ||
| 15 | 15 | |
| 16 | 16 | API changes, most recent first: |
| 17 | 17 | |
| 18 | −2015-xx-xx - xxxxxxx - lavc 56.33.0 - avcodec.h | |
| 19 | − Add AV_PKT_DATA_QUALITY_FACTOR to export the quality value of an AVPacket. | |
| 18 | +2015-xx-xx - xxxxxxx - lavc 56.51.100 - avcodec.h | |
| 19 | + Add AV_PKT_DATA_QUALITY_STATS to export the quality value, PSNR, and pict_type | |
| 20 | + of an AVPacket. | |
| 20 | 21 | |
| 21 | 22 | 2015-07-16 - xxxxxxxx - lavc 56.49.100 |
| 22 | 23 | Add av_codec_get_codec_properties(), FF_CODEC_PROPERTY_LOSSLESS |
| @@ -669,9 +669,9 @@ static void write_frame(AVFormatContext *s, AVPacket *pkt, OutputStream *ost) · 668 unmodified lines | ||
| 669 | 669 | ost->frame_number++; |
| 670 | 670 | } |
| 671 | 671 | if (avctx->codec_type == AVMEDIA_TYPE_VIDEO) { |
| 672 | − uint8_t *sd = av_packet_get_side_data(pkt, AV_PKT_DATA_QUALITY_FACTOR, | |
| 672 | + uint8_t *sd = av_packet_get_side_data(pkt, AV_PKT_DATA_QUALITY_STATS, | |
| 673 | 673 | NULL); |
| 674 | − ost->quality = sd ? *(int *)sd : -1; | |
| 674 | + ost->quality = sd ? AV_RL32(sd) : -1; | |
| 675 | 675 | } |
| 676 | 676 | |
| 677 | 677 | if (bsfc) |
| @@ -1055,11 +1055,16 @@ enum AVPacketSideDataType { · 1054 unmodified lines | ||
| 1055 | 1055 | AV_PKT_DATA_AUDIO_SERVICE_TYPE, |
| 1056 | 1056 | |
| 1057 | 1057 | /** |
| 1058 | − * This side data contains an integer value representing the quality | |
| 1059 | − * factor of the compressed frame. Allowed range is between 1 (good) | |
| 1060 | − * and FF_LAMBDA_MAX (bad). | |
| 1058 | + * This side data contains quality related information from the encoder. | |
| 1059 | + * @code | |
| 1060 | + * u32le quality factor of the compressed frame. Allowed range is between 1 (good) and FF_LAMBDA_MAX (bad). | |
| 1061 | + * u8 picture type | |
| 1062 | + * u8 error count | |
| 1063 | + * u16 reserved | |
| 1064 | + * u64le[error count] sum of squared differences between encoder in and output | |
| 1065 | + * @endcode | |
| 1061 | 1066 | */ |
| 1062 | − AV_PKT_DATA_QUALITY_FACTOR, | |
| 1067 | + AV_PKT_DATA_QUALITY_STATS, | |
| 1063 | 1068 | |
| 1064 | 1069 | /** |
| 1065 | 1070 | * Recommmends skipping the specified number of samples |
| @@ -1126,6 +1131,8 @@ enum AVPacketSideDataType { · 60 unmodified lines | ||
| 1126 | 1131 | AV_PKT_DATA_METADATA_UPDATE, |
| 1127 | 1132 | }; |
| 1128 | 1133 | |
| 1134 | +#define AV_PKT_DATA_QUALITY_FACTOR AV_PKT_DATA_QUALITY_STATS //DEPRECATED | |
| 1135 | + | |
| 1129 | 1136 | typedef struct AVPacketSideData { |
| 1130 | 1137 | uint8_t *data; |
| 1131 | 1138 | int size; |
| @@ -602,3 +602,28 @@ void av_packet_rescale_ts(AVPacket *pkt, AVRational src_tb, AVRational dst_tb) · 601 unmodified lines | ||
| 602 | 602 | if (pkt->convergence_duration > 0) |
| 603 | 603 | pkt->convergence_duration = av_rescale_q(pkt->convergence_duration, src_tb, dst_tb); |
| 604 | 604 | } |
| 605 | + | |
| 606 | +int ff_side_data_set_encoder_stats(AVPacket *pkt, int quality, int64_t *error, int error_count, int pict_type) | |
| 607 | +{ | |
| 608 | + uint8_t *side_data; | |
| 609 | + int side_data_size; | |
| 610 | + int i; | |
| 611 | + | |
| 612 | + side_data = av_packet_get_side_data(pkt, AV_PKT_DATA_QUALITY_STATS, &side_data_size); | |
| 613 | + if (!side_data) { | |
| 614 | + side_data_size = 4+4+8*error_count; | |
| 615 | + side_data = av_packet_new_side_data(pkt, AV_PKT_DATA_QUALITY_STATS, | |
| 616 | + side_data_size); | |
| 617 | + } | |
| 618 | + | |
| 619 | + if (!side_data || side_data_size < 4+4+8*error_count) | |
| 620 | + return AVERROR(ENOMEM); | |
| 621 | + | |
| 622 | + AV_WL32(side_data , quality ); | |
| 623 | + side_data[4] = pict_type; | |
| 624 | + side_data[5] = error_count; | |
| 625 | + for (i = 0; i<error_count; i++) | |
| 626 | + AV_WL64(side_data+8 + 8*i , error[i]); | |
| 627 | + | |
| 628 | + return 0; | |
| 629 | +} | |
| @@ -1115,10 +1115,7 @@ FF_DISABLE_DEPRECATION_WARNINGS · 1114 unmodified lines | ||
| 1115 | 1115 | FF_ENABLE_DEPRECATION_WARNINGS |
| 1116 | 1116 | #endif |
| 1117 | 1117 | |
| 1118 | − sd = av_packet_new_side_data(pkt, AV_PKT_DATA_QUALITY_FACTOR, sizeof(int)); | |
| 1119 | − if (!sd) | |
| 1120 | − return AVERROR(ENOMEM); | |
| 1121 | − *(int *)sd = ctx->qscale * FF_QP2LAMBDA; | |
| 1118 | + ff_side_data_set_encoder_stats(pkt, ctx->qscale * FF_QP2LAMBDA, NULL, 0, 0); | |
| 1122 | 1119 | |
| 1123 | 1120 | pkt->flags |= AV_PKT_FLAG_KEY; |
| 1124 | 1121 | *got_packet = 1; |
| @@ -298,4 +298,6 @@ int ff_get_format(AVCodecContext *avctx, const enum AVPixelFormat *fmt); · 297 unmodified lines | ||
| 298 | 298 | */ |
| 299 | 299 | int ff_decode_frame_props(AVCodecContext *avctx, AVFrame *frame); |
| 300 | 300 | |
| 301 | +int ff_side_data_set_encoder_stats(AVPacket *pkt, int quality, int64_t *error, int error_count, int pict_type); | |
| 302 | + | |
| 301 | 303 | #endif /* AVCODEC_INTERNAL_H */ |
| @@ -307,11 +307,7 @@ FF_ENABLE_DEPRECATION_WARNINGS · 306 unmodified lines | ||
| 307 | 307 | |
| 308 | 308 | pkt->flags |= AV_PKT_FLAG_KEY*pic_out.b_keyframe; |
| 309 | 309 | if (ret) { |
| 310 | − uint8_t *sd = av_packet_new_side_data(pkt, AV_PKT_DATA_QUALITY_FACTOR, | |
| 311 | − sizeof(int)); | |
| 312 | − if (!sd) | |
| 313 | − return AVERROR(ENOMEM); | |
| 314 | − *(int *)sd = (pic_out.i_qpplus1 - 1) * FF_QP2LAMBDA; | |
| 310 | + ff_side_data_set_encoder_stats(pkt, (pic_out.i_qpplus1 - 1) * FF_QP2LAMBDA, NULL, 0, 0); | |
| 315 | 311 | |
| 316 | 312 | #if FF_API_CODED_FRAME |
| 317 | 313 | FF_DISABLE_DEPRECATION_WARNINGS |
| @@ -208,10 +208,7 @@ FF_DISABLE_DEPRECATION_WARNINGS · 207 unmodified lines | ||
| 208 | 208 | FF_ENABLE_DEPRECATION_WARNINGS |
| 209 | 209 | #endif |
| 210 | 210 | |
| 211 | − sd = av_packet_new_side_data(pkt, AV_PKT_DATA_QUALITY_FACTOR, sizeof(int)); | |
| 212 | − if (!sd) | |
| 213 | − return AVERROR(ENOMEM); | |
| 214 | − *(int *)sd = (pic_out.i_qpplus1 - 1) * FF_QP2LAMBDA; | |
| 211 | + ff_side_data_set_encoder_stats(pkt, (pic_out.i_qpplus1 - 1) * FF_QP2LAMBDA, NULL, 0, 0); | |
| 215 | 212 | |
| 216 | 213 | x4->out_frame_count++; |
| 217 | 214 | *got_packet = ret; |
| @@ -771,27 +771,28 @@ static int xvid_encode_frame(AVCodecContext *avctx, AVPacket *pkt, · 770 unmodified lines | ||
| 771 | 771 | } |
| 772 | 772 | |
| 773 | 773 | if (xerr > 0) { |
| 774 | − uint8_t *sd = av_packet_new_side_data(pkt, AV_PKT_DATA_QUALITY_FACTOR, | |
| 775 | − sizeof(int)); | |
| 776 | − if (!sd) | |
| 777 | − return AVERROR(ENOMEM); | |
| 778 | − *(int *)sd = xvid_enc_stats.quant * FF_QP2LAMBDA; | |
| 774 | + int pict_type; | |
| 779 | 775 | |
| 780 | 776 | *got_packet = 1; |
| 781 | 777 | |
| 782 | −#if FF_API_CODED_FRAME | |
| 783 | −FF_DISABLE_DEPRECATION_WARNINGS | |
| 784 | − avctx->coded_frame->quality = xvid_enc_stats.quant * FF_QP2LAMBDA; | |
| 785 | 778 | if (xvid_enc_stats.type == XVID_TYPE_PVOP) |
| 786 | − avctx->coded_frame->pict_type = AV_PICTURE_TYPE_P; | |
| 779 | + pict_type = AV_PICTURE_TYPE_P; | |
| 787 | 780 | else if (xvid_enc_stats.type == XVID_TYPE_BVOP) |
| 788 | − avctx->coded_frame->pict_type = AV_PICTURE_TYPE_B; | |
| 781 | + pict_type = AV_PICTURE_TYPE_B; | |
| 789 | 782 | else if (xvid_enc_stats.type == XVID_TYPE_SVOP) |
| 790 | − avctx->coded_frame->pict_type = AV_PICTURE_TYPE_S; | |
| 783 | + pict_type = AV_PICTURE_TYPE_S; | |
| 791 | 784 | else |
| 792 | − avctx->coded_frame->pict_type = AV_PICTURE_TYPE_I; | |
| 785 | + pict_type = AV_PICTURE_TYPE_I; | |
| 786 | + | |
| 787 | +#if FF_API_CODED_FRAME | |
| 788 | +FF_DISABLE_DEPRECATION_WARNINGS | |
| 789 | + avctx->coded_frame->pict_type = pict_type; | |
| 790 | + avctx->coded_frame->quality = xvid_enc_stats.quant * FF_QP2LAMBDA; | |
| 793 | 791 | FF_ENABLE_DEPRECATION_WARNINGS |
| 794 | 792 | #endif |
| 793 | + | |
| 794 | + ff_side_data_set_encoder_stats(pkt, xvid_enc_stats.quant * FF_QP2LAMBDA, NULL, 0, pict_type); | |
| 795 | + | |
| 795 | 796 | if (xvid_enc_frame.out_flags & XVID_KEYFRAME) { |
| 796 | 797 | #if FF_API_CODED_FRAME |
| 797 | 798 | FF_DISABLE_DEPRECATION_WARNINGS |
| @@ -1786,11 +1786,7 @@ vbv_retry: · 1785 unmodified lines | ||
| 1786 | 1786 | |
| 1787 | 1787 | frame_end(s); |
| 1788 | 1788 | |
| 1789 | − sd = av_packet_new_side_data(pkt, AV_PKT_DATA_QUALITY_FACTOR, | |
| 1790 | − sizeof(int)); | |
| 1791 | − if (!sd) | |
| 1792 | − return AVERROR(ENOMEM); | |
| 1793 | − *(int *)sd = s->current_picture.f->quality; | |
| 1789 | + ff_side_data_set_encoder_stats(pkt, s->current_picture.f->quality, NULL, 0, s->pict_type); | |
| 1794 | 1790 | |
| 1795 | 1791 | if (CONFIG_MJPEG_ENCODER && s->out_format == FMT_MJPEG) |
| 1796 | 1792 | ff_mjpeg_encode_picture_trailer(&s->pb, s->header_bits); |
| @@ -618,10 +618,7 @@ FF_DISABLE_DEPRECATION_WARNINGS · 617 unmodified lines | ||
| 618 | 618 | FF_ENABLE_DEPRECATION_WARNINGS |
| 619 | 619 | #endif |
| 620 | 620 | |
| 621 | − sd = av_packet_new_side_data(pkt, AV_PKT_DATA_QUALITY_FACTOR, sizeof(int)); | |
| 622 | − if (!sd) | |
| 623 | − return AVERROR(ENOMEM); | |
| 624 | − *(int *)sd = pict->quality; | |
| 621 | + ff_side_data_set_encoder_stats(pkt, pict->quality, NULL, 0, s->pict_type); | |
| 625 | 622 | |
| 626 | 623 | svq1_write_header(s, s->pict_type); |
| 627 | 624 | for (i = 0; i < 3; i++) |
| @@ -29,8 +29,8 @@ · 28 unmodified lines | ||
| 29 | 29 | #include "libavutil/version.h" |
| 30 | 30 | |
| 31 | 31 | #define LIBAVCODEC_VERSION_MAJOR 56 |
| 32 | −#define LIBAVCODEC_VERSION_MINOR 50 | |
| 33 | −#define LIBAVCODEC_VERSION_MICRO 101 | |
| 32 | +#define LIBAVCODEC_VERSION_MINOR 51 | |
| 33 | +#define LIBAVCODEC_VERSION_MICRO 100 | |
| 34 | 34 | |
| 35 | 35 | #define LIBAVCODEC_VERSION_INT AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \ |
| 36 | 36 | LIBAVCODEC_VERSION_MINOR, \ |
| @@ -377,8 +377,8 @@ static void dump_sidedata(void *ctx, AVStream *st, const char *indent) · 376 unmodified lines | ||
| 377 | 377 | av_log(ctx, AV_LOG_INFO, "audio service type: "); |
| 378 | 378 | dump_audioservicetype(ctx, &sd); |
| 379 | 379 | break; |
| 380 | − case AV_PKT_DATA_QUALITY_FACTOR: | |
| 381 | − av_log(ctx, AV_LOG_INFO, "quality factor: %d", *(int *)sd.data); | |
| 380 | + case AV_PKT_DATA_QUALITY_STATS: | |
| 381 | + av_log(ctx, AV_LOG_INFO, "quality factor: %d", AV_RL32(sd.data)); | |
| 382 | 382 | break; |
| 383 | 383 | default: |
| 384 | 384 | av_log(ctx, AV_LOG_WARNING, |