• R/O
  • HTTP
  • SSH
  • HTTPS

libav_saccubus: Commit

さきゅばす/いんきゅばす用libav(実験的)


Commit MetaInfo

Révisionaf1e247038c6c728b857118405adee0d2f184b40 (tree)
l'heure2011-09-12 15:45:55
AuteurAnton Khirnov <anton@khir...>
CommiterAnton Khirnov

Message de Log

libxavs: add private options corresponding to deprecated global options

Code mostly copied from libx264 wrapper.

Change Summary

Modification

--- a/libavcodec/libxavs.c
+++ b/libavcodec/libxavs.c
@@ -24,8 +24,11 @@
2424 #include <string.h>
2525 #include <math.h>
2626 #include <stdint.h>
27+#include <float.h>
2728 #include <xavs.h>
2829 #include "avcodec.h"
30+#include "internal.h"
31+#include "libavutil/opt.h"
2932
3033 #define END_OF_STREAM 0x001
3134
@@ -41,6 +44,15 @@ typedef struct XavsContext {
4144 int sei_size;
4245 AVFrame out_pic;
4346 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;
4456 } XavsContext;
4557
4658 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)
181193 x4->params.pf_log = XAVS_log;
182194 x4->params.p_log_private = avctx;
183195 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+ }
185200 x4->params.rc.i_vbv_buffer_size = avctx->rc_buffer_size / 1000;
186201 x4->params.rc.i_vbv_max_bitrate = avctx->rc_max_rate / 1000;
187202 x4->params.rc.b_stat_write = avctx->flags & CODEC_FLAG_PASS1;
188203 if (avctx->flags & CODEC_FLAG_PASS2) {
189204 x4->params.rc.b_stat_read = 1;
190205 } else {
206+#if FF_API_X264_GLOBAL_OPTS
191207 if (avctx->crf) {
192208 x4->params.rc.i_rc_method = XAVS_RC_CRF;
193209 x4->params.rc.f_rf_constant = avctx->crf;
@@ -195,19 +211,63 @@ static av_cold int XAVS_init(AVCodecContext *avctx)
195211 x4->params.rc.i_rc_method = XAVS_RC_CQP;
196212 x4->params.rc.i_qp_constant = avctx->cqp;
197213 }
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+ }
198223 }
199224
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;
204265
205266 x4->params.i_bframe = avctx->max_b_frames;
206267 /* cabac is not included in AVS JiZhun Profile */
207268 x4->params.b_cabac = 0;
208269
209270 x4->params.i_bframe_adaptive = avctx->b_frame_strategy;
210- x4->params.i_bframe_bias = avctx->bframebias;
211271
212272 avctx->has_b_frames = !!avctx->max_b_frames;
213273
@@ -220,8 +280,6 @@ static av_cold int XAVS_init(AVCodecContext *avctx)
220280 x4->params.i_scenecut_threshold = avctx->scenechange_threshold;
221281
222282 // 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;
225283
226284 x4->params.rc.i_qp_min = avctx->qmin;
227285 x4->params.rc.i_qp_max = avctx->qmax;
@@ -229,7 +287,6 @@ static av_cold int XAVS_init(AVCodecContext *avctx)
229287
230288 x4->params.rc.f_qcompress = avctx->qcompress; /* 0.0 => cbr, 1.0 => constant qp */
231289 x4->params.rc.f_qblur = avctx->qblur; /* temporally blur quants */
232- x4->params.rc.f_complexity_blur = avctx->complexityblur;
233290
234291 x4->params.i_frame_reference = avctx->refs;
235292
@@ -241,20 +298,6 @@ static av_cold int XAVS_init(AVCodecContext *avctx)
241298 x4->params.i_fps_num = avctx->time_base.den;
242299 x4->params.i_fps_den = avctx->time_base.num;
243300 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;
258301
259302 switch (avctx->me_method) {
260303 case ME_EPZS:
@@ -279,11 +322,9 @@ static av_cold int XAVS_init(AVCodecContext *avctx)
279322 x4->params.analyse.i_me_range = avctx->me_range;
280323 x4->params.analyse.i_subpel_refine = avctx->me_subpel_quality;
281324
282- x4->params.analyse.b_mixed_references = avctx->flags2 & CODEC_FLAG2_MIXED_REFS;
283325 x4->params.analyse.b_chroma_me = avctx->me_cmp & FF_CMP_CHROMA;
284326 /* AVS P2 only enables 8x8 transform */
285327 x4->params.analyse.b_transform_8x8 = 1; //avctx->flags2 & CODEC_FLAG2_8X8DCT;
286- x4->params.analyse.b_fast_pskip = avctx->flags2 & CODEC_FLAG2_FASTPSKIP;
287328
288329 x4->params.analyse.i_trellis = avctx->trellis;
289330 x4->params.analyse.i_noise_reduction = avctx->noise_reduction;
@@ -303,14 +344,12 @@ static av_cold int XAVS_init(AVCodecContext *avctx)
303344
304345 /* TAG:do we have MB tree RC method */
305346 /* what is the RC method we are now using? Default NO */
306- x4->params.rc.b_mb_tree = !!(avctx->flags2 & CODEC_FLAG2_MBTREE);
307347 x4->params.rc.f_ip_factor = 1 / fabs(avctx->i_quant_factor);
308348 x4->params.rc.f_pb_factor = avctx->b_quant_factor;
309349 x4->params.analyse.i_chroma_qp_offset = avctx->chromaoffset;
310350
311351 x4->params.analyse.b_psnr = avctx->flags & CODEC_FLAG_PSNR;
312352 x4->params.i_log_level = XAVS_LOG_DEBUG;
313- x4->params.b_aud = avctx->flags2 & CODEC_FLAG2_AUD;
314353 x4->params.i_threads = avctx->thread_count;
315354 x4->params.b_interlaced = avctx->flags & CODEC_FLAG_INTERLACED_DCT;
316355
@@ -336,6 +375,37 @@ static av_cold int XAVS_init(AVCodecContext *avctx)
336375 return 0;
337376 }
338377
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+
339409 AVCodec ff_libxavs_encoder = {
340410 .name = "libxavs",
341411 .type = AVMEDIA_TYPE_VIDEO,
@@ -347,5 +417,7 @@ AVCodec ff_libxavs_encoder = {
347417 .capabilities = CODEC_CAP_DELAY,
348418 .pix_fmts = (const enum PixelFormat[]) { PIX_FMT_YUV420P, PIX_FMT_NONE },
349419 .long_name = NULL_IF_CONFIG_SMALL("libxavs - the Chinese Audio Video Standard Encoder"),
420+ .priv_class = &class,
421+ .defaults = xavs_defaults,
350422 };
351423
Afficher sur ancien navigateur de dépôt.