* commit '5d3addb937946eca5391e40b5e6308e74ac6f77b': Add a quality factor packet side data Conflicts: doc/APIchanges ffmpeg.c libavcodec/avcodec.h libavcodec/mpegvideo_enc.c libavcodec/version.h
Unified · Split
| @@ -15,6 +15,9 @@ libavutil: 2014-08-09 · 14 unmodified lines | |||
| 15 | 15 | ||
| 16 | API changes, most recent first: | 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. | ||
| 20 | |||
| 18 | 2015-07-16 - xxxxxxxx - lavc 56.49.100 | 21 | 2015-07-16 - xxxxxxxx - lavc 56.49.100 |
| 19 | Add av_codec_get_codec_properties(), FF_CODEC_PROPERTY_LOSSLESS | 22 | Add av_codec_get_codec_properties(), FF_CODEC_PROPERTY_LOSSLESS |
| 20 | and FF_CODEC_PROPERTY_CLOSED_CAPTIONS | 23 | and FF_CODEC_PROPERTY_CLOSED_CAPTIONS |
| @@ -667,6 +667,11 @@ static void write_frame(AVFormatContext *s, AVPacket *pkt, OutputStream *ost) · 666 unmodified lines | |||
| 667 | } | 667 | } |
| 668 | ost->frame_number++; | 668 | ost->frame_number++; |
| 669 | } | 669 | } |
| 670 | if (avctx->codec_type == AVMEDIA_TYPE_VIDEO) { | ||
| 671 | uint8_t *sd = av_packet_get_side_data(pkt, AV_PKT_DATA_QUALITY_FACTOR, | ||
| 672 | NULL); | ||
| 673 | ost->quality = sd ? *(int *)sd : -1; | ||
| 674 | } | ||
| 670 | 675 | ||
| 671 | if (bsfc) | 676 | if (bsfc) |
| 672 | av_packet_split_side_data(pkt); | 677 | av_packet_split_side_data(pkt); |
| @@ -1257,7 +1262,8 @@ static void do_video_stats(OutputStream *ost, int frame_size) · 584 unmodified lines | |||
| 1257 | enc = ost->enc_ctx; | 1262 | enc = ost->enc_ctx; |
| 1258 | if (enc->codec_type == AVMEDIA_TYPE_VIDEO) { | 1263 | if (enc->codec_type == AVMEDIA_TYPE_VIDEO) { |
| 1259 | frame_number = ost->st->nb_frames; | 1264 | frame_number = ost->st->nb_frames; |
| 1260 | fprintf(vstats_file, "frame= %5d q= %2.1f ", frame_number, enc->coded_frame ? enc->coded_frame->quality / (float)FF_QP2LAMBDA : 0); | 1265 | fprintf(vstats_file, "frame= %5d q= %2.1f ", frame_number, |
| 1266 | ost->quality / (float)FF_QP2LAMBDA); | ||
| 1261 | if (enc->coded_frame && (enc->flags&CODEC_FLAG_PSNR)) | 1267 | if (enc->coded_frame && (enc->flags&CODEC_FLAG_PSNR)) |
| 1262 | fprintf(vstats_file, "PSNR= %6.2f ", psnr(enc->coded_frame->error[0] / (enc->width * enc->height * 255.0 * 255.0))); | 1268 | fprintf(vstats_file, "PSNR= %6.2f ", psnr(enc->coded_frame->error[0] / (enc->width * enc->height * 255.0 * 255.0))); |
| 1263 | 1269 | ||
| @@ -1548,8 +1554,9 @@ static void print_report(int is_last_report, int64_t timer_start, int64_t cur_ti · 284 unmodified lines | |||
| 1548 | float q = -1; | 1554 | float q = -1; |
| 1549 | ost = output_streams[i]; | 1555 | ost = output_streams[i]; |
| 1550 | enc = ost->enc_ctx; | 1556 | enc = ost->enc_ctx; |
| 1551 | if (!ost->stream_copy && enc->coded_frame) | 1557 | if (!ost->stream_copy) |
| 1552 | q = enc->coded_frame->quality / (float)FF_QP2LAMBDA; | 1558 | q = ost->quality / (float) FF_QP2LAMBDA; |
| 1559 | |||
| 1553 | if (vid && enc->codec_type == AVMEDIA_TYPE_VIDEO) { | 1560 | if (vid && enc->codec_type == AVMEDIA_TYPE_VIDEO) { |
| 1554 | snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), "q=%2.1f ", q); | 1561 | snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), "q=%2.1f ", q); |
| 1555 | av_bprintf(&buf_script, "stream_%d_%d_q=%.1f\n", | 1562 | av_bprintf(&buf_script, "stream_%d_%d_q=%.1f\n", |
| @@ -456,6 +456,9 @@ typedef struct OutputStream { · 455 unmodified lines | |||
| 456 | // number of frames/samples sent to the encoder | 456 | // number of frames/samples sent to the encoder |
| 457 | uint64_t frames_encoded; | 457 | uint64_t frames_encoded; |
| 458 | uint64_t samples_encoded; | 458 | uint64_t samples_encoded; |
| 459 | |||
| 460 | /* packet quality factor */ | ||
| 461 | int quality; | ||
| 459 | } OutputStream; | 462 | } OutputStream; |
| 460 | 463 | ||
| 461 | typedef struct OutputFile { | 464 | typedef struct OutputFile { |
| @@ -1054,6 +1054,13 @@ enum AVPacketSideDataType { · 1053 unmodified lines | |||
| 1054 | */ | 1054 | */ |
| 1055 | AV_PKT_DATA_AUDIO_SERVICE_TYPE, | 1055 | AV_PKT_DATA_AUDIO_SERVICE_TYPE, |
| 1056 | 1056 | ||
| 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). | ||
| 1061 | */ | ||
| 1062 | AV_PKT_DATA_QUALITY_FACTOR, | ||
| 1063 | |||
| 1057 | /** | 1064 | /** |
| 1058 | * Recommmends skipping the specified number of samples | 1065 | * Recommmends skipping the specified number of samples |
| 1059 | * @code | 1066 | * @code |
| @@ -1050,7 +1050,7 @@ static int dnxhd_encode_picture(AVCodecContext *avctx, AVPacket *pkt, · 1049 unmodified lines | |||
| 1050 | DNXHDEncContext *ctx = avctx->priv_data; | 1050 | DNXHDEncContext *ctx = avctx->priv_data; |
| 1051 | int first_field = 1; | 1051 | int first_field = 1; |
| 1052 | int offset, i, ret; | 1052 | int offset, i, ret; |
| 1053 | uint8_t *buf; | 1053 | uint8_t *buf, *sd; |
| 1054 | 1054 | ||
| 1055 | if ((ret = ff_alloc_packet2(avctx, pkt, ctx->cid_table->frame_size)) < 0) | 1055 | if ((ret = ff_alloc_packet2(avctx, pkt, ctx->cid_table->frame_size)) < 0) |
| 1056 | return ret; | 1056 | return ret; |
| @@ -1103,6 +1103,11 @@ encode_coding_unit: · 46 unmodified lines | |||
| 1103 | 1103 | ||
| 1104 | avctx->coded_frame->quality = ctx->qscale * FF_QP2LAMBDA; | 1104 | avctx->coded_frame->quality = ctx->qscale * FF_QP2LAMBDA; |
| 1105 | 1105 | ||
| 1106 | sd = av_packet_new_side_data(pkt, AV_PKT_DATA_QUALITY_FACTOR, sizeof(int)); | ||
| 1107 | if (!sd) | ||
| 1108 | return AVERROR(ENOMEM); | ||
| 1109 | *(int *)sd = ctx->qscale * FF_QP2LAMBDA; | ||
| 1110 | |||
| 1106 | pkt->flags |= AV_PKT_FLAG_KEY; | 1111 | pkt->flags |= AV_PKT_FLAG_KEY; |
| 1107 | *got_packet = 1; | 1112 | *got_packet = 1; |
| 1108 | return 0; | 1113 | return 0; |
| @@ -302,8 +302,15 @@ static int X264_frame(AVCodecContext *ctx, AVPacket *pkt, const AVFrame *frame, · 301 unmodified lines | |||
| 302 | } | 302 | } |
| 303 | 303 | ||
| 304 | pkt->flags |= AV_PKT_FLAG_KEY*pic_out.b_keyframe; | 304 | pkt->flags |= AV_PKT_FLAG_KEY*pic_out.b_keyframe; |
| 305 | if (ret) | 305 | if (ret) { |
| 306 | uint8_t *sd = av_packet_new_side_data(pkt, AV_PKT_DATA_QUALITY_FACTOR, | ||
| 307 | sizeof(int)); | ||
| 308 | if (!sd) | ||
| 309 | return AVERROR(ENOMEM); | ||
| 310 | *(int *)sd = (pic_out.i_qpplus1 - 1) * FF_QP2LAMBDA; | ||
| 311 | |||
| 306 | ctx->coded_frame->quality = (pic_out.i_qpplus1 - 1) * FF_QP2LAMBDA; | 312 | ctx->coded_frame->quality = (pic_out.i_qpplus1 - 1) * FF_QP2LAMBDA; |
| 313 | } | ||
| 307 | 314 | ||
| 308 | *got_packet = ret; | 315 | *got_packet = ret; |
| 309 | return 0; | 316 | return 0; |
| @@ -117,6 +117,7 @@ static int XAVS_frame(AVCodecContext *avctx, AVPacket *pkt, · 116 unmodified lines | |||
| 117 | xavs_nal_t *nal; | 117 | xavs_nal_t *nal; |
| 118 | int nnal, i, ret; | 118 | int nnal, i, ret; |
| 119 | xavs_picture_t pic_out; | 119 | xavs_picture_t pic_out; |
| 120 | uint8_t *sd; | ||
| 120 | 121 | ||
| 121 | x4->pic.img.i_csp = XAVS_CSP_I420; | 122 | x4->pic.img.i_csp = XAVS_CSP_I420; |
| 122 | x4->pic.img.i_plane = 3; | 123 | x4->pic.img.i_plane = 3; |
| @@ -191,6 +192,11 @@ static int XAVS_frame(AVCodecContext *avctx, AVPacket *pkt, · 68 unmodified lines | |||
| 191 | 192 | ||
| 192 | avctx->coded_frame->quality = (pic_out.i_qpplus1 - 1) * FF_QP2LAMBDA; | 193 | avctx->coded_frame->quality = (pic_out.i_qpplus1 - 1) * FF_QP2LAMBDA; |
| 193 | 194 | ||
| 195 | sd = av_packet_new_side_data(pkt, AV_PKT_DATA_QUALITY_FACTOR, sizeof(int)); | ||
| 196 | if (!sd) | ||
| 197 | return AVERROR(ENOMEM); | ||
| 198 | *(int *)sd = (pic_out.i_qpplus1 - 1) * FF_QP2LAMBDA; | ||
| 199 | |||
| 194 | x4->out_frame_count++; | 200 | x4->out_frame_count++; |
| 195 | *got_packet = ret; | 201 | *got_packet = ret; |
| 196 | return 0; | 202 | return 0; |
| @@ -771,6 +771,12 @@ 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, | ||
| 775 | sizeof(int)); | ||
| 776 | if (!sd) | ||
| 777 | return AVERROR(ENOMEM); | ||
| 778 | *(int *)sd = xvid_enc_stats.quant * FF_QP2LAMBDA; | ||
| 779 | |||
| 774 | *got_packet = 1; | 780 | *got_packet = 1; |
| 775 | 781 | ||
| 776 | avctx->coded_frame->quality = xvid_enc_stats.quant * FF_QP2LAMBDA; | 782 | avctx->coded_frame->quality = xvid_enc_stats.quant * FF_QP2LAMBDA; |
| @@ -1731,6 +1731,7 @@ int ff_mpv_encode_picture(AVCodecContext *avctx, AVPacket *pkt, · 1730 unmodified lines | |||
| 1731 | 1731 | ||
| 1732 | /* output? */ | 1732 | /* output? */ |
| 1733 | if (s->new_picture.f->data[0]) { | 1733 | if (s->new_picture.f->data[0]) { |
| 1734 | uint8_t *sd; | ||
| 1734 | int growing_buffer = context_count == 1 && !pkt->data && !s->data_partitioning; | 1735 | int growing_buffer = context_count == 1 && !pkt->data && !s->data_partitioning; |
| 1735 | int pkt_size = growing_buffer ? FFMAX(s->mb_width*s->mb_height*64+10000, avctx->internal->byte_buffer_size) - FF_INPUT_BUFFER_PADDING_SIZE | 1736 | int pkt_size = growing_buffer ? FFMAX(s->mb_width*s->mb_height*64+10000, avctx->internal->byte_buffer_size) - FF_INPUT_BUFFER_PADDING_SIZE |
| 1736 | : | 1737 | : |
| @@ -1781,6 +1782,12 @@ vbv_retry: · 44 unmodified lines | |||
| 1781 | 1782 | ||
| 1782 | frame_end(s); | 1783 | frame_end(s); |
| 1783 | 1784 | ||
| 1785 | sd = av_packet_new_side_data(pkt, AV_PKT_DATA_QUALITY_FACTOR, | ||
| 1786 | sizeof(int)); | ||
| 1787 | if (!sd) | ||
| 1788 | return AVERROR(ENOMEM); | ||
| 1789 | *(int *)sd = s->current_picture.f->quality; | ||
| 1790 | |||
| 1784 | if (CONFIG_MJPEG_ENCODER && s->out_format == FMT_MJPEG) | 1791 | if (CONFIG_MJPEG_ENCODER && s->out_format == FMT_MJPEG) |
| 1785 | ff_mjpeg_encode_picture_trailer(&s->pb, s->header_bits); | 1792 | ff_mjpeg_encode_picture_trailer(&s->pb, s->header_bits); |
| 1786 | 1793 | ||
| @@ -574,6 +574,7 @@ static int svq1_encode_frame(AVCodecContext *avctx, AVPacket *pkt, · 573 unmodified lines | |||
| 574 | { | 574 | { |
| 575 | SVQ1EncContext *const s = avctx->priv_data; | 575 | SVQ1EncContext *const s = avctx->priv_data; |
| 576 | int i, ret; | 576 | int i, ret; |
| 577 | uint8_t *sd; | ||
| 577 | 578 | ||
| 578 | if ((ret = ff_alloc_packet2(avctx, pkt, s->y_block_width * s->y_block_height * | 579 | if ((ret = ff_alloc_packet2(avctx, pkt, s->y_block_width * s->y_block_height * |
| 579 | MAX_MB_BYTES*3 + FF_MIN_BUFFER_SIZE)) < 0) | 580 | MAX_MB_BYTES*3 + FF_MIN_BUFFER_SIZE)) < 0) |
| @@ -613,6 +614,11 @@ static int svq1_encode_frame(AVCodecContext *avctx, AVPacket *pkt, · 33 unmodified lines | |||
| 613 | avctx->coded_frame->pict_type = s->pict_type; | 614 | avctx->coded_frame->pict_type = s->pict_type; |
| 614 | avctx->coded_frame->key_frame = s->pict_type == AV_PICTURE_TYPE_I; | 615 | avctx->coded_frame->key_frame = s->pict_type == AV_PICTURE_TYPE_I; |
| 615 | 616 | ||
| 617 | sd = av_packet_new_side_data(pkt, AV_PKT_DATA_QUALITY_FACTOR, sizeof(int)); | ||
| 618 | if (!sd) | ||
| 619 | return AVERROR(ENOMEM); | ||
| 620 | *(int *)sd = pict->quality; | ||
| 621 | |||
| 616 | svq1_write_header(s, s->pict_type); | 622 | svq1_write_header(s, s->pict_type); |
| 617 | for (i = 0; i < 3; i++) | 623 | for (i = 0; i < 3; i++) |
| 618 | if (svq1_encode_plane(s, i, | 624 | if (svq1_encode_plane(s, i, |
| @@ -29,8 +29,8 @@ · 28 unmodified lines | |||
| 29 | #include "libavutil/version.h" | 29 | #include "libavutil/version.h" |
| 30 | 30 | ||
| 31 | #define LIBAVCODEC_VERSION_MAJOR 56 | 31 | #define LIBAVCODEC_VERSION_MAJOR 56 |
| 32 | #define LIBAVCODEC_VERSION_MINOR 49 | 32 | #define LIBAVCODEC_VERSION_MINOR 50 |
| 33 | #define LIBAVCODEC_VERSION_MICRO 101 | 33 | #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, \ |
| @@ -377,6 +377,9 @@ 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: | ||
| 381 | av_log(ctx, AV_LOG_INFO, "quality factor: %d", *(int *)sd.data); | ||
| 382 | break; | ||
| 380 | default: | 383 | default: |
| 381 | av_log(ctx, AV_LOG_WARNING, | 384 | av_log(ctx, AV_LOG_WARNING, |
| 382 | "unknown side data type %d (%d bytes)", sd.type, sd.size); | 385 | "unknown side data type %d (%d bytes)", sd.type, sd.size); |