さきゅばす/いんきゅばす用libav(実験的)
Révision | af1e247038c6c728b857118405adee0d2f184b40 (tree) |
---|---|
l'heure | 2011-09-12 15:45:55 |
Auteur | Anton Khirnov <anton@khir...> |
Commiter | Anton Khirnov |
libxavs: add private options corresponding to deprecated global options
Code mostly copied from libx264 wrapper.
@@ -24,8 +24,11 @@ | ||
24 | 24 | #include <string.h> |
25 | 25 | #include <math.h> |
26 | 26 | #include <stdint.h> |
27 | +#include <float.h> | |
27 | 28 | #include <xavs.h> |
28 | 29 | #include "avcodec.h" |
30 | +#include "internal.h" | |
31 | +#include "libavutil/opt.h" | |
29 | 32 | |
30 | 33 | #define END_OF_STREAM 0x001 |
31 | 34 |
@@ -41,6 +44,15 @@ typedef struct XavsContext { | ||
41 | 44 | int sei_size; |
42 | 45 | AVFrame out_pic; |
43 | 46 | int end_of_stream; |
47 | + float crf; | |
48 | + int cqp; | |
49 | + int b_bias; | |
50 | + float cplxblur; | |
51 | + int direct_pred; | |
52 | + int aud; | |
53 | + int fast_pskip; | |
54 | + int mbtree; | |
55 | + int mixed_refs; | |
44 | 56 | } XavsContext; |
45 | 57 | |
46 | 58 | static void XAVS_log(void *p, int level, const char *fmt, va_list args) |
@@ -181,13 +193,17 @@ static av_cold int XAVS_init(AVCodecContext *avctx) | ||
181 | 193 | x4->params.pf_log = XAVS_log; |
182 | 194 | x4->params.p_log_private = avctx; |
183 | 195 | x4->params.i_keyint_max = avctx->gop_size; |
184 | - x4->params.rc.i_bitrate = avctx->bit_rate / 1000; | |
196 | + if (avctx->bit_rate) { | |
197 | + x4->params.rc.i_bitrate = avctx->bit_rate / 1000; | |
198 | + x4->params.rc.i_rc_method = XAVS_RC_ABR; | |
199 | + } | |
185 | 200 | x4->params.rc.i_vbv_buffer_size = avctx->rc_buffer_size / 1000; |
186 | 201 | x4->params.rc.i_vbv_max_bitrate = avctx->rc_max_rate / 1000; |
187 | 202 | x4->params.rc.b_stat_write = avctx->flags & CODEC_FLAG_PASS1; |
188 | 203 | if (avctx->flags & CODEC_FLAG_PASS2) { |
189 | 204 | x4->params.rc.b_stat_read = 1; |
190 | 205 | } else { |
206 | +#if FF_API_X264_GLOBAL_OPTS | |
191 | 207 | if (avctx->crf) { |
192 | 208 | x4->params.rc.i_rc_method = XAVS_RC_CRF; |
193 | 209 | x4->params.rc.f_rf_constant = avctx->crf; |
@@ -195,19 +211,63 @@ static av_cold int XAVS_init(AVCodecContext *avctx) | ||
195 | 211 | x4->params.rc.i_rc_method = XAVS_RC_CQP; |
196 | 212 | x4->params.rc.i_qp_constant = avctx->cqp; |
197 | 213 | } |
214 | +#endif | |
215 | + | |
216 | + if (x4->crf >= 0) { | |
217 | + x4->params.rc.i_rc_method = XAVS_RC_CRF; | |
218 | + x4->params.rc.f_rf_constant = x4->crf; | |
219 | + } else if (x4->cqp >= 0) { | |
220 | + x4->params.rc.i_rc_method = XAVS_RC_CQP; | |
221 | + x4->params.rc.i_qp_constant = x4->cqp; | |
222 | + } | |
198 | 223 | } |
199 | 224 | |
200 | - /* if neither crf nor cqp modes are selected we have to enable the RC */ | |
201 | - /* we do it this way because we cannot check if the bitrate has been set */ | |
202 | - if (!(avctx->crf || (avctx->cqp > -1))) | |
203 | - x4->params.rc.i_rc_method = XAVS_RC_ABR; | |
225 | +#if FF_API_X264_GLOBAL_OPTS | |
226 | + if (avctx->bframebias) | |
227 | + x4->params.i_bframe_bias = avctx->bframebias; | |
228 | + if (avctx->deblockalpha) | |
229 | + x4->params.i_deblocking_filter_alphac0 = avctx->deblockalpha; | |
230 | + if (avctx->deblockbeta) | |
231 | + x4->params.i_deblocking_filter_beta = avctx->deblockbeta; | |
232 | + if (avctx->complexityblur >= 0) | |
233 | + x4->params.rc.f_complexity_blur = avctx->complexityblur; | |
234 | + if (avctx->directpred >= 0) | |
235 | + x4->params.analyse.i_direct_mv_pred = avctx->directpred; | |
236 | + if (avctx->partitions) { | |
237 | + if (avctx->partitions & XAVS_PART_I8X8) | |
238 | + x4->params.analyse.inter |= XAVS_ANALYSE_I8x8; | |
239 | + if (avctx->partitions & XAVS_PART_P8X8) | |
240 | + x4->params.analyse.inter |= XAVS_ANALYSE_PSUB16x16; | |
241 | + if (avctx->partitions & XAVS_PART_B8X8) | |
242 | + x4->params.analyse.inter |= XAVS_ANALYSE_BSUB16x16; | |
243 | + } | |
244 | + x4->params.rc.b_mb_tree = !!(avctx->flags2 & CODEC_FLAG2_MBTREE); | |
245 | + x4->params.b_aud = avctx->flags2 & CODEC_FLAG2_AUD; | |
246 | + x4->params.analyse.b_mixed_references = avctx->flags2 & CODEC_FLAG2_MIXED_REFS; | |
247 | + x4->params.analyse.b_fast_pskip = avctx->flags2 & CODEC_FLAG2_FASTPSKIP; | |
248 | + x4->params.analyse.b_weighted_bipred = avctx->flags2 & CODEC_FLAG2_WPRED; | |
249 | +#endif | |
250 | + | |
251 | + if (x4->aud >= 0) | |
252 | + x4->params.b_aud = x4->aud; | |
253 | + if (x4->mbtree >= 0) | |
254 | + x4->params.rc.b_mb_tree = x4->mbtree; | |
255 | + if (x4->direct_pred >= 0) | |
256 | + x4->params.analyse.i_direct_mv_pred = x4->direct_pred; | |
257 | + if (x4->fast_pskip >= 0) | |
258 | + x4->params.analyse.b_fast_pskip = x4->fast_pskip; | |
259 | + if (x4->mixed_refs >= 0) | |
260 | + x4->params.analyse.b_mixed_references = x4->mixed_refs; | |
261 | + if (x4->b_bias != INT_MIN) | |
262 | + x4->params.i_bframe_bias = x4->b_bias; | |
263 | + if (x4->cplxblur >= 0) | |
264 | + x4->params.rc.f_complexity_blur = x4->cplxblur; | |
204 | 265 | |
205 | 266 | x4->params.i_bframe = avctx->max_b_frames; |
206 | 267 | /* cabac is not included in AVS JiZhun Profile */ |
207 | 268 | x4->params.b_cabac = 0; |
208 | 269 | |
209 | 270 | x4->params.i_bframe_adaptive = avctx->b_frame_strategy; |
210 | - x4->params.i_bframe_bias = avctx->bframebias; | |
211 | 271 | |
212 | 272 | avctx->has_b_frames = !!avctx->max_b_frames; |
213 | 273 |
@@ -220,8 +280,6 @@ static av_cold int XAVS_init(AVCodecContext *avctx) | ||
220 | 280 | x4->params.i_scenecut_threshold = avctx->scenechange_threshold; |
221 | 281 | |
222 | 282 | // x4->params.b_deblocking_filter = avctx->flags & CODEC_FLAG_LOOP_FILTER; |
223 | - x4->params.i_deblocking_filter_alphac0 = avctx->deblockalpha; | |
224 | - x4->params.i_deblocking_filter_beta = avctx->deblockbeta; | |
225 | 283 | |
226 | 284 | x4->params.rc.i_qp_min = avctx->qmin; |
227 | 285 | x4->params.rc.i_qp_max = avctx->qmax; |
@@ -229,7 +287,6 @@ static av_cold int XAVS_init(AVCodecContext *avctx) | ||
229 | 287 | |
230 | 288 | x4->params.rc.f_qcompress = avctx->qcompress; /* 0.0 => cbr, 1.0 => constant qp */ |
231 | 289 | x4->params.rc.f_qblur = avctx->qblur; /* temporally blur quants */ |
232 | - x4->params.rc.f_complexity_blur = avctx->complexityblur; | |
233 | 290 | |
234 | 291 | x4->params.i_frame_reference = avctx->refs; |
235 | 292 |
@@ -241,20 +298,6 @@ static av_cold int XAVS_init(AVCodecContext *avctx) | ||
241 | 298 | x4->params.i_fps_num = avctx->time_base.den; |
242 | 299 | x4->params.i_fps_den = avctx->time_base.num; |
243 | 300 | x4->params.analyse.inter = XAVS_ANALYSE_I8x8 |XAVS_ANALYSE_PSUB16x16| XAVS_ANALYSE_BSUB16x16; |
244 | - if (avctx->partitions) { | |
245 | - if (avctx->partitions & XAVS_PART_I8X8) | |
246 | - x4->params.analyse.inter |= XAVS_ANALYSE_I8x8; | |
247 | - | |
248 | - if (avctx->partitions & XAVS_PART_P8X8) | |
249 | - x4->params.analyse.inter |= XAVS_ANALYSE_PSUB16x16; | |
250 | - | |
251 | - if (avctx->partitions & XAVS_PART_B8X8) | |
252 | - x4->params.analyse.inter |= XAVS_ANALYSE_BSUB16x16; | |
253 | - } | |
254 | - | |
255 | - x4->params.analyse.i_direct_mv_pred = avctx->directpred; | |
256 | - | |
257 | - x4->params.analyse.b_weighted_bipred = avctx->flags2 & CODEC_FLAG2_WPRED; | |
258 | 301 | |
259 | 302 | switch (avctx->me_method) { |
260 | 303 | case ME_EPZS: |
@@ -279,11 +322,9 @@ static av_cold int XAVS_init(AVCodecContext *avctx) | ||
279 | 322 | x4->params.analyse.i_me_range = avctx->me_range; |
280 | 323 | x4->params.analyse.i_subpel_refine = avctx->me_subpel_quality; |
281 | 324 | |
282 | - x4->params.analyse.b_mixed_references = avctx->flags2 & CODEC_FLAG2_MIXED_REFS; | |
283 | 325 | x4->params.analyse.b_chroma_me = avctx->me_cmp & FF_CMP_CHROMA; |
284 | 326 | /* AVS P2 only enables 8x8 transform */ |
285 | 327 | x4->params.analyse.b_transform_8x8 = 1; //avctx->flags2 & CODEC_FLAG2_8X8DCT; |
286 | - x4->params.analyse.b_fast_pskip = avctx->flags2 & CODEC_FLAG2_FASTPSKIP; | |
287 | 328 | |
288 | 329 | x4->params.analyse.i_trellis = avctx->trellis; |
289 | 330 | x4->params.analyse.i_noise_reduction = avctx->noise_reduction; |
@@ -303,14 +344,12 @@ static av_cold int XAVS_init(AVCodecContext *avctx) | ||
303 | 344 | |
304 | 345 | /* TAG:do we have MB tree RC method */ |
305 | 346 | /* what is the RC method we are now using? Default NO */ |
306 | - x4->params.rc.b_mb_tree = !!(avctx->flags2 & CODEC_FLAG2_MBTREE); | |
307 | 347 | x4->params.rc.f_ip_factor = 1 / fabs(avctx->i_quant_factor); |
308 | 348 | x4->params.rc.f_pb_factor = avctx->b_quant_factor; |
309 | 349 | x4->params.analyse.i_chroma_qp_offset = avctx->chromaoffset; |
310 | 350 | |
311 | 351 | x4->params.analyse.b_psnr = avctx->flags & CODEC_FLAG_PSNR; |
312 | 352 | x4->params.i_log_level = XAVS_LOG_DEBUG; |
313 | - x4->params.b_aud = avctx->flags2 & CODEC_FLAG2_AUD; | |
314 | 353 | x4->params.i_threads = avctx->thread_count; |
315 | 354 | x4->params.b_interlaced = avctx->flags & CODEC_FLAG_INTERLACED_DCT; |
316 | 355 |
@@ -336,6 +375,37 @@ static av_cold int XAVS_init(AVCodecContext *avctx) | ||
336 | 375 | return 0; |
337 | 376 | } |
338 | 377 | |
378 | +#define OFFSET(x) offsetof(XavsContext, x) | |
379 | +#define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM | |
380 | +static const AVOption options[] = { | |
381 | + { "crf", "Select the quality for constant quality mode", OFFSET(crf), FF_OPT_TYPE_FLOAT, {-1 }, -1, FLT_MAX, VE }, | |
382 | + { "qp", "Constant quantization parameter rate control method",OFFSET(cqp), FF_OPT_TYPE_INT, {-1 }, -1, INT_MAX, VE }, | |
383 | + { "b-bias", "Influences how often B-frames are used", OFFSET(b_bias), FF_OPT_TYPE_INT, {INT_MIN}, INT_MIN, INT_MAX, VE }, | |
384 | + { "cplxblur", "Reduce fluctuations in QP (before curve compression)", OFFSET(cplxblur), FF_OPT_TYPE_FLOAT, {-1 }, -1, FLT_MAX, VE}, | |
385 | + { "direct-pred", "Direct MV prediction mode", OFFSET(direct_pred), FF_OPT_TYPE_INT, {-1 }, -1, INT_MAX, VE, "direct-pred" }, | |
386 | + { "none", NULL, 0, FF_OPT_TYPE_CONST, { XAVS_DIRECT_PRED_NONE }, 0, 0, VE, "direct-pred" }, | |
387 | + { "spatial", NULL, 0, FF_OPT_TYPE_CONST, { XAVS_DIRECT_PRED_SPATIAL }, 0, 0, VE, "direct-pred" }, | |
388 | + { "temporal", NULL, 0, FF_OPT_TYPE_CONST, { XAVS_DIRECT_PRED_TEMPORAL }, 0, 0, VE, "direct-pred" }, | |
389 | + { "auto", NULL, 0, FF_OPT_TYPE_CONST, { XAVS_DIRECT_PRED_AUTO }, 0, 0, VE, "direct-pred" }, | |
390 | + { "aud", "Use access unit delimiters.", OFFSET(aud), FF_OPT_TYPE_INT, {-1 }, -1, 1, VE}, | |
391 | + { "mbtree", "Use macroblock tree ratecontrol.", OFFSET(mbtree), FF_OPT_TYPE_INT, {-1 }, -1, 1, VE}, | |
392 | + { "mixed-refs", "One reference per partition, as opposed to one reference per macroblock", OFFSET(mixed_refs), FF_OPT_TYPE_INT, {-1}, -1, 1, VE }, | |
393 | + { "fast-pskip", NULL, OFFSET(fast_pskip), FF_OPT_TYPE_INT, {-1 }, -1, 1, VE}, | |
394 | + { NULL }, | |
395 | +}; | |
396 | + | |
397 | +static const AVClass class = { | |
398 | + .class_name = "libxavs", | |
399 | + .item_name = av_default_item_name, | |
400 | + .option = options, | |
401 | + .version = LIBAVUTIL_VERSION_INT, | |
402 | +}; | |
403 | + | |
404 | +static const AVCodecDefault xavs_defaults[] = { | |
405 | + { "b", "0" }, | |
406 | + { NULL }, | |
407 | +}; | |
408 | + | |
339 | 409 | AVCodec ff_libxavs_encoder = { |
340 | 410 | .name = "libxavs", |
341 | 411 | .type = AVMEDIA_TYPE_VIDEO, |
@@ -347,5 +417,7 @@ AVCodec ff_libxavs_encoder = { | ||
347 | 417 | .capabilities = CODEC_CAP_DELAY, |
348 | 418 | .pix_fmts = (const enum PixelFormat[]) { PIX_FMT_YUV420P, PIX_FMT_NONE }, |
349 | 419 | .long_name = NULL_IF_CONFIG_SMALL("libxavs - the Chinese Audio Video Standard Encoder"), |
420 | + .priv_class = &class, | |
421 | + .defaults = xavs_defaults, | |
350 | 422 | }; |
351 | 423 |