update x264 wrapper.

patch by Robert Swain.

Originally committed as revision 4784 to svn://svn.ffmpeg.org/ffmpeg/trunk
pull/126/head
Robert Swain 19 years ago committed by Loren Merritt
parent d6f41eeddc
commit 58f7833e8e
  1. 8
      ffmpeg.c
  2. 100
      libavcodec/avcodec.h
  3. 32
      libavcodec/utils.c
  4. 96
      libavcodec/x264.c

@ -2531,8 +2531,8 @@ static void opt_qmin(const char *arg)
{
video_qmin = atoi(arg);
if (video_qmin < 1 ||
video_qmin > 31) {
fprintf(stderr, "qmin must be >= 1 and <= 31\n");
video_qmin > 51) {
fprintf(stderr, "qmin must be >= 1 and <= 51\n");
exit(1);
}
}
@ -2541,8 +2541,8 @@ static void opt_qmax(const char *arg)
{
video_qmax = atoi(arg);
if (video_qmax < 1 ||
video_qmax > 31) {
fprintf(stderr, "qmax must be >= 1 and <= 31\n");
video_qmax > 51) {
fprintf(stderr, "qmax must be >= 1 and <= 51\n");
exit(1);
}
}

@ -363,6 +363,13 @@ extern int motion_estimation_method;
#define CODEC_FLAG2_STRICT_GOP 0x00000002 ///< strictly enforce GOP size
#define CODEC_FLAG2_NO_OUTPUT 0x00000004 ///< skip bitstream encoding
#define CODEC_FLAG2_LOCAL_HEADER 0x00000008 ///< place global headers at every keyframe instead of in extradata
#define CODEC_FLAG2_BPYRAMID 0x00000010 ///< H.264 allow b-frames to be used as references
#define CODEC_FLAG2_WPRED 0x00000020 ///< H.264 weighted biprediction for b-frames
#define CODEC_FLAG2_MIXED_REFS 0x00000040 ///< H.264 multiple references per partition
#define CODEC_FLAG2_8X8DCT 0x00000080 ///< H.264 high profile 8x8 transform
#define CODEC_FLAG2_FASTPSKIP 0x00000100 ///< H.264 fast pskip
#define CODEC_FLAG2_AUD 0x00000200 ///< H.264 access unit delimiters
#define CODEC_FLAG2_BRDO 0x00000400 ///< b-frame rate-distortion optimization
/* Unsupported options :
* Syntax Arithmetic coding (SAC)
@ -733,6 +740,8 @@ typedef struct AVCodecContext {
/**
* motion estimation algorithm used for video coding.
* 1 (zero), 2 (full), 3 (log), 4 (phods), 5 (epzs), 6 (x1), 7 (hex),
* 8 (umh), 9 (iter) [7, 8 are x264 specific, 9 is snow specific]
* - encoding: MUST be set by user.
* - decoding: unused
*/
@ -1879,6 +1888,97 @@ typedef struct AVCodecContext {
* - decoding: unused
*/
int brd_scale;
/**
* constant rate factor - quality-based VBR - values ~correspond to qps
* - encoding: set by user.
* - decoding: unused
*/
int crf;
/**
* constant quantization parameter rate control method
* - encoding: set by user.
* - decoding: unused
*/
int cqp;
/**
* minimum gop size
* - encoding: set by user.
* - decoding: unused
*/
int keyint_min;
/**
* number of reference frames
* - encoding: set by user.
* - decoding: unused
*/
int refs;
/**
* chroma qp offset from luma
* - encoding: set by user.
* - decoding: unused
*/
int chromaoffset;
/**
* influences how often b-frames are used
* - encoding: set by user.
* - decoding: unused
*/
int bframebias;
/**
* trellis RD quantization
* - encoding: set by user.
* - decoding: unused
*/
int trellis;
/**
* reduce fluctuations in qp (before curve compression)
* - encoding: set by user.
* - decoding: unused
*/
float complexityblur;
/**
* in-loop deblocking filter alphac0 parameter
* alpha is in the range -6...6
* - encoding: set by user.
* - decoding: unused
*/
int deblockalpha;
/**
* in-loop deblocking filter beta parameter
* beta is in the range -6...6
* - encoding: set by user.
* - decoding: unused
*/
int deblockbeta;
/**
* macroblock subpartition sizes to consider - p8x8, p4x4, b8x8, i8x8, i4x4
* - encoding: set by user.
* - decoding: unused
*/
int partitions;
#define X264_PART_I4X4 0x001 /* Analyse i4x4 */
#define X264_PART_I8X8 0x002 /* Analyse i8x8 (requires 8x8 transform) */
#define X264_PART_P8X8 0x010 /* Analyse p16x8, p8x16 and p8x8 */
#define X264_PART_P4X4 0x020 /* Analyse p8x4, p4x8, p4x4 */
#define X264_PART_B8X8 0x100 /* Analyse b16x8, b8x16 and b8x8 */
/**
* direct mv prediction mode - 0 (none), 1 (spatial), 2 (temporal)
* - encoding: set by user.
* - decoding: unused
*/
int directpred;
} AVCodecContext;
/**

@ -679,7 +679,7 @@ static AVOption options[]={
{"nr", "noise reduction", OFFSET(noise_reduction), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E},
{"rc_init_occupancy", NULL, OFFSET(rc_initial_buffer_occupancy), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E},
{"inter_threshold", NULL, OFFSET(inter_threshold), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E},
{"flags2", NULL, OFFSET(flags2), FF_OPT_TYPE_FLAGS, DEFAULT, INT_MIN, INT_MAX},
{"flags2", NULL, OFFSET(flags2), FF_OPT_TYPE_FLAGS, DEFAULT, INT_MIN, INT_MAX, V|A|E|D, "flags2"},
{"error_rate", NULL, OFFSET(error_rate), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX},
{"antialias", NULL, OFFSET(antialias_algo), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|D, "aa"},
{"auto", NULL, 0, FF_OPT_TYPE_CONST, FF_AA_AUTO, INT_MIN, INT_MAX, V|D, "aa"},
@ -709,6 +709,30 @@ static AVOption options[]={
{"me_penalty_compensation", NULL, OFFSET(me_penalty_compensation), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E},
{"bidir_refine", NULL, OFFSET(bidir_refine), FF_OPT_TYPE_INT, DEFAULT, 0, 4, V|E},
{"brd_scale", NULL, OFFSET(brd_scale), FF_OPT_TYPE_INT, DEFAULT, 0, 10, V|E},
{"crf", NULL, OFFSET(crf), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E},
{"cqp", NULL, OFFSET(cqp), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E},
{"keyint_min", NULL, OFFSET(keyint_min), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E},
{"refs", NULL, OFFSET(refs), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E},
{"chromaoffset", NULL, OFFSET(chromaoffset), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E},
{"bframebias", NULL, OFFSET(bframebias), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E},
{"trellis", NULL, OFFSET(trellis), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E},
{"directpred", NULL, OFFSET(directpred), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E},
{"bpyramid", NULL, 0, FF_OPT_TYPE_CONST, CODEC_FLAG2_BPYRAMID, INT_MIN, INT_MAX, V|E, "flags2"},
{"wpred", NULL, 0, FF_OPT_TYPE_CONST, CODEC_FLAG2_WPRED, INT_MIN, INT_MAX, V|E, "flags2"},
{"mixed_refs", NULL, 0, FF_OPT_TYPE_CONST, CODEC_FLAG2_MIXED_REFS, INT_MIN, INT_MAX, V|E, "flags2"},
{"8x8dct", NULL, 0, FF_OPT_TYPE_CONST, CODEC_FLAG2_8X8DCT, INT_MIN, INT_MAX, V|E, "flags2"},
{"fastpskip", NULL, 0, FF_OPT_TYPE_CONST, CODEC_FLAG2_FASTPSKIP, INT_MIN, INT_MAX, V|E, "flags2"},
{"aud", NULL, 0, FF_OPT_TYPE_CONST, CODEC_FLAG2_AUD, INT_MIN, INT_MAX, V|E, "flags2"},
{"brdo", NULL, 0, FF_OPT_TYPE_CONST, CODEC_FLAG2_BRDO, INT_MIN, INT_MAX, V|E, "flags2"},
{"complexityblur", NULL, OFFSET(complexityblur), FF_OPT_TYPE_FLOAT, DEFAULT, FLT_MIN, FLT_MAX, V|E},
{"deblockalpha", NULL, OFFSET(deblockalpha), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E},
{"deblockbeta", NULL, OFFSET(deblockbeta), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E},
{"partitions", NULL, OFFSET(partitions), FF_OPT_TYPE_FLAGS, DEFAULT, INT_MIN, INT_MAX, V|E, "partitions"},
{"parti4x4", NULL, 0, FF_OPT_TYPE_CONST, X264_PART_I4X4, INT_MIN, INT_MAX, V|E, "partitions"},
{"parti8x8", NULL, 0, FF_OPT_TYPE_CONST, X264_PART_I8X8, INT_MIN, INT_MAX, V|E, "partitions"},
{"partp4x4", NULL, 0, FF_OPT_TYPE_CONST, X264_PART_P4X4, INT_MIN, INT_MAX, V|E, "partitions"},
{"partp8x8", NULL, 0, FF_OPT_TYPE_CONST, X264_PART_P8X8, INT_MIN, INT_MAX, V|E, "partitions"},
{"partb8x8", NULL, 0, FF_OPT_TYPE_CONST, X264_PART_B8X8, INT_MIN, INT_MAX, V|E, "partitions"},
{NULL},
};
@ -728,7 +752,13 @@ void avcodec_get_context_defaults(AVCodecContext *s){
s->mb_lmin= FF_QP2LAMBDA * 2;
s->mb_lmax= FF_QP2LAMBDA * 31;
s->rc_eq= "tex^qComp";
s->cqp = -1;
s->refs = 1;
s->directpred = 2;
s->qcompress= 0.5;
s->complexityblur = 20.0;
s->keyint_min = 25;
s->flags2 = CODEC_FLAG2_FASTPSKIP;
s->max_qdiff= 3;
s->b_quant_factor=1.25;
s->b_quant_offset=1.25;

@ -20,6 +20,9 @@
#include "avcodec.h"
#include <x264.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef struct X264Context {
x264_param_t params;
@ -136,10 +139,32 @@ X264_init(AVCodecContext *avctx)
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;
if(avctx->rc_buffer_size)
x4->params.rc.b_cbr = 1;
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_rf_constant = avctx->crf;
else if(avctx->cqp > -1) x4->params.rc.i_qp_constant = avctx->cqp;
}
// 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.b_cbr = 1;
x4->params.i_bframe = avctx->max_b_frames;
x4->params.b_cabac = avctx->coder_type == FF_CODER_TYPE_AC;
x4->params.b_bframe_adaptive = avctx->b_frame_strategy;
x4->params.i_bframe_bias = avctx->bframebias;
x4->params.b_bframe_pyramid = (avctx->flags2 & CODEC_FLAG2_BPYRAMID);
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;
@ -147,10 +172,9 @@ X264_init(AVCodecContext *avctx)
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;
if(avctx->flags & CODEC_FLAG_QSCALE && avctx->global_quality > 0)
x4->params.rc.i_qp_constant =
12 + 6 * log2((double) avctx->global_quality / FF_QP2LAMBDA);
x4->params.i_frame_reference = avctx->refs;
x4->params.i_width = avctx->width;
x4->params.i_height = avctx->height;
@ -159,6 +183,68 @@ X264_init(AVCodecContext *avctx)
x4->params.i_fps_num = avctx->time_base.den;
x4->params.i_fps_den = avctx->time_base.num;
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 x4->params.analyse.i_me_method = X264_ME_HEX;
x4->params.analyse.i_me_range = avctx->me_range;
x4->params.analyse.i_subpel_refine = avctx->me_subpel_quality;
x4->params.analyse.b_bframe_rdo = (avctx->flags2 & CODEC_FLAG2_BRDO);
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;
if(avctx->level > 0) x4->params.i_level_idc = avctx->level;
x4->params.rc.f_rate_tolerance =
(float)avctx->bit_rate_tolerance/avctx->bit_rate;
if((avctx->rc_buffer_size != 0) &&
(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;
}
else x4->params.rc.f_vbv_buffer_init = 0.9;
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;
x4->params.rc.psz_rc_eq = avctx->rc_eq;
x4->params.analyse.b_psnr = (avctx->flags & CODEC_FLAG_PSNR);
x4->params.i_log_level = X264_LOG_DEBUG;
x4->params.b_aud = (avctx->flags2 & CODEC_FLAG2_AUD);
x4->params.i_threads = avctx->thread_count;
x4->enc = x264_encoder_open(&x4->params);

Loading…
Cancel
Save