Hi,<br>     i&#39;m developing a program using x264 api starting by the source code of x264.c, and I encurr in a problem that probably i miss any operations. I need to minimize the frame delay, so for this reason initially i have developed forcing using only one thread. The program in this case works correctly. Then, for maximize the performance i simply set the i_threads=2 to enabling multi-threading, and I expect a frame delay of one frame, but the result is very different. I test the encoder on a sequence of 100 frames, and for all 100 frames the encoder function return a zero value for i_nal, at the end in the flush _delayed_frame loop  i  have again  2 encoder function calling with i_nal null, and then at the third passing i have i_nal=1 but i have this error:<br>
test_x264_2thread: common/frame.c:971: x264_frame_push_unused: Assertion `frame-&gt;i_reference_count &gt; 0&#39; failed.<br>The strange things is that with param.i_threads=1 always works without problem.<br>If i force the settings of x264.c by specifying it before calling the encoder function to be equal at the settings that i specify in my program i haven&#39;t this error. What could be the problem?<br>
I also include my encoding functions:<br><br>int  static Encode_frame( x264_t *h, x264_picture_t *pic )<br>{<br>    x264_picture_t pic_out;<br>    x264_nal_t *nal;<br>    int i_nal, i, i_nalu_size;<br>    int buffersize=0;<br>
<br>    i_nalu_size = 0;<br><br><br><br>    if( x264_encoder_encode( h, &amp;nal, &amp;i_nal, pic, &amp;pic_out ) &lt; 0 )<br>    {<br>        fprintf( stderr, &quot;x264 [error]: x264_encoder_encode failed\n&quot; );<br>
        return -1;<br>    }<br><br>    printf(&quot;inal:%d\n&quot;,i_nal);<br><br>    for( i = 0; i &lt; i_nal; i++ )<br>    {<br>        int i_size;<br><br>        if( mux_buffer_size &lt; nal[i].i_payload * 3/2 + 4 )<br>
        {<br>            mux_buffer_size = nal[i].i_payload * 2 + 4;<br>            free( mux_buffer );<br>            mux_buffer = (uint8_t*)malloc( mux_buffer_size );<br>            if( !mux_buffer )<br>                return -1;<br>
        }<br><br>        i_size = mux_buffer_size;<br>        x264_nal_encode( mux_buffer, &amp;i_size, 1, &amp;nal[i] );<br>        i_nalu_size += write_nal_unit(  mux_buffer, i_size );<br>        printf(&quot;i_nalu_size: %d\n&quot;,i_nalu_size);<br>
        if( i_nalu_size &lt; 0 )<br>            return -1;<br>        buffersize += i_nalu_size;<br>    }<br><br>    return buffersize;<br>}<br><br>static int  Encode(FILE *f)<br>{<br>    x264_t *h;<br>    x264_picture_t pic;<br>
    x264_param_t param;<br><br>    int     i_frame;<br>    int64_t i_file;<br>    int     i_frame_size;<br>    struct timeb t_ini,t_fin;<br>    double media=0.0;<br><br>    x264_param_default( &amp;param );<br>    param.i_width=352;<br>
    param.i_height=288;<br><br>    /*Modified*/<br>    param.rc.i_lookahead = 0;<br>    param.i_threads = 2;<br>    //Gop Size maximum 20<br>    param.i_keyint_max = 20;<br><br>    //only pass1 mode for low latency<br>    param.rc.b_stat_read = 0;<br>
    param.rc.b_stat_write = 1;<br><br>    //We don&#39;t need bframe<br>    param.i_bframe = 0;<br>    param.i_bframe_adaptive = 0;<br>     //Setting CRF<br>    param.rc.i_rc_method = X264_RC_CRF;<br>    //Specify quality of encoding<br>
    param.rc.f_rf_constant = 30;<br><br><br>    //Maximum dimension of the gop<br>    param.i_keyint_max = 20;<br><br>    /*end modify*/<br><br>    if( ( h = x264_encoder_open( &amp;param ) ) == NULL )<br>    {<br>        fprintf( stderr, &quot;x264 [error]: x264_encoder_open failed\n&quot; );<br>
        return -1;<br>    }<br><br>    /* Create a new pic */<br>    if( x264_picture_alloc( &amp;pic, X264_CSP_I420, param.i_width, param.i_height ) &lt; 0 )<br>    {<br>        fprintf( stderr, &quot;x264 [error]: malloc failed\n&quot; );<br>
        return -1;<br>    }<br>    /* Encode frames */<br>    for( i_frame = 0, i_file = 0; read_yuv_frame(f, &amp;pic, 352,288); )<br>    {<br>        pic.i_pts = (int64_t)i_frame * param.i_fps_den;<br>        printf(&quot;%d\n&quot;,param.i_fps_den);<br>
<br><br>        /* Do not force any parameters */<br>        pic.i_type = X264_TYPE_AUTO;<br>        pic.i_qpplus1 = 0;<br><br>        ftime(&amp;t_ini);<br>    i_frame_size = Encode_frame( h,  &amp;pic );<br>        ftime(&amp;t_fin);<br>
        media = media + (t_fin.time-t_ini.time)*1000 + t_fin.millitm - t_ini.millitm;<br>        printf(&quot;Encoding time frame n°%d:%d\n&quot;,i_frame,(t_fin.time-t_ini.time)*1000 + t_fin.millitm - t_ini.millitm);<br>    if( i_frame_size &lt; 0 )<br>
            return -1;<br>        i_frame++;<br>    }<br><br>    /*modified*/<br>    int z=0;<br>    media = media/i_frame;<br><br>    printf(&quot;Media tempo di encoding:%0.3f\n&quot;,media);<br><br>    /* Flush delayed frames */<br>
    while( x264_encoder_delayed_frames( h ) )<br>    {<br>        z++;<br>        i_frame_size = Encode_frame( h, NULL );<br>        if( i_frame_size &lt; 0 )<br>            return -1;<br>        i_file += i_frame_size;<br>
    }<br><br><br>    x264_picture_clean( &amp;pic );<br>    x264_encoder_close( h );<br>    free( mux_buffer );<br><br>    return 0;<br>}<br><br>Thanks for the attention. <br>Best regards.<br>