<div dir="ltr"><div><div>Ok, I fix this delay.<br><br></div>I change settings of encoder and set:<br><br>m_params->i_keyint_max = 5;    //At this interval of frames force setted IDR frame<br>m_params->b_intra_refresh = 0;  //use IDR frames instead periodic intra refresh<br>
<br></div>Now it work correctly. Thanks for all.<br><div><div><div class="gmail_extra"><br><br><div class="gmail_quote">2013/10/4 Дмитрий Бахтияров <span dir="ltr"><<a href="mailto:bakhtiyarov.dima@gmail.com" target="_blank">bakhtiyarov.dima@gmail.com</a>></span><br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div><div><div>Hi, all!<br><br></div>I'm developing network application, which can play H264 video from RTSP stream. I use live555 for RTSP/RTP processing, libx264 for encoding and ffmpeg for decoding. <br>

</div>My problem is in the decoder working - I have video stream with 12-15 fps, but avcodec_decode_video2 set got_image into not-null value very rarely - average 1 time per second or less. In a GUI its looks like very long freezes of interface, when one frame drawing on widgets few seconds.<br>

 When I connect to server using vlc all work correct - I have video with 12-15 fps.<br><br></div>I have a such code for decoding:<br><div><br>AVCodec* m_decoder;<br>AVCodecContext* m_decoderContext;<br>AVFrame* m_picture;<br>

AVPacket m_packet;<br><br></div><div>//initialisation of decoder<br>{<br></div><div>    avcodec_register_all();<br>    av_init_packet(&m_packet);<br>    m_decoder = avcodec_find_decoder(CODEC_ID_H264);<br>    if (!m_decoder)<br>

    {<br>        QString str = QString("Can't find H264 decoder!");<br>        emit criticalError(str);<br>    }<br>    m_decoderContext = avcodec_alloc_context3(m_decoder);<br><br>    m_decoderContext->flags |= CODEC_FLAG_TRUNCATED;<br>

    <br>    m_decoderContext->flags |= CODEC_FLAG_LOW_DELAY;<br>    //we can receive truncated frames<br>    m_decoderContext->flags2 |= CODEC_FLAG2_CHUNKS;<br><br>    AVDictionary* dictionary = nullptr;<br>    if (avcodec_open2(m_decoderContext, m_decoder, &dictionary) < 0)<br>

    {<br>        QString str = QString("Failed to open decoder!");<br>        emit criticalError(str);<br>    }<br>    qDebug() << "H264 Decoder successfully opened";<br>    m_picture = avcodec_alloc_frame();<br clear="all">

<div><div><div>}<br></div><div><br><br><br>//decoding frame; Frame_t is equal to vector<unsigned char><br>{<br>    Frame_t enc_frame;<br>    orig_frame >> enc_frame;<br>    m_packet.size = enc_frame.size();<br>

    m_packet.data = enc_frame.data();<br><br>    qDebug() << "H264Decoder: received encoded frame with framesize " << enc_frame.size();<br><br>    while(m_packet.size > 0)<br>    {<br>        int got_picture;<br>

        int len = avcodec_decode_video2(m_decoderContext, m_picture, &got_picture, &m_packet);<br>        if (len < 0)<br>        {<br>            QString err("Decoding error");<br>            qDebug() << err;<br>

            return false;<br>        }<br>        if (got_picture)<br>        {<br>            qDebug() << "H264Decoder: frame decoded!";<br>            //.......<br>        }<br>    }<br>}<br><br></div><div>

On the server side I have this encoder settings:<br>{<br>    m_params = new x264_param_t;<br>    if (x264_param_default_preset(m_params, "ultrafast", "zerolatency") != 0)<br>        qDebug() << "presetting default values for x264 parameters failed!";<br>

<br>    m_params->i_width = m_out_width;<br>    m_params->i_height = m_out_height;<br>    m_params->i_threads = 2;<br>    m_params->i_fps_num = m_fps;  //avg 12-15<br>    m_params->i_fps_den = 1;<br><br>    m_params->i_keyint_max = 24;<br>

    m_params->b_intra_refresh = 1;<br><br>    m_params->rc.i_rc_method = X264_RC_CRF;<br>    m_params->rc.f_rf_constant = 25;<br>    m_params->rc.f_rf_constant_max = 35;<br><br>    m_params->b_repeat_headers = 1;<br>

    m_params->b_annexb = 1;<br>    x264_param_apply_profile(m_params, "baseline");<br><br>    m_encoder = x264_encoder_open(m_params);<br>    if (m_encoder == nullptr)<br>    {<br>        qDebug() << "x264: encoder opening failed!";<br>

        abort();<br>    }<br>    m_in_pic = new x264_picture_t;<br><br>    if (x264_picture_alloc( m_in_pic, X264_CSP_I420, 640, 480 ) != 0)<br>        qDebug() << "x264: Picture allocating failed!";<br><br>

    x264_encoder_parameters(m_encoder, m_params);<br><br>    m_out_pic = new x264_picture_t;<br><br>    x264_nal_t* headers;<br>    int pi_nal;<br>    if (x264_encoder_headers(m_encoder, &headers, &pi_nal) < 0)<br>

        qDebug() << "Error creating NAL headers!";<br>}<br><br><br></div><div>What is the reason of this delay and how I can fix it?<br></div></div></div></div></div>
</blockquote></div><br><br></div></div></div></div>