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
1515
1616 API changes, most recent first:
1717
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.
2021
2122 2015-07-16 - xxxxxxxx - lavc 56.49.100
2223 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
669669 ost->frame_number++;
670670 }
671671 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,
673673 NULL);
674− ost->quality = sd ? *(int *)sd : -1;
674+ ost->quality = sd ? AV_RL32(sd) : -1;
675675 }
676676
677677 if (bsfc)
libavcodec/avcodec.h+11−4
@@ -1055,11 +1055,16 @@ enum AVPacketSideDataType { · 1054 unmodified lines
10551055 AV_PKT_DATA_AUDIO_SERVICE_TYPE,
10561056
10571057 /**
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
10611066 */
1062− AV_PKT_DATA_QUALITY_FACTOR,
1067+ AV_PKT_DATA_QUALITY_STATS,
10631068
10641069 /**
10651070 * Recommmends skipping the specified number of samples
@@ -1126,6 +1131,8 @@ enum AVPacketSideDataType { · 60 unmodified lines
11261131 AV_PKT_DATA_METADATA_UPDATE,
11271132 };
11281133
1134+#define AV_PKT_DATA_QUALITY_FACTOR AV_PKT_DATA_QUALITY_STATS //DEPRECATED
1135+
11291136 typedef struct AVPacketSideData {
11301137 uint8_t *data;
11311138 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
602602 if (pkt->convergence_duration > 0)
603603 pkt->convergence_duration = av_rescale_q(pkt->convergence_duration, src_tb, dst_tb);
604604 }
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+}
libavcodec/dnxhdenc.c+1−4
@@ -1115,10 +1115,7 @@ FF_DISABLE_DEPRECATION_WARNINGS · 1114 unmodified lines
11151115 FF_ENABLE_DEPRECATION_WARNINGS
11161116 #endif
11171117
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);
11221119
11231120 pkt->flags |= AV_PKT_FLAG_KEY;
11241121 *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
298298 */
299299 int ff_decode_frame_props(AVCodecContext *avctx, AVFrame *frame);
300300
301+int ff_side_data_set_encoder_stats(AVPacket *pkt, int quality, int64_t *error, int error_count, int pict_type);
302+
301303 #endif /* AVCODEC_INTERNAL_H */
libavcodec/libx264.c+1−5
@@ -307,11 +307,7 @@ FF_ENABLE_DEPRECATION_WARNINGS · 306 unmodified lines
307307
308308 pkt->flags |= AV_PKT_FLAG_KEY*pic_out.b_keyframe;
309309 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);
315311
316312 #if FF_API_CODED_FRAME
317313 FF_DISABLE_DEPRECATION_WARNINGS
libavcodec/libxavs.c+1−4
@@ -208,10 +208,7 @@ FF_DISABLE_DEPRECATION_WARNINGS · 207 unmodified lines
208208 FF_ENABLE_DEPRECATION_WARNINGS
209209 #endif
210210
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);
215212
216213 x4->out_frame_count++;
217214 *got_packet = ret;
libavcodec/libxvid.c+13−12
@@ -771,27 +771,28 @@ static int xvid_encode_frame(AVCodecContext *avctx, AVPacket *pkt, · 770 unmodified lines
771771 }
772772
773773 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;
779775
780776 *got_packet = 1;
781777
782−#if FF_API_CODED_FRAME
783−FF_DISABLE_DEPRECATION_WARNINGS
784− avctx->coded_frame->quality = xvid_enc_stats.quant * FF_QP2LAMBDA;
785778 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;
787780 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;
789782 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;
791784 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;
793791 FF_ENABLE_DEPRECATION_WARNINGS
794792 #endif
793+
794+ ff_side_data_set_encoder_stats(pkt, xvid_enc_stats.quant * FF_QP2LAMBDA, NULL, 0, pict_type);
795+
795796 if (xvid_enc_frame.out_flags & XVID_KEYFRAME) {
796797 #if FF_API_CODED_FRAME
797798 FF_DISABLE_DEPRECATION_WARNINGS
libavcodec/mpegvideo_enc.c+1−5
@@ -1786,11 +1786,7 @@ vbv_retry: · 1785 unmodified lines
17861786
17871787 frame_end(s);
17881788
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);
17941790
17951791 if (CONFIG_MJPEG_ENCODER && s->out_format == FMT_MJPEG)
17961792 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
618618 FF_ENABLE_DEPRECATION_WARNINGS
619619 #endif
620620
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);
625622
626623 svq1_write_header(s, s->pict_type);
627624 for (i = 0; i < 3; i++)
libavcodec/version.h+2−2
@@ -29,8 +29,8 @@ · 28 unmodified lines
2929 #include "libavutil/version.h"
3030
3131 #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
3434
3535 #define LIBAVCODEC_VERSION_INT AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \
3636 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
377377 av_log(ctx, AV_LOG_INFO, "audio service type: ");
378378 dump_audioservicetype(ctx, &sd);
379379 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));
382382 break;
383383 default:
384384 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