[FFmpeg-devel] [RFC] Specifying KEYINT (-g) has no effect in libx264
Etienne Buira
etienne.buira.lists at free.fr
Sun Jul 3 12:40:01 CEST 2011
On Sat, Jul 02, 2011 at 12:43:59PM -0700, Baptiste Coudurier wrote:
> On 6/30/11 3:22 AM, Etienne Buira wrote:
> > On Sun, Jun 26, 2011 at 04:06:17PM -0700, Baptiste Coudurier wrote:
> >> On 6/26/11 7:05 AM, Etienne Buira wrote:
> >>> [...]
> >>>
> >>> Did you consider going back to libx264 ffpresets? IIRC the only issue
> >>> was to keep them up to date with libx264 defaults, but these should not
> >>> change very often, and I think such a check is scriptable. (all
> >>> solutions I see are listed in the mail before the one you replied to,
> >>> but have received no comments).
> >>
> >> No.
> >
> > Hi.
> >
> > Can you explain a bit more, or provide a pointer about issues on using
> > ffpresets? I searched a bit and couldn't find anything relevant.
Hi Baptiste, thanks for answering.
> IIRC it doesn't work on windows.
> It's the same mess to maintain when parameters change in libx264.
> libx264 provides a simple and nice API to use internal presets, we
> should use them.
Had ideas on how to fix all of them, but maybe cleaner to just use
x264opts.
Attached patch barely tested, if it's really the way established devs
want to go.
-------------- next part --------------
>From 4447ea919d2454bc3ef6567437324c3d6cd3b4d7 Mon Sep 17 00:00:00 2001
From: Etienne Buira <etienne.buira.lists at free.fr>
Date: Sun, 3 Jul 2011 12:31:41 +0200
Subject: [PATCH] Go x264opts
---
doc/encoders.texi | 19 ++-----
doc/faq.texi | 8 ++--
libavcodec/libx264.c | 142 +-------------------------------------------------
3 files changed, 9 insertions(+), 160 deletions(-)
diff --git a/doc/encoders.texi b/doc/encoders.texi
index a54f726..6e7ab95 100644
--- a/doc/encoders.texi
+++ b/doc/encoders.texi
@@ -551,33 +551,22 @@ Set the encoding preset.
@item tune @var{tune_name}
Tune the encoding params.
-Deprecated in favor of @var{x264_opts}
@item fastfirstpass @var{bool}
Use fast settings when encoding first pass, default value is 1.
-Deprecated in favor of @var{x264_opts}.
@item profile @var{profile_name}
Set profile restrictions.
-Deprecated in favor of @var{x264_opts}.
-
- at item level @var{level}
-Specify level (as defined by Annex A).
-Deprecated in favor of @var{x264_opts}.
-
- at item passlogfile @var{filename}
-Specify filename for 2 pass stats.
-Deprecated in favor of @var{x264_opts}.
-
- at item wpredp @var{wpred_type}
-Specify Weighted prediction for P-frames.
-Deprecated in favor of @var{x264_opts}.
@item x264opts @var{options}
Allow to set any x264 option, see x264 manual for a list.
@var{options} is a list of @var{key}=@var{value} couples separated by
":".
+
+To set paired values, you can comma separate them (example to set
+deblockalpha and deblockbeta, you should put "filter=alphaval,betaval"
+in @var{options}).
@end table
For example to specify libx264 encoding options with @file{ffmpeg}:
diff --git a/doc/faq.texi b/doc/faq.texi
index 225f139..39d5595 100644
--- a/doc/faq.texi
+++ b/doc/faq.texi
@@ -241,17 +241,17 @@ B-frames
@item example command line
ffmpeg -i input -acodec libfaac -ab 128k -vcodec mpeg4 -b 1200k -ar 24000 -mbd 2 -flags +mv4+aic -trellis 2 -cmp 2 -subcmp 2 -s 368x192 -r 30000/1001 -metadata title=X -f psp output.mp4
@item needed stuff for H.264
--acodec libfaac -vcodec libx264 width*height<=76800 width%16=0? height%16=0? -ar 48000 -coder 1 -r 30000/1001 or 15000/1001 -f psp
+-acodec libfaac -vcodec libx264 width*height<=76800 width%16=0? height%16=0? -ar 48000 -r 30000/1001 or 15000/1001 -f psp
@item working stuff for H.264
title, loop filter
@item non-working stuff for H.264
CAVLC
@item example command line
-ffmpeg -i input -acodec libfaac -ab 128k -vcodec libx264 -b 1200k -ar 48000 -mbd 2 -coder 1 -cmp 2 -subcmp 2 -s 368x192 -r 30000/1001 -metadata title=X -f psp -flags loop -trellis 2 -partitions parti4x4+parti8x8+partp4x4+partp8x8+partb8x8 output.mp4
+ffmpeg -i input -acodec libfaac -ab 128k -vcodec libx264 -ar 48000 -s 368x192 -r 30000/1001 -metadata title=X -f psp -x264opts bitrate=1200000:trellis=2:partitions=all output.mp4
@item higher resolution for newer PSP firmwares, width<=480, height<=272
--vcodec libx264 -level 21 -coder 1 -f psp
+-vcodec libx264 -x264opts level=21 -f psp
@item example command line
-ffmpeg -i input -acodec libfaac -ab 128k -ac 2 -ar 48000 -vcodec libx264 -level 21 -b 640k -coder 1 -f psp -flags +loop -trellis 2 -partitions +parti4x4+parti8x8+partp4x4+partp8x8+partb8x8 -g 250 -s 480x272 output.mp4
+ffmpeg -i input -acodec libfaac -ab 128k -ac 2 -ar 48000 -vcodec libx264 -f psp -s 480x272 -x264opts level=21:bitrate=640000:trellis=2:partitions=all output.mp4
@end table
@section Which are good parameters for encoding high quality MPEG-4?
diff --git a/libavcodec/libx264.c b/libavcodec/libx264.c
index cc5b983..0634e54 100644
--- a/libavcodec/libx264.c
+++ b/libavcodec/libx264.c
@@ -38,10 +38,7 @@ typedef struct X264Context {
char *preset;
char *tune;
char *profile;
- char *level;
int fastfirstpass;
- char *stats;
- char *weightp;
char *x264opts;
} X264Context;
@@ -211,91 +208,8 @@ static av_cold int X264_init(AVCodecContext *avctx)
{
X264Context *x4 = avctx->priv_data;
- x4->sei_size = 0;
x264_param_default(&x4->params);
- x4->params.i_keyint_max = avctx->gop_size;
-
- x4->params.i_bframe = avctx->max_b_frames;
- x4->params.b_cabac = avctx->coder_type == FF_CODER_TYPE_AC;
- x4->params.i_bframe_adaptive = avctx->b_frame_strategy;
- x4->params.i_bframe_bias = avctx->bframebias;
- x4->params.i_bframe_pyramid = avctx->flags2 & CODEC_FLAG2_BPYRAMID ? X264_B_PYRAMID_NORMAL : X264_B_PYRAMID_NONE;
-
- x4->params.i_keyint_min = avctx->keyint_min;
- if (x4->params.i_keyint_min > x4->params.i_keyint_max)
- x4->params.i_keyint_min = x4->params.i_keyint_max;
-
- x4->params.i_scenecut_threshold = avctx->scenechange_threshold;
-
- x4->params.b_deblocking_filter = avctx->flags & CODEC_FLAG_LOOP_FILTER;
- x4->params.i_deblocking_filter_alphac0 = avctx->deblockalpha;
- x4->params.i_deblocking_filter_beta = avctx->deblockbeta;
-
- x4->params.rc.i_qp_min = avctx->qmin;
- x4->params.rc.i_qp_max = avctx->qmax;
- x4->params.rc.i_qp_step = avctx->max_qdiff;
-
- x4->params.rc.f_qcompress = avctx->qcompress; /* 0.0 => cbr, 1.0 => constant qp */
- x4->params.rc.f_qblur = avctx->qblur; /* temporally blur quants */
- x4->params.rc.f_complexity_blur = avctx->complexityblur;
-
- x4->params.i_frame_reference = avctx->refs;
-
- x4->params.analyse.inter = 0;
- if (avctx->partitions) {
- if (avctx->partitions & X264_PART_I4X4)
- x4->params.analyse.inter |= X264_ANALYSE_I4x4;
- if (avctx->partitions & X264_PART_I8X8)
- x4->params.analyse.inter |= X264_ANALYSE_I8x8;
- if (avctx->partitions & X264_PART_P8X8)
- x4->params.analyse.inter |= X264_ANALYSE_PSUB16x16;
- if (avctx->partitions & X264_PART_P4X4)
- x4->params.analyse.inter |= X264_ANALYSE_PSUB8x8;
- if (avctx->partitions & X264_PART_B8X8)
- x4->params.analyse.inter |= X264_ANALYSE_BSUB16x16;
- }
-
- x4->params.analyse.i_direct_mv_pred = avctx->directpred;
-
- x4->params.analyse.b_weighted_bipred = avctx->flags2 & CODEC_FLAG2_WPRED;
-
- if (avctx->me_method == ME_EPZS)
- x4->params.analyse.i_me_method = X264_ME_DIA;
- else if (avctx->me_method == ME_HEX)
- x4->params.analyse.i_me_method = X264_ME_HEX;
- else if (avctx->me_method == ME_UMH)
- x4->params.analyse.i_me_method = X264_ME_UMH;
- else if (avctx->me_method == ME_FULL)
- x4->params.analyse.i_me_method = X264_ME_ESA;
- else if (avctx->me_method == ME_TESA)
- 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;
-
- 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;
- x4->params.analyse.i_subpel_refine = avctx->me_subpel_quality;
-
- x4->params.analyse.b_mixed_references = avctx->flags2 & CODEC_FLAG2_MIXED_REFS;
- x4->params.analyse.b_chroma_me = avctx->me_cmp & FF_CMP_CHROMA;
- x4->params.analyse.b_transform_8x8 = avctx->flags2 & CODEC_FLAG2_8X8DCT;
- x4->params.analyse.b_fast_pskip = avctx->flags2 & CODEC_FLAG2_FASTPSKIP;
-
- x4->params.analyse.i_trellis = avctx->trellis;
- x4->params.analyse.i_noise_reduction = avctx->noise_reduction;
-
- x4->params.rc.b_mb_tree = !!(avctx->flags2 & CODEC_FLAG2_MBTREE);
- x4->params.rc.f_ip_factor = 1 / fabs(avctx->i_quant_factor);
- x4->params.rc.f_pb_factor = avctx->b_quant_factor;
- x4->params.analyse.i_chroma_qp_offset = avctx->chromaoffset;
-
if (!x4->preset)
check_default_settings(avctx);
@@ -308,41 +222,6 @@ static av_cold int X264_init(AVCodecContext *avctx)
x4->params.p_log_private = avctx;
x4->params.i_log_level = X264_LOG_DEBUG;
- OPT_STR("weightp", x4->weightp);
-
- x4->params.b_intra_refresh = avctx->flags2 & CODEC_FLAG2_INTRA_REFRESH;
- x4->params.rc.i_bitrate = avctx->bit_rate / 1000;
- x4->params.rc.i_vbv_buffer_size = avctx->rc_buffer_size / 1000;
- x4->params.rc.i_vbv_max_bitrate = avctx->rc_max_rate / 1000;
- x4->params.rc.b_stat_write = avctx->flags & CODEC_FLAG_PASS1;
- if (avctx->flags & CODEC_FLAG_PASS2) {
- x4->params.rc.b_stat_read = 1;
- } else {
- 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) {
- x4->params.rc.i_rc_method = X264_RC_CQP;
- x4->params.rc.i_qp_constant = avctx->cqp;
- }
- }
-
- OPT_STR("stats", x4->stats);
-
- // if neither crf nor cqp modes are selected we have to enable the RC
- // we do it this way because we cannot check if the bitrate has been set
- if (!(avctx->crf || (avctx->cqp > -1)))
- x4->params.rc.i_rc_method = X264_RC_ABR;
-
- if (avctx->rc_buffer_size && avctx->rc_initial_buffer_occupancy &&
- (avctx->rc_initial_buffer_occupancy <= avctx->rc_buffer_size)) {
- x4->params.rc.f_vbv_buffer_init =
- (float)avctx->rc_initial_buffer_occupancy / avctx->rc_buffer_size;
- }
-
- OPT_STR("level", x4->level);
-
if(x4->x264opts){
const char *p= x4->x264opts;
while(p){
@@ -368,24 +247,8 @@ static av_cold int X264_init(AVCodecContext *avctx)
x4->params.i_fps_num = x4->params.i_timebase_den = avctx->time_base.den;
x4->params.i_fps_den = x4->params.i_timebase_num = avctx->time_base.num;
- x4->params.analyse.b_psnr = avctx->flags & CODEC_FLAG_PSNR;
- x4->params.analyse.b_ssim = avctx->flags2 & CODEC_FLAG2_SSIM;
-
- x4->params.b_aud = avctx->flags2 & CODEC_FLAG2_AUD;
-
- x4->params.i_threads = avctx->thread_count;
-
- x4->params.b_interlaced = avctx->flags & CODEC_FLAG_INTERLACED_DCT;
-
-// x4->params.b_open_gop = !(avctx->flags & CODEC_FLAG_CLOSED_GOP);
-
- x4->params.i_slice_count = avctx->slices;
-
x4->params.vui.b_fullrange = avctx->pix_fmt == PIX_FMT_YUVJ420P;
- if (avctx->flags & CODEC_FLAG_GLOBAL_HEADER)
- x4->params.b_repeat_headers = 0;
-
// update AVCodecContext with x264 parameters
avctx->has_b_frames = x4->params.i_bframe ?
x4->params.i_bframe_pyramid ? 2 : 1 : 0;
@@ -398,7 +261,7 @@ static av_cold int X264_init(AVCodecContext *avctx)
avctx->coded_frame = &x4->out_pic;
- if (avctx->flags & CODEC_FLAG_GLOBAL_HEADER) {
+ if (!x4->params.b_repeat_headers) {
x264_nal_t *nal;
int nnal, s, i;
@@ -423,9 +286,6 @@ static const AVOption options[] = {
{"tune", "Tune the encoding params", OFFSET(tune), FF_OPT_TYPE_STRING, {.str=NULL}, 0, 0, VE},
{"fastfirstpass", "Use fast settings when encoding first pass", OFFSET(fastfirstpass), FF_OPT_TYPE_INT, {.dbl=1}, 0, 1, VE},
{"profile", "Set profile restrictions", OFFSET(profile), FF_OPT_TYPE_STRING, {.str=NULL}, 0, 0, VE},
- {"level", "Specify level (as defined by Annex A)", OFFSET(level), FF_OPT_TYPE_STRING, {.str=NULL}, 0, 0, VE},
- {"passlogfile", "Filename for 2 pass stats", OFFSET(stats), FF_OPT_TYPE_STRING, {.str=NULL}, 0, 0, VE},
- {"wpredp", "Weighted prediction for P-frames", OFFSET(weightp), FF_OPT_TYPE_STRING, {.str=NULL}, 0, 0, VE},
{"x264opts", "x264 options", OFFSET(x264opts), FF_OPT_TYPE_STRING, {.str=NULL}, 0, 0, VE},
{ NULL },
};
--
1.7.3.4
More information about the ffmpeg-devel
mailing list