xpra icon
Bug tracker and wiki

Opened 3 weeks ago

Last modified 3 weeks ago

#2064 new defect

x264 produces too many delayed frames

Reported by: Antoine Martin Owned by: J. Max Mena
Priority: major Milestone: 2.5
Component: encodings Version: 2.4.x
Keywords: Cc:


As per r19322, we don't need to enable b-frames to see delayed frames.

Sometimes many:

compress:   0.3ms for  300x300  pixels at    0,0    for wid=2     using      h264 with ratio   0.9%  \
    (  351KB to     3KB), sequence   167, client_options=\
    {u'pts': 188, u'frame': 10, u'delayed': 11, 'csc': u'YUV420P', 'paint': False, u'type': u'B'}
compress:   0.7ms for  300x300  pixels at    0,0    for wid=2     using      h264 with ratio   2.1%  \
   (  351KB to     7KB), sequence   493, client_options=\
   {u'type': u'B', u'frame': 336, u'pts': 6929, u'delayed': 11, 'csc': u'YUV420P'}

We do send jpeg frames to prevent stuttering, but 11 frames is too many and will cause av-sync to fail.

Change History (3)

comment:1 Changed 3 weeks ago by Antoine Martin

Status: newassigned

Probably comes from this code setting i_delay:

    if( h->param.i_bframe_adaptive == X264_B_ADAPT_TRELLIS && !h->param.rc.b_stat_read )
        h->frames.i_delay = X264_MAX(h->param.i_bframe,3)*4;
        h->frames.i_delay = h->param.i_bframe;
    if( h->param.rc.b_mb_tree || h->param.rc.i_vbv_buffer_size )
        h->frames.i_delay = X264_MAX( h->frames.i_delay, h->param.rc.i_lookahead );
    i_slicetype_length = h->frames.i_delay;
    h->frames.i_delay += h->i_thread_frames - 1;
    h->frames.i_delay += h->param.i_sync_lookahead;
    h->frames.i_delay += h->param.b_vfr_input;

Because later on:

        if( h->frames.i_input <= h->frames.i_delay + 1 - h->i_thread_frames )
            /* Nothing yet to encode, waiting for filling of buffers */
            pic_out->i_type = X264_TYPE_AUTO;
            return 0;
Last edited 3 weeks ago by Antoine Martin (previous) (diff)

comment:2 Changed 3 weeks ago by Antoine Martin

  • the first one is OK, we already replace X264_B_ADAPT_TRELLIS with X264_B_ADAPT_FAST - and i_bframe should be set to 1 if enabled
  • the value of i_lookahead is not greater than i_bframe
  • i_thread_frames is set to: h->i_thread_frames = h->param.b_sliced_threads ? 1 : h->param.i_threads (see also #1840): when using sliced threads this is not a problem, but when sliced threads are disabled we end up using i_threads which is set to X264_THREADS_AUTO by default and this evaluates to i_threads = x264_cpu_num_processors() * (h->param.b_sliced_threads?2:3)/2; - this can be a fairly big number.
  • i_sync_lookahead should probably be capped (set elsewhere by the profile or tune)
  • b_vfr_input is always 0

comment:3 Changed 3 weeks ago by Antoine Martin

Owner: changed from Antoine Martin to J. Max Mena
Status: assignednew

Preparatory work in r21113.

  • we now always set the number of threads used to get_cpu_count()//2 (maximum 4)

on systems with 4 cpus or less, this probably doesn't make much of a difference.

Note: See TracTickets for help on using tickets.