From 6c7ee2f7db5e07e65182c89608e191f861c499ed Mon Sep 17 00:00:00 2001 From: Alex Converse Date: Mon, 22 Aug 2011 10:38:35 -0700 Subject: [PATCH 01/14] avconv: use av_clip_int16 for audio clipping --- avconv.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/avconv.c b/avconv.c index a86fa02eb7..efb9b12a32 100644 --- a/avconv.c +++ b/avconv.c @@ -1638,9 +1638,7 @@ static int output_packet(InputStream *ist, int ist_index, volp = samples; for(i=0;i<(decoded_data_size / sizeof(short));i++) { int v = ((*volp) * audio_volume + 128) >> 8; - if (v < -32768) v = -32768; - if (v > 32767) v = 32767; - *volp++ = v; + *volp++ = av_clip_int16(v); } } } From 7e6029f98a60724a7d7de64096aece4bb1479da0 Mon Sep 17 00:00:00 2001 From: Alex Converse Date: Mon, 22 Aug 2011 18:47:24 -0700 Subject: [PATCH 02/14] lavf utils: Fix bad indentation. --- libavformat/utils.c | 67 +++++++++++++++++++++++---------------------- 1 file changed, 34 insertions(+), 33 deletions(-) diff --git a/libavformat/utils.c b/libavformat/utils.c index 6e3cb2fa54..6077be99a4 100644 --- a/libavformat/utils.c +++ b/libavformat/utils.c @@ -587,7 +587,7 @@ static int init_input(AVFormatContext *s, const char *filename) return 0; if ((ret = avio_open(&s->pb, filename, AVIO_FLAG_READ)) < 0) - return ret; + return ret; if (s->iformat) return 0; return av_probe_input_buffer(s->pb, &s->iformat, filename, s, 0, 0); @@ -1146,7 +1146,7 @@ static int read_frame_internal(AVFormatContext *s, AVPacket *pkt) st->cur_pkt.data = NULL; assert(st->cur_len == 0); }else{ - pkt->destruct = NULL; + pkt->destruct = NULL; } compute_pkt_fields(s, st, st->parser, pkt); @@ -1760,7 +1760,7 @@ int av_seek_frame(AVFormatContext *s, int stream_index, int64_t timestamp, int f return -1; st= s->streams[stream_index]; - /* timestamp for default must be expressed in AV_TIME_BASE units */ + /* timestamp for default must be expressed in AV_TIME_BASE units */ timestamp = av_rescale(timestamp, st->time_base.den, AV_TIME_BASE * (int64_t)st->time_base.num); } @@ -1959,39 +1959,40 @@ static void estimate_timings_from_pts(AVFormatContext *ic, int64_t old_offset) filesize = ic->file_size; end_time = AV_NOPTS_VALUE; do{ - offset = filesize - (DURATION_MAX_READ_SIZE<pb, offset, SEEK_SET); - read_size = 0; - for(;;) { - if (read_size >= DURATION_MAX_READ_SIZE<<(FFMAX(retry-1,0))) - break; + avio_seek(ic->pb, offset, SEEK_SET); + read_size = 0; + for(;;) { + if (read_size >= DURATION_MAX_READ_SIZE<<(FFMAX(retry-1,0))) + break; - do{ - ret = av_read_packet(ic, pkt); - }while(ret == AVERROR(EAGAIN)); - if (ret != 0) - break; - read_size += pkt->size; - st = ic->streams[pkt->stream_index]; - if (pkt->pts != AV_NOPTS_VALUE && - (st->start_time != AV_NOPTS_VALUE || - st->first_dts != AV_NOPTS_VALUE)) { - duration = end_time = pkt->pts; - if (st->start_time != AV_NOPTS_VALUE) duration -= st->start_time; - else duration -= st->first_dts; - if (duration < 0) - duration += 1LL<pts_wrap_bits; - if (duration > 0) { - if (st->duration == AV_NOPTS_VALUE || - st->duration < duration) - st->duration = duration; + do { + ret = av_read_packet(ic, pkt); + } while(ret == AVERROR(EAGAIN)); + if (ret != 0) + break; + read_size += pkt->size; + st = ic->streams[pkt->stream_index]; + if (pkt->pts != AV_NOPTS_VALUE && + (st->start_time != AV_NOPTS_VALUE || + st->first_dts != AV_NOPTS_VALUE)) { + duration = end_time = pkt->pts; + if (st->start_time != AV_NOPTS_VALUE) + duration -= st->start_time; + else + duration -= st->first_dts; + if (duration < 0) + duration += 1LL<pts_wrap_bits; + if (duration > 0) { + if (st->duration == AV_NOPTS_VALUE || st->duration < duration) + st->duration = duration; + } } + av_free_packet(pkt); } - av_free_packet(pkt); - } }while( end_time==AV_NOPTS_VALUE && filesize > (DURATION_MAX_READ_SIZE<codec_tag, codec_id); else if (codec_id == ofmt->video_codec || codec_id == ofmt->audio_codec || codec_id == ofmt->subtitle_codec) - return 1; + return 1; } return AVERROR_PATCHWELCOME; } From 8ee18b4bee24f99e733cf1425894e82c25d02426 Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Tue, 23 Aug 2011 17:28:33 +0200 Subject: [PATCH 03/14] lavc: remove vbv_delay option It's broken and serves no purpose as it's a read-only field. --- libavcodec/options.c | 1 - 1 file changed, 1 deletion(-) diff --git a/libavcodec/options.c b/libavcodec/options.c index 821bf800b3..47886e8444 100644 --- a/libavcodec/options.c +++ b/libavcodec/options.c @@ -456,7 +456,6 @@ static const AVOption options[]={ {"thread_type", "select multithreading type", OFFSET(thread_type), FF_OPT_TYPE_INT, {.dbl = FF_THREAD_SLICE|FF_THREAD_FRAME }, 0, INT_MAX, V|E|D, "thread_type"}, {"slice", NULL, 0, FF_OPT_TYPE_CONST, {.dbl = FF_THREAD_SLICE }, INT_MIN, INT_MAX, V|E|D, "thread_type"}, {"frame", NULL, 0, FF_OPT_TYPE_CONST, {.dbl = FF_THREAD_FRAME }, INT_MIN, INT_MAX, V|E|D, "thread_type"}, -{"vbv_delay", "initial buffer fill time in periods of 27Mhz clock", 0, FF_OPT_TYPE_INT64, {.dbl = 0 }, 0, INT64_MAX}, {"audio_service_type", "audio service type", OFFSET(audio_service_type), FF_OPT_TYPE_INT, {.dbl = AV_AUDIO_SERVICE_TYPE_MAIN }, 0, AV_AUDIO_SERVICE_TYPE_NB-1, A|E, "audio_service_type"}, {"ma", "Main Audio Service", 0, FF_OPT_TYPE_CONST, {.dbl = AV_AUDIO_SERVICE_TYPE_MAIN }, INT_MIN, INT_MAX, A|E, "audio_service_type"}, {"ef", "Effects", 0, FF_OPT_TYPE_CONST, {.dbl = AV_AUDIO_SERVICE_TYPE_EFFECTS }, INT_MIN, INT_MAX, A|E, "audio_service_type"}, From d5dc8cc2974c816ba964692b75c9f17f40830414 Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Mon, 22 Aug 2011 07:55:34 +0200 Subject: [PATCH 04/14] libx264: add 'crf' private option. Deprecate corresponding global option. Ideally all x264 private options should be generated automatically, but x264 doesn't provide the API for this yet. --- libavcodec/avcodec.h | 5 ++++- libavcodec/libx264.c | 13 ++++++++++++- libavcodec/options.c | 2 ++ libavcodec/version.h | 3 +++ 4 files changed, 21 insertions(+), 2 deletions(-) diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h index 5698f512a5..350708da08 100644 --- a/libavcodec/avcodec.h +++ b/libavcodec/avcodec.h @@ -2377,12 +2377,15 @@ typedef struct AVCodecContext { */ int brd_scale; +#if FF_API_X264_GLOBAL_OPTS /** * constant rate factor - quality-based VBR - values ~correspond to qps * - encoding: Set by user. * - decoding: unused + * @deprecated use 'crf' libx264 private option */ - float crf; + attribute_deprecated float crf; +#endif /** * constant quantization parameter rate control method diff --git a/libavcodec/libx264.c b/libavcodec/libx264.c index 44c85fdef6..bd7955a2a3 100644 --- a/libavcodec/libx264.c +++ b/libavcodec/libx264.c @@ -23,6 +23,7 @@ #include "avcodec.h" #include "internal.h" #include +#include #include #include #include @@ -40,6 +41,7 @@ typedef struct X264Context { char *tune; char *profile; int fastfirstpass; + float crf; } X264Context; static void X264_log(void *p, int level, const char *fmt, va_list args) @@ -274,14 +276,22 @@ static av_cold int X264_init(AVCodecContext *avctx) if (avctx->flags & CODEC_FLAG_PASS2) { x4->params.rc.b_stat_read = 1; } else { +#if FF_API_X264_GLOBAL_OPTS if (avctx->crf) { x4->params.rc.i_rc_method = X264_RC_CRF; x4->params.rc.f_rf_constant = avctx->crf; x4->params.rc.f_rf_constant_max = avctx->crf_max; - } else if (avctx->cqp > -1) { + } else +#endif + if (avctx->cqp > -1) { x4->params.rc.i_rc_method = X264_RC_CQP; x4->params.rc.i_qp_constant = avctx->cqp; } + + if (x4->crf >= 0) { + x4->params.rc.i_rc_method = X264_RC_CRF; + x4->params.rc.f_rf_constant = x4->crf; + } } if (avctx->rc_buffer_size && avctx->rc_initial_buffer_occupancy && @@ -365,6 +375,7 @@ static const AVOption options[] = { { "tune", "Tune the encoding params (cf. x264 --fullhelp)", OFFSET(tune), FF_OPT_TYPE_STRING, { 0 }, 0, 0, VE}, { "profile", "Set profile restrictions (cf. x264 --fullhelp) ", OFFSET(profile), FF_OPT_TYPE_STRING, { 0 }, 0, 0, VE}, { "fastfirstpass", "Use fast settings when encoding first pass", OFFSET(fastfirstpass), FF_OPT_TYPE_INT, { 1 }, 0, 1, VE}, + { "crf", "Select the quality for constant quality mode", OFFSET(crf), FF_OPT_TYPE_FLOAT, {-1 }, -1, FLT_MAX, VE }, { NULL }, }; diff --git a/libavcodec/options.c b/libavcodec/options.c index 47886e8444..3cef24c3d2 100644 --- a/libavcodec/options.c +++ b/libavcodec/options.c @@ -375,7 +375,9 @@ static const AVOption options[]={ {"all" , NULL, 0, FF_OPT_TYPE_CONST, {.dbl = AVDISCARD_ALL }, INT_MIN, INT_MAX, V|D, "avdiscard"}, {"bidir_refine", "refine the two motion vectors used in bidirectional macroblocks", OFFSET(bidir_refine), FF_OPT_TYPE_INT, {.dbl = 1 }, 0, 4, V|E}, {"brd_scale", "downscales frames for dynamic B-frame decision", OFFSET(brd_scale), FF_OPT_TYPE_INT, {.dbl = DEFAULT }, 0, 10, V|E}, +#if FF_API_X264_GLOBAL_OPTS {"crf", "enables constant quality mode, and selects the quality (x264)", OFFSET(crf), FF_OPT_TYPE_FLOAT, {.dbl = DEFAULT }, 0, 51, V|E}, +#endif {"cqp", "constant quantization parameter rate control method", OFFSET(cqp), FF_OPT_TYPE_INT, {.dbl = -1 }, INT_MIN, INT_MAX, V|E}, {"keyint_min", "minimum interval between IDR-frames (x264)", OFFSET(keyint_min), FF_OPT_TYPE_INT, {.dbl = 25 }, INT_MIN, INT_MAX, V|E}, {"refs", "reference frames to consider for motion compensation (Snow)", OFFSET(refs), FF_OPT_TYPE_INT, {.dbl = 1 }, INT_MIN, INT_MAX, V|E}, diff --git a/libavcodec/version.h b/libavcodec/version.h index 43efcafc5b..889e945082 100644 --- a/libavcodec/version.h +++ b/libavcodec/version.h @@ -83,5 +83,8 @@ #ifndef FF_API_AVCODEC_INIT #define FF_API_AVCODEC_INIT (LIBAVCODEC_VERSION_MAJOR < 54) #endif +#ifndef FF_API_X264_GLOBAL_OPTS +#define FF_API_X264_GLOBAL_OPTS (LIBAVCODEC_VERSION_MAJOR < 54) +#endif #endif /* AVCODEC_VERSION_H */ From 9d508e4914d6e9aafc8ae7ab0ff965a291ee42a8 Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Mon, 22 Aug 2011 07:55:34 +0200 Subject: [PATCH 05/14] libx264: add 'cqp' private option. Deprecate corresponding global option. --- libavcodec/avcodec.h | 5 +++-- libavcodec/libx264.c | 12 +++++++++--- libavcodec/options.c | 2 +- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h index 350708da08..bff4b8f84e 100644 --- a/libavcodec/avcodec.h +++ b/libavcodec/avcodec.h @@ -2385,14 +2385,15 @@ typedef struct AVCodecContext { * @deprecated use 'crf' libx264 private option */ attribute_deprecated float crf; -#endif /** * constant quantization parameter rate control method * - encoding: Set by user. * - decoding: unused + * @deprecated use 'cqp' libx264 private option */ - int cqp; + attribute_deprecated int cqp; +#endif /** * minimum GOP size diff --git a/libavcodec/libx264.c b/libavcodec/libx264.c index bd7955a2a3..cafca18451 100644 --- a/libavcodec/libx264.c +++ b/libavcodec/libx264.c @@ -42,6 +42,7 @@ typedef struct X264Context { char *profile; int fastfirstpass; float crf; + int cqp; } X264Context; static void X264_log(void *p, int level, const char *fmt, va_list args) @@ -281,16 +282,18 @@ static av_cold int X264_init(AVCodecContext *avctx) x4->params.rc.i_rc_method = X264_RC_CRF; x4->params.rc.f_rf_constant = avctx->crf; x4->params.rc.f_rf_constant_max = avctx->crf_max; - } else -#endif - if (avctx->cqp > -1) { + } else if (avctx->cqp > -1) { x4->params.rc.i_rc_method = X264_RC_CQP; x4->params.rc.i_qp_constant = avctx->cqp; } +#endif if (x4->crf >= 0) { x4->params.rc.i_rc_method = X264_RC_CRF; x4->params.rc.f_rf_constant = x4->crf; + } else if (x4->cqp >= 0) { + x4->params.rc.i_rc_method = X264_RC_CQP; + x4->params.rc.i_qp_constant = x4->cqp; } } @@ -343,7 +346,9 @@ static av_cold int X264_init(AVCodecContext *avctx) avctx->has_b_frames = x4->params.i_bframe ? x4->params.i_bframe_pyramid ? 2 : 1 : 0; avctx->bit_rate = x4->params.rc.i_bitrate*1000; +#if FF_API_X264_GLOBAL_OPTS avctx->crf = x4->params.rc.f_rf_constant; +#endif x4->enc = x264_encoder_open(&x4->params); if (!x4->enc) @@ -376,6 +381,7 @@ static const AVOption options[] = { { "profile", "Set profile restrictions (cf. x264 --fullhelp) ", OFFSET(profile), FF_OPT_TYPE_STRING, { 0 }, 0, 0, VE}, { "fastfirstpass", "Use fast settings when encoding first pass", OFFSET(fastfirstpass), FF_OPT_TYPE_INT, { 1 }, 0, 1, VE}, { "crf", "Select the quality for constant quality mode", OFFSET(crf), FF_OPT_TYPE_FLOAT, {-1 }, -1, FLT_MAX, VE }, + { "cqp", "Constant quantization parameter rate control method",OFFSET(cqp), FF_OPT_TYPE_INT, {-1 }, -1, INT_MAX, VE }, { NULL }, }; diff --git a/libavcodec/options.c b/libavcodec/options.c index 3cef24c3d2..38ac9860d1 100644 --- a/libavcodec/options.c +++ b/libavcodec/options.c @@ -377,8 +377,8 @@ static const AVOption options[]={ {"brd_scale", "downscales frames for dynamic B-frame decision", OFFSET(brd_scale), FF_OPT_TYPE_INT, {.dbl = DEFAULT }, 0, 10, V|E}, #if FF_API_X264_GLOBAL_OPTS {"crf", "enables constant quality mode, and selects the quality (x264)", OFFSET(crf), FF_OPT_TYPE_FLOAT, {.dbl = DEFAULT }, 0, 51, V|E}, -#endif {"cqp", "constant quantization parameter rate control method", OFFSET(cqp), FF_OPT_TYPE_INT, {.dbl = -1 }, INT_MIN, INT_MAX, V|E}, +#endif {"keyint_min", "minimum interval between IDR-frames (x264)", OFFSET(keyint_min), FF_OPT_TYPE_INT, {.dbl = 25 }, INT_MIN, INT_MAX, V|E}, {"refs", "reference frames to consider for motion compensation (Snow)", OFFSET(refs), FF_OPT_TYPE_INT, {.dbl = 1 }, INT_MIN, INT_MAX, V|E}, {"chromaoffset", "chroma qp offset from luma", OFFSET(chromaoffset), FF_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX, V|E}, From 85254fcb46b4af38510685bc48ae6aa557f861aa Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Mon, 22 Aug 2011 07:55:34 +0200 Subject: [PATCH 06/14] libx264: add 'aq_mode' private option. Deprecate corresponding global option. --- libavcodec/avcodec.h | 4 +++- libavcodec/libx264.c | 15 ++++++++++++++- libavcodec/options.c | 4 +++- 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h index bff4b8f84e..e789a52dd9 100644 --- a/libavcodec/avcodec.h +++ b/libavcodec/avcodec.h @@ -2722,6 +2722,7 @@ typedef struct AVCodecContext { */ int weighted_p_pred; +#if FF_API_X264_GLOBAL_OPTS /** * AQ mode * 0: Disabled @@ -2730,7 +2731,8 @@ typedef struct AVCodecContext { * - encoding: Set by user * - decoding: unused */ - int aq_mode; + attribute_deprecated int aq_mode; +#endif /** * AQ strength diff --git a/libavcodec/libx264.c b/libavcodec/libx264.c index cafca18451..7d6f1408d0 100644 --- a/libavcodec/libx264.c +++ b/libavcodec/libx264.c @@ -43,6 +43,7 @@ typedef struct X264Context { int fastfirstpass; float crf; int cqp; + int aq_mode; } X264Context; static void X264_log(void *p, int level, const char *fmt, va_list args) @@ -234,7 +235,6 @@ static av_cold int X264_init(AVCodecContext *avctx) x4->params.analyse.i_me_method = X264_ME_TESA; else x4->params.analyse.i_me_method = X264_ME_HEX; - x4->params.rc.i_aq_mode = avctx->aq_mode; x4->params.rc.f_aq_strength = avctx->aq_strength; x4->params.rc.i_lookahead = avctx->rc_lookahead; @@ -308,6 +308,15 @@ static av_cold int X264_init(AVCodecContext *avctx) x4->params.rc.f_pb_factor = avctx->b_quant_factor; x4->params.analyse.i_chroma_qp_offset = avctx->chromaoffset; +#if FF_API_X264_GLOBAL_OPTS + if (avctx->aq_mode >= 0) + x4->params.rc.i_aq_mode = avctx->aq_mode; +#endif + + if (x4->aq_mode >= 0) + x4->params.rc.i_aq_mode = x4->aq_mode; + + if (x4->fastfirstpass) x264_param_apply_fastfirstpass(&x4->params); @@ -382,6 +391,10 @@ static const AVOption options[] = { { "fastfirstpass", "Use fast settings when encoding first pass", OFFSET(fastfirstpass), FF_OPT_TYPE_INT, { 1 }, 0, 1, VE}, { "crf", "Select the quality for constant quality mode", OFFSET(crf), FF_OPT_TYPE_FLOAT, {-1 }, -1, FLT_MAX, VE }, { "cqp", "Constant quantization parameter rate control method",OFFSET(cqp), FF_OPT_TYPE_INT, {-1 }, -1, INT_MAX, VE }, + { "aq_mode", "AQ method", OFFSET(aq_mode), FF_OPT_TYPE_INT, {-1 }, -1, INT_MAX, VE, "aq_mode"}, + { "none", NULL, 0, FF_OPT_TYPE_CONST, {X264_AQ_NONE}, INT_MIN, INT_MAX, VE, "aq_mode" }, + { "variance", "Variance AQ (complexity mask)", 0, FF_OPT_TYPE_CONST, {X264_AQ_VARIANCE}, INT_MIN, INT_MAX, VE, "aq_mode" }, + { "autovariance", "Auto-variance AQ (experimental)", 0, FF_OPT_TYPE_CONST, {X264_AQ_AUTOVARIANCE}, INT_MIN, INT_MAX, VE, "aq_mode" }, { NULL }, }; diff --git a/libavcodec/options.c b/libavcodec/options.c index 38ac9860d1..290f932b7c 100644 --- a/libavcodec/options.c +++ b/libavcodec/options.c @@ -439,7 +439,9 @@ static const AVOption options[]={ {"psy", "use psycho visual optimization", 0, FF_OPT_TYPE_CONST, {.dbl = CODEC_FLAG2_PSY }, INT_MIN, INT_MAX, V|E, "flags2"}, {"psy_rd", "specify psycho visual strength", OFFSET(psy_rd), FF_OPT_TYPE_FLOAT, {.dbl = 1.0 }, 0, FLT_MAX, V|E}, {"psy_trellis", "specify psycho visual trellis", OFFSET(psy_trellis), FF_OPT_TYPE_FLOAT, {.dbl = 0 }, 0, FLT_MAX, V|E}, -{"aq_mode", "specify aq method", OFFSET(aq_mode), FF_OPT_TYPE_INT, {.dbl = 1 }, 0, INT_MAX, V|E}, +#if FF_API_X264_GLOBAL_OPTS +{"aq_mode", "specify aq method", OFFSET(aq_mode), FF_OPT_TYPE_INT, {.dbl = -1 }, -1, INT_MAX, V|E}, +#endif {"aq_strength", "specify aq strength", OFFSET(aq_strength), FF_OPT_TYPE_FLOAT, {.dbl = 1.0 }, 0, FLT_MAX, V|E}, {"rc_lookahead", "specify number of frames to look ahead for frametype", OFFSET(rc_lookahead), FF_OPT_TYPE_INT, {.dbl = 40 }, 0, INT_MAX, V|E}, {"ssim", "ssim will be calculated during encoding", 0, FF_OPT_TYPE_CONST, {.dbl = CODEC_FLAG2_SSIM }, INT_MIN, INT_MAX, V|E, "flags2"}, From 5c75b2a0b75f2d12a289af70c0ad99eac0533eb3 Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Mon, 22 Aug 2011 07:55:34 +0200 Subject: [PATCH 07/14] libx264: add 'aq_strength' private option. Deprecate corresponding global option. --- libavcodec/avcodec.h | 4 ++-- libavcodec/libx264.c | 8 ++++++-- libavcodec/options.c | 2 +- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h index e789a52dd9..65064ea2e1 100644 --- a/libavcodec/avcodec.h +++ b/libavcodec/avcodec.h @@ -2732,7 +2732,6 @@ typedef struct AVCodecContext { * - decoding: unused */ attribute_deprecated int aq_mode; -#endif /** * AQ strength @@ -2740,7 +2739,8 @@ typedef struct AVCodecContext { * - encoding: Set by user * - decoding: unused */ - float aq_strength; + attribute_deprecated float aq_strength; +#endif /** * PSY RD diff --git a/libavcodec/libx264.c b/libavcodec/libx264.c index 7d6f1408d0..b46e10a73d 100644 --- a/libavcodec/libx264.c +++ b/libavcodec/libx264.c @@ -44,6 +44,7 @@ typedef struct X264Context { float crf; int cqp; int aq_mode; + float aq_strength; } X264Context; static void X264_log(void *p, int level, const char *fmt, va_list args) @@ -235,7 +236,6 @@ static av_cold int X264_init(AVCodecContext *avctx) x4->params.analyse.i_me_method = X264_ME_TESA; else x4->params.analyse.i_me_method = X264_ME_HEX; - x4->params.rc.f_aq_strength = avctx->aq_strength; x4->params.rc.i_lookahead = avctx->rc_lookahead; x4->params.analyse.b_psy = avctx->flags2 & CODEC_FLAG2_PSY; @@ -311,11 +311,14 @@ static av_cold int X264_init(AVCodecContext *avctx) #if FF_API_X264_GLOBAL_OPTS if (avctx->aq_mode >= 0) x4->params.rc.i_aq_mode = avctx->aq_mode; + if (avctx->aq_strength >= 0) + x4->params.rc.f_aq_strength = avctx->aq_strength; #endif if (x4->aq_mode >= 0) x4->params.rc.i_aq_mode = x4->aq_mode; - + if (x4->aq_strength >= 0) + x4->params.rc.f_aq_strength = x4->aq_strength; if (x4->fastfirstpass) x264_param_apply_fastfirstpass(&x4->params); @@ -395,6 +398,7 @@ static const AVOption options[] = { { "none", NULL, 0, FF_OPT_TYPE_CONST, {X264_AQ_NONE}, INT_MIN, INT_MAX, VE, "aq_mode" }, { "variance", "Variance AQ (complexity mask)", 0, FF_OPT_TYPE_CONST, {X264_AQ_VARIANCE}, INT_MIN, INT_MAX, VE, "aq_mode" }, { "autovariance", "Auto-variance AQ (experimental)", 0, FF_OPT_TYPE_CONST, {X264_AQ_AUTOVARIANCE}, INT_MIN, INT_MAX, VE, "aq_mode" }, + { "aq_strength", "AQ strength. Reduces blocking and blurring in flat and textured areas.", OFFSET(aq_strength), FF_OPT_TYPE_FLOAT, {-1}, -1, FLT_MAX, VE}, { NULL }, }; diff --git a/libavcodec/options.c b/libavcodec/options.c index 290f932b7c..7b94d1315c 100644 --- a/libavcodec/options.c +++ b/libavcodec/options.c @@ -441,8 +441,8 @@ static const AVOption options[]={ {"psy_trellis", "specify psycho visual trellis", OFFSET(psy_trellis), FF_OPT_TYPE_FLOAT, {.dbl = 0 }, 0, FLT_MAX, V|E}, #if FF_API_X264_GLOBAL_OPTS {"aq_mode", "specify aq method", OFFSET(aq_mode), FF_OPT_TYPE_INT, {.dbl = -1 }, -1, INT_MAX, V|E}, +{"aq_strength", "specify aq strength", OFFSET(aq_strength), FF_OPT_TYPE_FLOAT, {.dbl = -1.0 }, -1, FLT_MAX, V|E}, #endif -{"aq_strength", "specify aq strength", OFFSET(aq_strength), FF_OPT_TYPE_FLOAT, {.dbl = 1.0 }, 0, FLT_MAX, V|E}, {"rc_lookahead", "specify number of frames to look ahead for frametype", OFFSET(rc_lookahead), FF_OPT_TYPE_INT, {.dbl = 40 }, 0, INT_MAX, V|E}, {"ssim", "ssim will be calculated during encoding", 0, FF_OPT_TYPE_CONST, {.dbl = CODEC_FLAG2_SSIM }, INT_MIN, INT_MAX, V|E, "flags2"}, {"intra_refresh", "use periodic insertion of intra blocks instead of keyframes", 0, FF_OPT_TYPE_CONST, {.dbl = CODEC_FLAG2_INTRA_REFRESH }, INT_MIN, INT_MAX, V|E, "flags2"}, From 93e623c642d3966b74bd0b4913357527123546f5 Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Mon, 22 Aug 2011 07:55:34 +0200 Subject: [PATCH 08/14] libx264: add 'psy_rd' private option. Deprecate corresponding global option. --- libavcodec/avcodec.h | 4 ++-- libavcodec/libx264.c | 8 +++++++- libavcodec/options.c | 4 +++- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h index 65064ea2e1..29b6994aec 100644 --- a/libavcodec/avcodec.h +++ b/libavcodec/avcodec.h @@ -2740,7 +2740,6 @@ typedef struct AVCodecContext { * - decoding: unused */ attribute_deprecated float aq_strength; -#endif /** * PSY RD @@ -2748,7 +2747,8 @@ typedef struct AVCodecContext { * - encoding: Set by user * - decoding: unused */ - float psy_rd; + attribute_deprecated float psy_rd; +#endif /** * PSY trellis diff --git a/libavcodec/libx264.c b/libavcodec/libx264.c index b46e10a73d..45f55b46bf 100644 --- a/libavcodec/libx264.c +++ b/libavcodec/libx264.c @@ -45,6 +45,7 @@ typedef struct X264Context { int cqp; int aq_mode; float aq_strength; + float psy_rd; } X264Context; static void X264_log(void *p, int level, const char *fmt, va_list args) @@ -239,7 +240,6 @@ static av_cold int X264_init(AVCodecContext *avctx) x4->params.rc.i_lookahead = avctx->rc_lookahead; x4->params.analyse.b_psy = avctx->flags2 & CODEC_FLAG2_PSY; - x4->params.analyse.f_psy_rd = avctx->psy_rd; x4->params.analyse.f_psy_trellis = avctx->psy_trellis; x4->params.analyse.i_me_range = avctx->me_range; @@ -313,12 +313,17 @@ static av_cold int X264_init(AVCodecContext *avctx) x4->params.rc.i_aq_mode = avctx->aq_mode; if (avctx->aq_strength >= 0) x4->params.rc.f_aq_strength = avctx->aq_strength; + if (avctx->psy_rd >= 0) + x4->params.analyse.f_psy_rd = avctx->psy_rd; #endif if (x4->aq_mode >= 0) x4->params.rc.i_aq_mode = x4->aq_mode; if (x4->aq_strength >= 0) x4->params.rc.f_aq_strength = x4->aq_strength; + if (x4->psy_rd >= 0) + x4->params.analyse.f_psy_rd = x4->psy_rd; + if (x4->fastfirstpass) x264_param_apply_fastfirstpass(&x4->params); @@ -399,6 +404,7 @@ static const AVOption options[] = { { "variance", "Variance AQ (complexity mask)", 0, FF_OPT_TYPE_CONST, {X264_AQ_VARIANCE}, INT_MIN, INT_MAX, VE, "aq_mode" }, { "autovariance", "Auto-variance AQ (experimental)", 0, FF_OPT_TYPE_CONST, {X264_AQ_AUTOVARIANCE}, INT_MIN, INT_MAX, VE, "aq_mode" }, { "aq_strength", "AQ strength. Reduces blocking and blurring in flat and textured areas.", OFFSET(aq_strength), FF_OPT_TYPE_FLOAT, {-1}, -1, FLT_MAX, VE}, + { "pdy_rd", "Psy RD strength.", OFFSET(psy_rd), FF_OPT_TYPE_FLOAT, {-1 }, -1, FLT_MAX, VE}, { NULL }, }; diff --git a/libavcodec/options.c b/libavcodec/options.c index 7b94d1315c..a7b904993a 100644 --- a/libavcodec/options.c +++ b/libavcodec/options.c @@ -437,7 +437,9 @@ static const AVOption options[]={ {"color_range", NULL, OFFSET(color_range), FF_OPT_TYPE_INT, {.dbl = AVCOL_RANGE_UNSPECIFIED }, 0, AVCOL_RANGE_NB-1, V|E|D}, {"chroma_sample_location", NULL, OFFSET(chroma_sample_location), FF_OPT_TYPE_INT, {.dbl = AVCHROMA_LOC_UNSPECIFIED }, 0, AVCHROMA_LOC_NB-1, V|E|D}, {"psy", "use psycho visual optimization", 0, FF_OPT_TYPE_CONST, {.dbl = CODEC_FLAG2_PSY }, INT_MIN, INT_MAX, V|E, "flags2"}, -{"psy_rd", "specify psycho visual strength", OFFSET(psy_rd), FF_OPT_TYPE_FLOAT, {.dbl = 1.0 }, 0, FLT_MAX, V|E}, +#if FF_API_X264_GLOBAL_OPTS +{"psy_rd", "specify psycho visual strength", OFFSET(psy_rd), FF_OPT_TYPE_FLOAT, {.dbl = -1.0 }, -1, FLT_MAX, V|E}, +#endif {"psy_trellis", "specify psycho visual trellis", OFFSET(psy_trellis), FF_OPT_TYPE_FLOAT, {.dbl = 0 }, 0, FLT_MAX, V|E}, #if FF_API_X264_GLOBAL_OPTS {"aq_mode", "specify aq method", OFFSET(aq_mode), FF_OPT_TYPE_INT, {.dbl = -1 }, -1, INT_MAX, V|E}, From 2a44a8f6091913bad14c4df318ceeb68dc4a9258 Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Mon, 22 Aug 2011 07:55:34 +0200 Subject: [PATCH 09/14] libx264: add 'psy_trellis' private option. Deprecate corresponding global option. --- libavcodec/avcodec.h | 4 ++-- libavcodec/libx264.c | 7 ++++++- libavcodec/options.c | 4 +--- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h index 29b6994aec..c36c35e686 100644 --- a/libavcodec/avcodec.h +++ b/libavcodec/avcodec.h @@ -2748,7 +2748,6 @@ typedef struct AVCodecContext { * - decoding: unused */ attribute_deprecated float psy_rd; -#endif /** * PSY trellis @@ -2756,7 +2755,8 @@ typedef struct AVCodecContext { * - encoding: Set by user * - decoding: unused */ - float psy_trellis; + attribute_deprecated float psy_trellis; +#endif /** * RC lookahead diff --git a/libavcodec/libx264.c b/libavcodec/libx264.c index 45f55b46bf..30bbfe6bc6 100644 --- a/libavcodec/libx264.c +++ b/libavcodec/libx264.c @@ -46,6 +46,7 @@ typedef struct X264Context { int aq_mode; float aq_strength; float psy_rd; + float psy_trellis; } X264Context; static void X264_log(void *p, int level, const char *fmt, va_list args) @@ -240,7 +241,6 @@ static av_cold int X264_init(AVCodecContext *avctx) x4->params.rc.i_lookahead = avctx->rc_lookahead; x4->params.analyse.b_psy = avctx->flags2 & CODEC_FLAG2_PSY; - x4->params.analyse.f_psy_trellis = avctx->psy_trellis; x4->params.analyse.i_me_range = avctx->me_range; x4->params.analyse.i_subpel_refine = avctx->me_subpel_quality; @@ -315,6 +315,8 @@ static av_cold int X264_init(AVCodecContext *avctx) x4->params.rc.f_aq_strength = avctx->aq_strength; if (avctx->psy_rd >= 0) x4->params.analyse.f_psy_rd = avctx->psy_rd; + if (avctx->psy_trellis >= 0) + x4->params.analyse.f_psy_trellis = avctx->psy_trellis; #endif if (x4->aq_mode >= 0) @@ -323,6 +325,8 @@ static av_cold int X264_init(AVCodecContext *avctx) x4->params.rc.f_aq_strength = x4->aq_strength; if (x4->psy_rd >= 0) x4->params.analyse.f_psy_rd = x4->psy_rd; + if (x4->psy_trellis >= 0) + x4->params.analyse.f_psy_trellis = x4->psy_trellis; if (x4->fastfirstpass) @@ -405,6 +409,7 @@ static const AVOption options[] = { { "autovariance", "Auto-variance AQ (experimental)", 0, FF_OPT_TYPE_CONST, {X264_AQ_AUTOVARIANCE}, INT_MIN, INT_MAX, VE, "aq_mode" }, { "aq_strength", "AQ strength. Reduces blocking and blurring in flat and textured areas.", OFFSET(aq_strength), FF_OPT_TYPE_FLOAT, {-1}, -1, FLT_MAX, VE}, { "pdy_rd", "Psy RD strength.", OFFSET(psy_rd), FF_OPT_TYPE_FLOAT, {-1 }, -1, FLT_MAX, VE}, + { "psy_trellis", "Psy trellis strength", OFFSET(psy_trellis), FF_OPT_TYPE_FLOAT, {-1 }, -1, FLT_MAX, VE}, { NULL }, }; diff --git a/libavcodec/options.c b/libavcodec/options.c index a7b904993a..365f8608ad 100644 --- a/libavcodec/options.c +++ b/libavcodec/options.c @@ -439,9 +439,7 @@ static const AVOption options[]={ {"psy", "use psycho visual optimization", 0, FF_OPT_TYPE_CONST, {.dbl = CODEC_FLAG2_PSY }, INT_MIN, INT_MAX, V|E, "flags2"}, #if FF_API_X264_GLOBAL_OPTS {"psy_rd", "specify psycho visual strength", OFFSET(psy_rd), FF_OPT_TYPE_FLOAT, {.dbl = -1.0 }, -1, FLT_MAX, V|E}, -#endif -{"psy_trellis", "specify psycho visual trellis", OFFSET(psy_trellis), FF_OPT_TYPE_FLOAT, {.dbl = 0 }, 0, FLT_MAX, V|E}, -#if FF_API_X264_GLOBAL_OPTS +{"psy_trellis", "specify psycho visual trellis", OFFSET(psy_trellis), FF_OPT_TYPE_FLOAT, {.dbl = -1 }, -1, FLT_MAX, V|E}, {"aq_mode", "specify aq method", OFFSET(aq_mode), FF_OPT_TYPE_INT, {.dbl = -1 }, -1, INT_MAX, V|E}, {"aq_strength", "specify aq strength", OFFSET(aq_strength), FF_OPT_TYPE_FLOAT, {.dbl = -1.0 }, -1, FLT_MAX, V|E}, #endif From d4b967131842e7c225e5f83cb82337d4474a0bb7 Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Mon, 22 Aug 2011 07:55:34 +0200 Subject: [PATCH 10/14] libx264: add 'rc_lookahead' private option. Deprecate corresponding global option. --- libavcodec/avcodec.h | 4 ++-- libavcodec/libx264.c | 8 ++++++-- libavcodec/options.c | 2 +- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h index c36c35e686..77544e3837 100644 --- a/libavcodec/avcodec.h +++ b/libavcodec/avcodec.h @@ -2756,7 +2756,6 @@ typedef struct AVCodecContext { * - decoding: unused */ attribute_deprecated float psy_trellis; -#endif /** * RC lookahead @@ -2764,7 +2763,8 @@ typedef struct AVCodecContext { * - encoding: Set by user * - decoding: unused */ - int rc_lookahead; + attribute_deprecated int rc_lookahead; +#endif /** * Constant rate factor maximum diff --git a/libavcodec/libx264.c b/libavcodec/libx264.c index 30bbfe6bc6..72033b9310 100644 --- a/libavcodec/libx264.c +++ b/libavcodec/libx264.c @@ -47,6 +47,7 @@ typedef struct X264Context { float aq_strength; float psy_rd; float psy_trellis; + int rc_lookahead; } X264Context; static void X264_log(void *p, int level, const char *fmt, va_list args) @@ -238,8 +239,6 @@ static av_cold int X264_init(AVCodecContext *avctx) x4->params.analyse.i_me_method = X264_ME_TESA; else x4->params.analyse.i_me_method = X264_ME_HEX; - x4->params.rc.i_lookahead = avctx->rc_lookahead; - x4->params.analyse.b_psy = avctx->flags2 & CODEC_FLAG2_PSY; x4->params.analyse.i_me_range = avctx->me_range; @@ -317,6 +316,8 @@ static av_cold int X264_init(AVCodecContext *avctx) x4->params.analyse.f_psy_rd = avctx->psy_rd; if (avctx->psy_trellis >= 0) x4->params.analyse.f_psy_trellis = avctx->psy_trellis; + if (avctx->rc_lookahead >= 0) + x4->params.rc.i_lookahead = avctx->rc_lookahead; #endif if (x4->aq_mode >= 0) @@ -327,6 +328,8 @@ static av_cold int X264_init(AVCodecContext *avctx) x4->params.analyse.f_psy_rd = x4->psy_rd; if (x4->psy_trellis >= 0) x4->params.analyse.f_psy_trellis = x4->psy_trellis; + if (x4->rc_lookahead >= 0) + x4->params.rc.i_lookahead = x4->rc_lookahead; if (x4->fastfirstpass) @@ -410,6 +413,7 @@ static const AVOption options[] = { { "aq_strength", "AQ strength. Reduces blocking and blurring in flat and textured areas.", OFFSET(aq_strength), FF_OPT_TYPE_FLOAT, {-1}, -1, FLT_MAX, VE}, { "pdy_rd", "Psy RD strength.", OFFSET(psy_rd), FF_OPT_TYPE_FLOAT, {-1 }, -1, FLT_MAX, VE}, { "psy_trellis", "Psy trellis strength", OFFSET(psy_trellis), FF_OPT_TYPE_FLOAT, {-1 }, -1, FLT_MAX, VE}, + { "rc_lookahead", "Number of frames to look ahead for frametype and ratecontrol", OFFSET(rc_lookahead), FF_OPT_TYPE_INT, {-1 }, -1, INT_MAX, VE }, { NULL }, }; diff --git a/libavcodec/options.c b/libavcodec/options.c index 365f8608ad..00a4376957 100644 --- a/libavcodec/options.c +++ b/libavcodec/options.c @@ -442,8 +442,8 @@ static const AVOption options[]={ {"psy_trellis", "specify psycho visual trellis", OFFSET(psy_trellis), FF_OPT_TYPE_FLOAT, {.dbl = -1 }, -1, FLT_MAX, V|E}, {"aq_mode", "specify aq method", OFFSET(aq_mode), FF_OPT_TYPE_INT, {.dbl = -1 }, -1, INT_MAX, V|E}, {"aq_strength", "specify aq strength", OFFSET(aq_strength), FF_OPT_TYPE_FLOAT, {.dbl = -1.0 }, -1, FLT_MAX, V|E}, -#endif {"rc_lookahead", "specify number of frames to look ahead for frametype", OFFSET(rc_lookahead), FF_OPT_TYPE_INT, {.dbl = 40 }, 0, INT_MAX, V|E}, +#endif {"ssim", "ssim will be calculated during encoding", 0, FF_OPT_TYPE_CONST, {.dbl = CODEC_FLAG2_SSIM }, INT_MIN, INT_MAX, V|E, "flags2"}, {"intra_refresh", "use periodic insertion of intra blocks instead of keyframes", 0, FF_OPT_TYPE_CONST, {.dbl = CODEC_FLAG2_INTRA_REFRESH }, INT_MIN, INT_MAX, V|E, "flags2"}, {"crf_max", "in crf mode, prevents vbv from lowering quality beyond this point", OFFSET(crf_max), FF_OPT_TYPE_FLOAT, {.dbl = DEFAULT }, 0, 51, V|E}, From c5dd0bc4ca977924825a74080ff1c294dda01427 Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Mon, 22 Aug 2011 07:55:34 +0200 Subject: [PATCH 11/14] libx264: add 'weightp' private option. Deprecate corresponding global option. --- libavcodec/avcodec.h | 4 ++-- libavcodec/libx264.c | 11 ++++++++++- libavcodec/options.c | 4 +++- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h index 77544e3837..414b1502f1 100644 --- a/libavcodec/avcodec.h +++ b/libavcodec/avcodec.h @@ -2712,6 +2712,7 @@ typedef struct AVCodecContext { */ int (*execute2)(struct AVCodecContext *c, int (*func)(struct AVCodecContext *c2, void *arg, int jobnr, int threadnr), void *arg2, int *ret, int count); +#if FF_API_X264_GLOBAL_OPTS /** * explicit P-frame weighted prediction analysis method * 0: off @@ -2720,9 +2721,8 @@ typedef struct AVCodecContext { * - encoding: Set by user. * - decoding: unused */ - int weighted_p_pred; + attribute_deprecated int weighted_p_pred; -#if FF_API_X264_GLOBAL_OPTS /** * AQ mode * 0: Disabled diff --git a/libavcodec/libx264.c b/libavcodec/libx264.c index 72033b9310..435f228b80 100644 --- a/libavcodec/libx264.c +++ b/libavcodec/libx264.c @@ -48,6 +48,7 @@ typedef struct X264Context { float psy_rd; float psy_trellis; int rc_lookahead; + int weightp; } X264Context; static void X264_log(void *p, int level, const char *fmt, va_list args) @@ -225,7 +226,6 @@ static av_cold int X264_init(AVCodecContext *avctx) x4->params.analyse.i_direct_mv_pred = avctx->directpred; x4->params.analyse.b_weighted_bipred = avctx->flags2 & CODEC_FLAG2_WPRED; - x4->params.analyse.i_weighted_pred = avctx->weighted_p_pred; if (avctx->me_method == ME_EPZS) x4->params.analyse.i_me_method = X264_ME_DIA; @@ -318,6 +318,8 @@ static av_cold int X264_init(AVCodecContext *avctx) x4->params.analyse.f_psy_trellis = avctx->psy_trellis; if (avctx->rc_lookahead >= 0) x4->params.rc.i_lookahead = avctx->rc_lookahead; + if (avctx->weighted_p_pred >= 0) + x4->params.analyse.i_weighted_pred = avctx->weighted_p_pred; #endif if (x4->aq_mode >= 0) @@ -330,6 +332,9 @@ static av_cold int X264_init(AVCodecContext *avctx) x4->params.analyse.f_psy_trellis = x4->psy_trellis; if (x4->rc_lookahead >= 0) x4->params.rc.i_lookahead = x4->rc_lookahead; + if (x4->weightp >= 0) + x4->params.analyse.i_weighted_pred = x4->weightp; + if (x4->fastfirstpass) @@ -414,6 +419,10 @@ static const AVOption options[] = { { "pdy_rd", "Psy RD strength.", OFFSET(psy_rd), FF_OPT_TYPE_FLOAT, {-1 }, -1, FLT_MAX, VE}, { "psy_trellis", "Psy trellis strength", OFFSET(psy_trellis), FF_OPT_TYPE_FLOAT, {-1 }, -1, FLT_MAX, VE}, { "rc_lookahead", "Number of frames to look ahead for frametype and ratecontrol", OFFSET(rc_lookahead), FF_OPT_TYPE_INT, {-1 }, -1, INT_MAX, VE }, + { "weightp", "Weighted prediction analysis method.", OFFSET(weightp), FF_OPT_TYPE_INT, {-1 }, -1, INT_MAX, VE, "weightp" }, + { "none", NULL, 0, FF_OPT_TYPE_CONST, {X264_WEIGHTP_NONE}, INT_MIN, INT_MAX, VE, "weightp" }, + { "simple", NULL, 0, FF_OPT_TYPE_CONST, {X264_WEIGHTP_SIMPLE}, INT_MIN, INT_MAX, VE, "weightp" }, + { "smart", NULL, 0, FF_OPT_TYPE_CONST, {X264_WEIGHTP_SMART}, INT_MIN, INT_MAX, VE, "weightp" }, { NULL }, }; diff --git a/libavcodec/options.c b/libavcodec/options.c index 00a4376957..6d40ef0b5b 100644 --- a/libavcodec/options.c +++ b/libavcodec/options.c @@ -141,7 +141,9 @@ static const AVOption options[]={ {"b_qfactor", "qp factor between p and b frames", OFFSET(b_quant_factor), FF_OPT_TYPE_FLOAT, {.dbl = 1.25 }, -FLT_MAX, FLT_MAX, V|E}, {"rc_strategy", "ratecontrol method", OFFSET(rc_strategy), FF_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX, V|E}, {"b_strategy", "strategy to choose between I/P/B-frames", OFFSET(b_frame_strategy), FF_OPT_TYPE_INT, {.dbl = 0 }, INT_MIN, INT_MAX, V|E}, -{"wpredp", "weighted prediction analysis method", OFFSET(weighted_p_pred), FF_OPT_TYPE_INT, {.dbl = 0 }, INT_MIN, INT_MAX, V|E}, +#if FF_API_X264_GLOBAL_OPTS +{"wpredp", "weighted prediction analysis method", OFFSET(weighted_p_pred), FF_OPT_TYPE_INT, {.dbl = -1 }, INT_MIN, INT_MAX, V|E}, +#endif {"ps", "rtp payload size in bytes", OFFSET(rtp_payload_size), FF_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX, V|E}, {"mv_bits", NULL, OFFSET(mv_bits), FF_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX}, {"header_bits", NULL, OFFSET(header_bits), FF_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX}, From 4ae30cac228e0987faa528e7e6305a52712b5ad9 Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Mon, 22 Aug 2011 07:55:34 +0200 Subject: [PATCH 12/14] libx264: add 'crf_max' private option. Deprecate corresponding global option. --- libavcodec/avcodec.h | 4 ++-- libavcodec/libx264.c | 5 +++++ libavcodec/options.c | 2 ++ 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h index 414b1502f1..c0dcae5094 100644 --- a/libavcodec/avcodec.h +++ b/libavcodec/avcodec.h @@ -2764,7 +2764,6 @@ typedef struct AVCodecContext { * - decoding: unused */ attribute_deprecated int rc_lookahead; -#endif /** * Constant rate factor maximum @@ -2773,7 +2772,8 @@ typedef struct AVCodecContext { * - encoding: Set by user. * - decoding: unused */ - float crf_max; + attribute_deprecated float crf_max; +#endif int log_level_offset; diff --git a/libavcodec/libx264.c b/libavcodec/libx264.c index 435f228b80..ebbb217a46 100644 --- a/libavcodec/libx264.c +++ b/libavcodec/libx264.c @@ -42,6 +42,7 @@ typedef struct X264Context { char *profile; int fastfirstpass; float crf; + float crf_max; int cqp; int aq_mode; float aq_strength; @@ -294,6 +295,9 @@ static av_cold int X264_init(AVCodecContext *avctx) x4->params.rc.i_rc_method = X264_RC_CQP; x4->params.rc.i_qp_constant = x4->cqp; } + + if (x4->crf_max >= 0) + x4->params.rc.f_rf_constant_max = x4->crf_max; } if (avctx->rc_buffer_size && avctx->rc_initial_buffer_occupancy && @@ -410,6 +414,7 @@ static const AVOption options[] = { { "profile", "Set profile restrictions (cf. x264 --fullhelp) ", OFFSET(profile), FF_OPT_TYPE_STRING, { 0 }, 0, 0, VE}, { "fastfirstpass", "Use fast settings when encoding first pass", OFFSET(fastfirstpass), FF_OPT_TYPE_INT, { 1 }, 0, 1, VE}, { "crf", "Select the quality for constant quality mode", OFFSET(crf), FF_OPT_TYPE_FLOAT, {-1 }, -1, FLT_MAX, VE }, + { "crf_max", "In CRF mode, prevents VBV from lowering quality beyond this point.",OFFSET(crf_max), FF_OPT_TYPE_FLOAT, {-1 }, -1, FLT_MAX, VE }, { "cqp", "Constant quantization parameter rate control method",OFFSET(cqp), FF_OPT_TYPE_INT, {-1 }, -1, INT_MAX, VE }, { "aq_mode", "AQ method", OFFSET(aq_mode), FF_OPT_TYPE_INT, {-1 }, -1, INT_MAX, VE, "aq_mode"}, { "none", NULL, 0, FF_OPT_TYPE_CONST, {X264_AQ_NONE}, INT_MIN, INT_MAX, VE, "aq_mode" }, diff --git a/libavcodec/options.c b/libavcodec/options.c index 6d40ef0b5b..784d3b11a6 100644 --- a/libavcodec/options.c +++ b/libavcodec/options.c @@ -448,7 +448,9 @@ static const AVOption options[]={ #endif {"ssim", "ssim will be calculated during encoding", 0, FF_OPT_TYPE_CONST, {.dbl = CODEC_FLAG2_SSIM }, INT_MIN, INT_MAX, V|E, "flags2"}, {"intra_refresh", "use periodic insertion of intra blocks instead of keyframes", 0, FF_OPT_TYPE_CONST, {.dbl = CODEC_FLAG2_INTRA_REFRESH }, INT_MIN, INT_MAX, V|E, "flags2"}, +#if FF_API_X264_GLOBAL_OPTS {"crf_max", "in crf mode, prevents vbv from lowering quality beyond this point", OFFSET(crf_max), FF_OPT_TYPE_FLOAT, {.dbl = DEFAULT }, 0, 51, V|E}, +#endif {"log_level_offset", "set the log level offset", OFFSET(log_level_offset), FF_OPT_TYPE_INT, {.dbl = 0 }, INT_MIN, INT_MAX }, #if FF_API_FLAC_GLOBAL_OPTS {"lpc_type", "deprecated, use flac-specific options", OFFSET(lpc_type), FF_OPT_TYPE_INT, {.dbl = AV_LPC_TYPE_DEFAULT }, AV_LPC_TYPE_DEFAULT, AV_LPC_TYPE_NB-1, A|E}, From 389e0a5a24bf5a08d2c9a4cb41c7ae143e5ef2a6 Mon Sep 17 00:00:00 2001 From: Alex Converse Date: Tue, 23 Aug 2011 14:30:11 -0700 Subject: [PATCH 13/14] avconv: Remove dead store. --- avconv.c | 1 - 1 file changed, 1 deletion(-) diff --git a/avconv.c b/avconv.c index efb9b12a32..6f1b23736e 100644 --- a/avconv.c +++ b/avconv.c @@ -1627,7 +1627,6 @@ static int output_packet(InputStream *ist, int ist_index, } break; } - ret = avpkt.size; avpkt.size = 0; } From b9630bcf8215034f5a50e1f6835d4c4366413618 Mon Sep 17 00:00:00 2001 From: Alex Converse Date: Tue, 23 Aug 2011 13:47:31 -0700 Subject: [PATCH 14/14] avconv: Replace goto redo on decode fail with continue. This checks for sigterm but otherwise is identical to the previous behavior. --- avconv.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/avconv.c b/avconv.c index 6f1b23736e..57721f8fb2 100644 --- a/avconv.c +++ b/avconv.c @@ -2246,7 +2246,6 @@ static int transcode(OutputFile *output_files, int64_t ipts_min; double opts_min; - redo: ipts_min = INT64_MAX; opts_min= 1e100; @@ -2361,7 +2360,7 @@ static int transcode(OutputFile *output_files, if (exit_on_error) exit_program(1); av_free_packet(&pkt); - goto redo; + continue; } discard_packet: