[x264-devel] libx264 x264_encoder_encode question

Jason Garrett-Glaser jason at x264.com
Thu Dec 23 18:15:47 CET 2010


On Thu, Dec 23, 2010 at 12:11 PM,  <chris at crazyfool.org> wrote:
> Hi Guys
>
> Firstly thanks for providing such a great open source project, secondly I
> hope you can help with a question I have.
>
> I have an application which uses FFMPEG/X264 via the API, and specifically
> the function x264_encoder_encode to encode. Since updating the x264 lib to
> pick the various improvements I have come across an issue in my application.
> Briefly, my app receives video from the network and encodes it on the fly,
> in real time. Since the update I have noticed that the encode call seems to
> be delaying the encode until a specific number of frames have been buffered,
> in my case 40. This delay only appears to occur at the start of the stream.
>
> I believe the relevant code is :
>
> if( h->frames.i_input <= h->frames.i_delay + 1 - h->i_thread_frames ) inside
> x264_encoder_encode.
>
> Now I realise from looking at the GIT logs this is not new code, but rather
> the initialisation of the variable i_delay has changed.
>
> In my old x264 code, we never seemed to perform this buffering at the start,
> however now in the new code we do. I believe this is due to the i_delay
> being different.
>
> You are probably wondering what the problem is, well when i use the latest
> x264 code and it buffers the frames at the start, for some reason I am
> losing frames at the end of my output stream.

You aren't flushing delayed frames properly.

See for example the following code in x264.c:

    while( !b_ctrl_c && x264_encoder_delayed_frames( h ) )
    {
        prev_dts = last_dts;
        i_frame_size = encode_frame( h, opt->hout, NULL, &last_dts );
        if( i_frame_size < 0 )
            return -1;
        i_file += i_frame_size;
        if( i_frame_size )
        {
            i_frame_output++;
            if( i_frame_output == 1 )
                first_dts = prev_dts = last_dts;
        }
        if( opt->b_progress && i_frame_output % i_update_interval == 0
&& i_frame_output )
            print_status( i_start, i_frame_output,
param->i_frame_total, i_file, param, 2 * last_dts - prev_dts -
first_dts );
    }

Jason


More information about the x264-devel mailing list