Dear All:
I am using FFMpeg+x264 as a h264 encoder to encode video
stream in my application.But the encoder has 2 frame delay.The function
avcodec_encode_video() return 0 for the first 2 frames of the video stream, and 
the third
encoding output gets this of the first input video frame.I don't know whether 
is the problem of x264 or my settings.
  The following code shows the ffmpeg h264 encoder setting.
bool CH264::initEncode(const CVideoStreamParams* params)
{
   mpCodec = avcodec_find_encoder(CODEC_ID_H264);
   if (mpCodec == NULL)
   {
      return false;
   }

   mpCodecContext= avcodec_alloc_context();
   mpPicture= avcodec_alloc_frame();

   mpPictureSrc = new AVPicture();
   avpicture_alloc(mpPictureSrc, PIX_FMT_BGR24, params->getFrameWidth(), 
params->getFrameHeight());

     mpPictureDest = new AVPicture();
     avpicture_alloc(mpPictureDest, PIX_FMT_YUV420P, params->getFrameWidth(), 
params->getFrameHeight());

    mpCodecContext->coder_type = FF_CODER_TYPE_VLC; // CAVLC entropy coding
    mpCodecContext->max_b_frames = 0;
    mpCodecContext->refs = 3;
    AVRational ar = av_d2q(1. / mStreamParams.getFrameRate(), 
H264_TIMESTAMP_FREQ);
    mpCodecContext->time_base.num = ar.num;
    mpCodecContext->time_base.den = ar.den;
    mpCodecContext->gop_size = 
mpCodecContext->time_base.den/mpCodecContext->time_base.num;
    mpCodecContext->width = mStreamParams.getFrameWidth();
    mpCodecContext->height = mStreamParams.getFrameHeight();
    mpCodecContext->pix_fmt = PIX_FMT_YUV420P;

   mpCodecContext->crf = 23;
   mpCodecContext->flags2 |= CODEC_FLAG2_FASTPSKIP;
   mpCodecContext->me_method = 7;
   mpCodecContext->me_subpel_quality = 4;  
   mpCodecContext->trellis = 0;    
   mpCodecContext->thread_count = 0;
   // open codec
   if (avcodec_open(mpCodecContext, mpCodec) < 0)
   {
      freeEncode();
      return false;
   }
return true;
}

Is the problem of x264 or my setting?How to reduce delay to 0 frame?Thanks.

Leon 


      ___________________________________________________________ 
  好玩贺卡等你发,邮箱贺卡全新上线! 
http://card.mail.cn.yahoo.com/
_______________________________________________
libav-user mailing list
[email protected]
https://lists.mplayerhq.hu/mailman/listinfo/libav-user

Reply via email to