comparison x264.c @ 2996:bf34de4233a0 libavcodec

update x264 wrapper. patch by Robert Swain.
author lorenm
date Thu, 29 Dec 2005 07:24:23 +0000
parents bfabfdf9ce55
children 0b546eab515d
comparison
equal deleted inserted replaced
2995:dfc271b90fe6 2996:bf34de4233a0
18 */ 18 */
19 19
20 #include "avcodec.h" 20 #include "avcodec.h"
21 #include <x264.h> 21 #include <x264.h>
22 #include <math.h> 22 #include <math.h>
23 #include <stdio.h>
24 #include <stdlib.h>
25 #include <string.h>
23 26
24 typedef struct X264Context { 27 typedef struct X264Context {
25 x264_param_t params; 28 x264_param_t params;
26 x264_t *enc; 29 x264_t *enc;
27 x264_picture_t pic; 30 x264_picture_t pic;
134 137
135 x4->params.i_keyint_max = avctx->gop_size; 138 x4->params.i_keyint_max = avctx->gop_size;
136 x4->params.rc.i_bitrate = avctx->bit_rate / 1000; 139 x4->params.rc.i_bitrate = avctx->bit_rate / 1000;
137 x4->params.rc.i_vbv_buffer_size = avctx->rc_buffer_size / 1000; 140 x4->params.rc.i_vbv_buffer_size = avctx->rc_buffer_size / 1000;
138 x4->params.rc.i_vbv_max_bitrate = avctx->rc_max_rate / 1000; 141 x4->params.rc.i_vbv_max_bitrate = avctx->rc_max_rate / 1000;
139 if(avctx->rc_buffer_size) 142 x4->params.rc.b_stat_write = (avctx->flags & CODEC_FLAG_PASS1);
140 x4->params.rc.b_cbr = 1; 143 if(avctx->flags & CODEC_FLAG_PASS2) x4->params.rc.b_stat_read = 1;
144 else{
145 if(avctx->crf) x4->params.rc.i_rf_constant = avctx->crf;
146 else if(avctx->cqp > -1) x4->params.rc.i_qp_constant = avctx->cqp;
147 }
148
149 // if neither crf nor cqp modes are selected we have to enable the RC
150 // we do it this way because we cannot check if the bitrate has been set
151 if(!(avctx->crf || (avctx->cqp > -1))) x4->params.rc.b_cbr = 1;
152
141 x4->params.i_bframe = avctx->max_b_frames; 153 x4->params.i_bframe = avctx->max_b_frames;
142 x4->params.b_cabac = avctx->coder_type == FF_CODER_TYPE_AC; 154 x4->params.b_cabac = avctx->coder_type == FF_CODER_TYPE_AC;
155 x4->params.b_bframe_adaptive = avctx->b_frame_strategy;
156 x4->params.i_bframe_bias = avctx->bframebias;
157 x4->params.b_bframe_pyramid = (avctx->flags2 & CODEC_FLAG2_BPYRAMID);
158
159 x4->params.i_keyint_min = avctx->keyint_min;
160 if(x4->params.i_keyint_min > x4->params.i_keyint_max)
161 x4->params.i_keyint_min = x4->params.i_keyint_max;
162
163 x4->params.i_scenecut_threshold = avctx->scenechange_threshold;
164
165 x4->params.b_deblocking_filter = (avctx->flags & CODEC_FLAG_LOOP_FILTER);
166 x4->params.i_deblocking_filter_alphac0 = avctx->deblockalpha;
167 x4->params.i_deblocking_filter_beta = avctx->deblockbeta;
143 168
144 x4->params.rc.i_qp_min = avctx->qmin; 169 x4->params.rc.i_qp_min = avctx->qmin;
145 x4->params.rc.i_qp_max = avctx->qmax; 170 x4->params.rc.i_qp_max = avctx->qmax;
146 x4->params.rc.i_qp_step = avctx->max_qdiff; 171 x4->params.rc.i_qp_step = avctx->max_qdiff;
147 172
148 x4->params.rc.f_qcompress = avctx->qcompress; /* 0.0 => cbr, 1.0 => constant qp */ 173 x4->params.rc.f_qcompress = avctx->qcompress; /* 0.0 => cbr, 1.0 => constant qp */
149 x4->params.rc.f_qblur = avctx->qblur; /* temporally blur quants */ 174 x4->params.rc.f_qblur = avctx->qblur; /* temporally blur quants */
150 175 x4->params.rc.f_complexity_blur = avctx->complexityblur;
151 if(avctx->flags & CODEC_FLAG_QSCALE && avctx->global_quality > 0) 176
152 x4->params.rc.i_qp_constant = 177 x4->params.i_frame_reference = avctx->refs;
153 12 + 6 * log2((double) avctx->global_quality / FF_QP2LAMBDA);
154 178
155 x4->params.i_width = avctx->width; 179 x4->params.i_width = avctx->width;
156 x4->params.i_height = avctx->height; 180 x4->params.i_height = avctx->height;
157 x4->params.vui.i_sar_width = avctx->sample_aspect_ratio.num; 181 x4->params.vui.i_sar_width = avctx->sample_aspect_ratio.num;
158 x4->params.vui.i_sar_height = avctx->sample_aspect_ratio.den; 182 x4->params.vui.i_sar_height = avctx->sample_aspect_ratio.den;
159 x4->params.i_fps_num = avctx->time_base.den; 183 x4->params.i_fps_num = avctx->time_base.den;
160 x4->params.i_fps_den = avctx->time_base.num; 184 x4->params.i_fps_den = avctx->time_base.num;
185
186 x4->params.analyse.inter = 0;
187 if(avctx->partitions){
188 if(avctx->partitions & X264_PART_I4X4)
189 x4->params.analyse.inter |= X264_ANALYSE_I4x4;
190 if(avctx->partitions & X264_PART_I8X8)
191 x4->params.analyse.inter |= X264_ANALYSE_I8x8;
192 if(avctx->partitions & X264_PART_P8X8)
193 x4->params.analyse.inter |= X264_ANALYSE_PSUB16x16;
194 if(avctx->partitions & X264_PART_P4X4)
195 x4->params.analyse.inter |= X264_ANALYSE_PSUB8x8;
196 if(avctx->partitions & X264_PART_B8X8)
197 x4->params.analyse.inter |= X264_ANALYSE_BSUB16x16;
198 }
199
200 x4->params.analyse.i_direct_mv_pred = avctx->directpred;
201
202 x4->params.analyse.b_weighted_bipred = (avctx->flags2 & CODEC_FLAG2_WPRED);
203
204 if(avctx->me_method == ME_EPZS)
205 x4->params.analyse.i_me_method = X264_ME_DIA;
206 else if(avctx->me_method == ME_HEX)
207 x4->params.analyse.i_me_method = X264_ME_HEX;
208 else if(avctx->me_method == ME_UMH)
209 x4->params.analyse.i_me_method = X264_ME_UMH;
210 else if(avctx->me_method == ME_FULL)
211 x4->params.analyse.i_me_method = X264_ME_ESA;
212 else x4->params.analyse.i_me_method = X264_ME_HEX;
213
214 x4->params.analyse.i_me_range = avctx->me_range;
215 x4->params.analyse.i_subpel_refine = avctx->me_subpel_quality;
216
217 x4->params.analyse.b_bframe_rdo = (avctx->flags2 & CODEC_FLAG2_BRDO);
218 x4->params.analyse.b_mixed_references =
219 (avctx->flags2 & CODEC_FLAG2_MIXED_REFS);
220 x4->params.analyse.b_chroma_me = (avctx->me_cmp & FF_CMP_CHROMA);
221 x4->params.analyse.b_transform_8x8 = (avctx->flags2 & CODEC_FLAG2_8X8DCT);
222 x4->params.analyse.b_fast_pskip = (avctx->flags2 & CODEC_FLAG2_FASTPSKIP);
223
224 x4->params.analyse.i_trellis = avctx->trellis;
225
226 if(avctx->level > 0) x4->params.i_level_idc = avctx->level;
227
228 x4->params.rc.f_rate_tolerance =
229 (float)avctx->bit_rate_tolerance/avctx->bit_rate;
230
231 if((avctx->rc_buffer_size != 0) &&
232 (avctx->rc_initial_buffer_occupancy <= avctx->rc_buffer_size)){
233 x4->params.rc.f_vbv_buffer_init =
234 (float)avctx->rc_initial_buffer_occupancy/avctx->rc_buffer_size;
235 }
236 else x4->params.rc.f_vbv_buffer_init = 0.9;
237
238 x4->params.rc.f_ip_factor = 1/fabs(avctx->i_quant_factor);
239 x4->params.rc.f_pb_factor = avctx->b_quant_factor;
240 x4->params.analyse.i_chroma_qp_offset = avctx->chromaoffset;
241 x4->params.rc.psz_rc_eq = avctx->rc_eq;
242
243 x4->params.analyse.b_psnr = (avctx->flags & CODEC_FLAG_PSNR);
244 x4->params.i_log_level = X264_LOG_DEBUG;
245
246 x4->params.b_aud = (avctx->flags2 & CODEC_FLAG2_AUD);
161 247
162 x4->params.i_threads = avctx->thread_count; 248 x4->params.i_threads = avctx->thread_count;
163 249
164 x4->enc = x264_encoder_open(&x4->params); 250 x4->enc = x264_encoder_open(&x4->params);
165 if(!x4->enc) 251 if(!x4->enc)