之前我用同一份Source Code(包括ffmpeg 和x264及我上层调用的代码都是一样的),在Windows下和Linux下做同样的一件事情:编码H264视频,结果在Windows下跑是OK的,而在Linux下则一直报下面这个错误:
[libx264 @ 0x8b7d8b0]broken ffmpeg default settings detected
[libx264 @ 0x8b7d8b0]use an encoding preset (vpre)
详文请浏览:http://bbs.rosoo.net/thread-737-1-1.html
在翻阅了无数的文章后,发现其原因是在于x264内部的参数检测,归要到底还是由于自己在ffmpeg中设置的参数不正确导致的。以下是x264针对此判断代码如下:
相关判断位于encoder/encoder.c 393行:
-
- {
- int score = 0;
- score += h->param.analyse.i_me_range == 0;
- score += h->param.rc.i_qp_step == 3;
- score += h->param.i_keyint_max == 12;
- score += h->param.rc.i_qp_min == 2;
- score += h->param.rc.i_qp_max == 31;
- score += h->param.rc.f_qcompress == 0.5;
- score += fabs(h->param.rc.f_ip_factor - 1.25) < 0.01;
- score += fabs(h->param.rc.f_pb_factor - 1.25) < 0.01;
- score += h->param.analyse.inter == 0 && h->param.analyse.i_subpel_refine == 8;
- if( score >= 5 )
- {
- x264_log( h, X264_LOG_ERROR, "broken ffmpeg default settings detected\n" );
- x264_log( h, X264_LOG_ERROR, "use an encoding preset (vpre)\n" );
- return -1;
- }
- }
应用X264进行H.264编码,如果编码不能成功,大部分情况是编码参数选择不正确
请看图片:
这里边的编码参数大家应该看到了吧,那么如果我们用ffmpeg怎么设置这些编码参数呢?
代码为证:
- m_VCtx->codec_type = CODEC_TYPE_VIDEO;
- m_VCtx->bit_rate = bitrate * 1000;
- m_VCtx->width = width;
- m_VCtx->height = height;
- m_VCtx->time_base.den = fps;
- m_VCtx->time_base.num = 1;
- m_VCtx->gop_size = fps * 10;
-
- m_VCtx->crf = 26;
- m_VCtx->refs = 3;
- m_VCtx->flags2 = CODEC_FLAG2_MIXED_REFS;
- m_VCtx->max_b_frames = 3;
- m_VCtx->deblockbeta = -1;
- m_VCtx->deblockalpha = -1;
- m_VCtx->trellis = 2;
- m_VCtx->partitions = X264_PART_I4X4 | X264_PART_I8X8
- | X264_PART_P8X8 | X264_PART_P4X4 | X264_PART_B8X8;
- m_VCtx->flags2 |= CODEC_FLAG2_8X8DCT;
- m_VCtx->me_method = 8;
- m_VCtx->me_range = 16;
- m_VCtx->me_subpel_quality = 7;
- m_VCtx->qmin = 10;
- m_VCtx->qmax = 51;
- m_VCtx->rc_initial_buffer_occupancy = 0.9;
- m_VCtx->i_quant_factor = 1.0 / 1.40f;
-
- m_VCtx->b_quant_factor = 1.30f;
- m_VCtx->chromaoffset = 0;
- m_VCtx->max_qdiff = 4;
- m_VCtx->qcompress = 0.6f;
- m_VCtx->complexityblur = 20.0f;
- m_VCtx->qblur = 0.5f;
- m_VCtx->directpred = 1;
- m_VCtx->noise_reduction = 0;
- m_VCtx->pix_fmt = PIX_FMT_YUV420P;
-
- m_VCtx->thread_count = 1;
- m_VCtx->scenechange_threshold = 40;
- m_VCtx->bframebias = 0;
- m_VCtx->flags2 |= CODEC_FLAG2_AUD;
- m_VCtx->coder_type = FF_CODER_TYPE_AC;
- m_VCtx->flags |= CODEC_FLAG_LOOP_FILTER;
- m_VCtx->me_cmp = FF_CMP_CHROMA;
- m_VCtx->flags2 |= CODEC_FLAG2_FASTPSKIP;
- m_VCtx->flags2 |= CODEC_FLAG2_BPYRAMID;
- m_VCtx->flags2 |= CODEC_FLAG_NORMALIZE_AQP;
- m_VCtx->flags2 |= CODEC_FLAG2_WPRED;
- m_VCtx->keyint_min = 25;
- m_VCtx->flags2 |= CODEC_FLAG2_MBTREE;
-
-
-
-
-
-
-
-
-
-
- m_VCtx->level = 30;
- m_VCtx->b_frame_strategy = 2;
- m_VCtx->codec_tag = 7;
(落鹤生) |