History

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

Michael Niedermayer committed 11 years ago

Commit c40ecff1 parent a906e8613 files · +65 −46Browse files

Unified · Split

13 files
  1. doc/APIchanges +3 −2
  2. ffmpeg.c +2 −2
  3. libavcodec/avcodec.h +11 −4
  4. libavcodec/avpacket.c +25 −0
  5. libavcodec/dnxhdenc.c +1 −4
  6. libavcodec/internal.h +2 −0
  7. libavcodec/libx264.c +1 −5
  8. libavcodec/libxavs.c +1 −4
  9. libavcodec/libxvid.c +13 −12
  10. libavcodec/mpegvideo_enc.c +1 −5
  11. libavcodec/svq1enc.c +1 −4
  12. libavcodec/version.h +2 −2
  13. libavformat/dump.c +2 −2
doc/APIchanges+3−2
@@ -15,8 +15,9 @@ libavutil: 2014-08-09 · 14 unmodified lines
15 15
16API changes, most recent first:16API changes, most recent first:
17 17
182015-xx-xx - xxxxxxx - lavc 56.33.0 - avcodec.h182015-xx-xx - xxxxxxx - lavc 56.51.100 - avcodec.h
19 Add AV_PKT_DATA_QUALITY_FACTOR to export the quality value of an AVPacket.19 Add AV_PKT_DATA_QUALITY_STATS to export the quality value, PSNR, and pict_type
20 of an AVPacket.
20 21
212015-07-16 - xxxxxxxx - lavc 56.49.100222015-07-16 - xxxxxxxx - lavc 56.49.100
22 Add av_codec_get_codec_properties(), FF_CODEC_PROPERTY_LOSSLESS23 Add av_codec_get_codec_properties(), FF_CODEC_PROPERTY_LOSSLESS
ffmpeg.c+2−2
@@ -669,9 +669,9 @@ static void write_frame(AVFormatContext *s, AVPacket *pkt, OutputStream *ost) · 668 unmodified lines
669 ost->frame_number++;669 ost->frame_number++;
670 }670 }
671 if (avctx->codec_type == AVMEDIA_TYPE_VIDEO) {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 NULL);673 NULL);
674 ost->quality = sd ? *(int *)sd : -1;674 ost->quality = sd ? AV_RL32(sd) : -1;
675 }675 }
676 676
677 if (bsfc)677 if (bsfc)
libavcodec/avcodec.h+11−4
@@ -1055,11 +1055,16 @@ enum AVPacketSideDataType { · 1054 unmodified lines
1055 AV_PKT_DATA_AUDIO_SERVICE_TYPE,1055 AV_PKT_DATA_AUDIO_SERVICE_TYPE,
1056 1056
1057 /**1057 /**
1058 * This side data contains an integer value representing the quality1058 * This side data contains quality related information from the encoder.
1059 * factor of the compressed frame. Allowed range is between 1 (good)1059 * @code
1060 * and FF_LAMBDA_MAX (bad).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 * Recommmends skipping the specified number of samples1070 * Recommmends skipping the specified number of samples
@@ -1126,6 +1131,8 @@ enum AVPacketSideDataType { · 60 unmodified lines
1126 AV_PKT_DATA_METADATA_UPDATE,1131 AV_PKT_DATA_METADATA_UPDATE,
1127};1132};
1128 1133
1134#define AV_PKT_DATA_QUALITY_FACTOR AV_PKT_DATA_QUALITY_STATS //DEPRECATED
1135
1129typedef struct AVPacketSideData {1136typedef struct AVPacketSideData {
1130 uint8_t *data;1137 uint8_t *data;
1131 int size;1138 int size;
libavcodec/avpacket.c+25−0
@@ -602,3 +602,28 @@ void av_packet_rescale_ts(AVPacket *pkt, AVRational src_tb, AVRational dst_tb) · 601 unmodified lines
602 if (pkt->convergence_duration > 0)602 if (pkt->convergence_duration > 0)
603 pkt->convergence_duration = av_rescale_q(pkt->convergence_duration, src_tb, dst_tb);603 pkt->convergence_duration = av_rescale_q(pkt->convergence_duration, src_tb, dst_tb);
604}604}
605
606int 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}
libavcodec/dnxhdenc.c+1−4
@@ -1115,10 +1115,7 @@ FF_DISABLE_DEPRECATION_WARNINGS · 1114 unmodified lines
1115FF_ENABLE_DEPRECATION_WARNINGS1115FF_ENABLE_DEPRECATION_WARNINGS
1116#endif1116#endif
1117 1117
1118 sd = av_packet_new_side_data(pkt, AV_PKT_DATA_QUALITY_FACTOR, sizeof(int));1118 ff_side_data_set_encoder_stats(pkt, ctx->qscale * FF_QP2LAMBDA, NULL, 0, 0);
1119 if (!sd)
1120 return AVERROR(ENOMEM);
1121 *(int *)sd = ctx->qscale * FF_QP2LAMBDA;
1122 1119
1123 pkt->flags |= AV_PKT_FLAG_KEY;1120 pkt->flags |= AV_PKT_FLAG_KEY;
1124 *got_packet = 1;1121 *got_packet = 1;
libavcodec/internal.h+2−0
@@ -298,4 +298,6 @@ int ff_get_format(AVCodecContext *avctx, const enum AVPixelFormat *fmt); · 297 unmodified lines
298 */298 */
299int ff_decode_frame_props(AVCodecContext *avctx, AVFrame *frame);299int ff_decode_frame_props(AVCodecContext *avctx, AVFrame *frame);
300 300
301int ff_side_data_set_encoder_stats(AVPacket *pkt, int quality, int64_t *error, int error_count, int pict_type);
302
301#endif /* AVCODEC_INTERNAL_H */303#endif /* AVCODEC_INTERNAL_H */
libavcodec/libx264.c+1−5
@@ -307,11 +307,7 @@ FF_ENABLE_DEPRECATION_WARNINGS · 306 unmodified lines
307 307
308 pkt->flags |= AV_PKT_FLAG_KEY*pic_out.b_keyframe;308 pkt->flags |= AV_PKT_FLAG_KEY*pic_out.b_keyframe;
309 if (ret) {309 if (ret) {
310 uint8_t *sd = av_packet_new_side_data(pkt, AV_PKT_DATA_QUALITY_FACTOR,310 ff_side_data_set_encoder_stats(pkt, (pic_out.i_qpplus1 - 1) * FF_QP2LAMBDA, NULL, 0, 0);
311 sizeof(int));
312 if (!sd)
313 return AVERROR(ENOMEM);
314 *(int *)sd = (pic_out.i_qpplus1 - 1) * FF_QP2LAMBDA;
315 311
316#if FF_API_CODED_FRAME312#if FF_API_CODED_FRAME
317FF_DISABLE_DEPRECATION_WARNINGS313FF_DISABLE_DEPRECATION_WARNINGS
libavcodec/libxavs.c+1−4
@@ -208,10 +208,7 @@ FF_DISABLE_DEPRECATION_WARNINGS · 207 unmodified lines
208FF_ENABLE_DEPRECATION_WARNINGS208FF_ENABLE_DEPRECATION_WARNINGS
209#endif209#endif
210 210
211 sd = av_packet_new_side_data(pkt, AV_PKT_DATA_QUALITY_FACTOR, sizeof(int));211 ff_side_data_set_encoder_stats(pkt, (pic_out.i_qpplus1 - 1) * FF_QP2LAMBDA, NULL, 0, 0);
212 if (!sd)
213 return AVERROR(ENOMEM);
214 *(int *)sd = (pic_out.i_qpplus1 - 1) * FF_QP2LAMBDA;
215 212
216 x4->out_frame_count++;213 x4->out_frame_count++;
217 *got_packet = ret;214 *got_packet = ret;
libavcodec/libxvid.c+13−12
@@ -771,27 +771,28 @@ static int xvid_encode_frame(AVCodecContext *avctx, AVPacket *pkt, · 770 unmodified lines
771 }771 }
772 772
773 if (xerr > 0) {773 if (xerr > 0) {
774 uint8_t *sd = av_packet_new_side_data(pkt, AV_PKT_DATA_QUALITY_FACTOR,774 int pict_type;
775 sizeof(int));
776 if (!sd)
777 return AVERROR(ENOMEM);
778 *(int *)sd = xvid_enc_stats.quant * FF_QP2LAMBDA;
779 775
780 *got_packet = 1;776 *got_packet = 1;
781 777
782#if FF_API_CODED_FRAME
783FF_DISABLE_DEPRECATION_WARNINGS
784 avctx->coded_frame->quality = xvid_enc_stats.quant * FF_QP2LAMBDA;
785 if (xvid_enc_stats.type == XVID_TYPE_PVOP)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 else if (xvid_enc_stats.type == XVID_TYPE_BVOP)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 else if (xvid_enc_stats.type == XVID_TYPE_SVOP)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 else784 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
788FF_DISABLE_DEPRECATION_WARNINGS
789 avctx->coded_frame->pict_type = pict_type;
790 avctx->coded_frame->quality = xvid_enc_stats.quant * FF_QP2LAMBDA;
793FF_ENABLE_DEPRECATION_WARNINGS791FF_ENABLE_DEPRECATION_WARNINGS
794#endif792#endif
793
794 ff_side_data_set_encoder_stats(pkt, xvid_enc_stats.quant * FF_QP2LAMBDA, NULL, 0, pict_type);
795
795 if (xvid_enc_frame.out_flags & XVID_KEYFRAME) {796 if (xvid_enc_frame.out_flags & XVID_KEYFRAME) {
796#if FF_API_CODED_FRAME797#if FF_API_CODED_FRAME
797FF_DISABLE_DEPRECATION_WARNINGS798FF_DISABLE_DEPRECATION_WARNINGS
libavcodec/mpegvideo_enc.c+1−5
@@ -1786,11 +1786,7 @@ vbv_retry: · 1785 unmodified lines
1786 1786
1787 frame_end(s);1787 frame_end(s);
1788 1788
1789 sd = av_packet_new_side_data(pkt, AV_PKT_DATA_QUALITY_FACTOR,1789 ff_side_data_set_encoder_stats(pkt, s->current_picture.f->quality, NULL, 0, s->pict_type);
1790 sizeof(int));
1791 if (!sd)
1792 return AVERROR(ENOMEM);
1793 *(int *)sd = s->current_picture.f->quality;
1794 1790
1795 if (CONFIG_MJPEG_ENCODER && s->out_format == FMT_MJPEG)1791 if (CONFIG_MJPEG_ENCODER && s->out_format == FMT_MJPEG)
1796 ff_mjpeg_encode_picture_trailer(&s->pb, s->header_bits);1792 ff_mjpeg_encode_picture_trailer(&s->pb, s->header_bits);
libavcodec/svq1enc.c+1−4
@@ -618,10 +618,7 @@ FF_DISABLE_DEPRECATION_WARNINGS · 617 unmodified lines
618FF_ENABLE_DEPRECATION_WARNINGS618FF_ENABLE_DEPRECATION_WARNINGS
619#endif619#endif
620 620
621 sd = av_packet_new_side_data(pkt, AV_PKT_DATA_QUALITY_FACTOR, sizeof(int));621 ff_side_data_set_encoder_stats(pkt, pict->quality, NULL, 0, s->pict_type);
622 if (!sd)
623 return AVERROR(ENOMEM);
624 *(int *)sd = pict->quality;
625 622
626 svq1_write_header(s, s->pict_type);623 svq1_write_header(s, s->pict_type);
627 for (i = 0; i < 3; i++)624 for (i = 0; i < 3; i++)
libavcodec/version.h+2−2
@@ -29,8 +29,8 @@ · 28 unmodified lines
29#include "libavutil/version.h"29#include "libavutil/version.h"
30 30
31#define LIBAVCODEC_VERSION_MAJOR 5631#define LIBAVCODEC_VERSION_MAJOR 56
32#define LIBAVCODEC_VERSION_MINOR 5032#define LIBAVCODEC_VERSION_MINOR 51
33#define LIBAVCODEC_VERSION_MICRO 10133#define LIBAVCODEC_VERSION_MICRO 100
34 34
35#define LIBAVCODEC_VERSION_INT AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \35#define LIBAVCODEC_VERSION_INT AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \
36 LIBAVCODEC_VERSION_MINOR, \36 LIBAVCODEC_VERSION_MINOR, \
libavformat/dump.c+2−2
@@ -377,8 +377,8 @@ static void dump_sidedata(void *ctx, AVStream *st, const char *indent) · 376 unmodified lines
377 av_log(ctx, AV_LOG_INFO, "audio service type: ");377 av_log(ctx, AV_LOG_INFO, "audio service type: ");
378 dump_audioservicetype(ctx, &sd);378 dump_audioservicetype(ctx, &sd);
379 break;379 break;
380 case AV_PKT_DATA_QUALITY_FACTOR:380 case AV_PKT_DATA_QUALITY_STATS:
381 av_log(ctx, AV_LOG_INFO, "quality factor: %d", *(int *)sd.data);381 av_log(ctx, AV_LOG_INFO, "quality factor: %d", AV_RL32(sd.data));
382 break;382 break;
383 default:383 default:
384 av_log(ctx, AV_LOG_WARNING,384 av_log(ctx, AV_LOG_WARNING,

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t