[x264-devel] [PATCH] ratecontrol: Fix infinite loop with negative frame duration
Vasilyev, Kostya
kvasilye at amazon.com
Mon Nov 9 21:59:19 UTC 2026
Sorry - typo, I meant x264 (of course) not x265.
Also attaching the reproducer inline, as our email system replaces attachments with links.
Sorry in advance if it gets messed up too.
Thanks,
~ K
-----
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <x264.h>
/* Reproducer: VBV infinite loop in x264_ratecontrol_mb (clang -ffast-math builds, since d46938de).
*
*
1920x1020, preset medium, profile main, 4 frame threads, rc-lookahead 8, ABR 3777 kbps with
*
vbv-maxrate = vbv-bufsize = 3777, ratetol 0.02, no scenecut, VFR with timebase 1/1000.
*
Encodes 91 frames at 25 ms intervals from pts 1000, then a forced IDR at pts 3000 (pts goes
*
backwards) followed by 90 more frames.
*
*
Usage: rep [back=1] [luma=0]
*
back=1 second segment starts at pts 3000 (backwards) -> hangs
*
back=0 second segment starts at pts 3275 (monotonic) -> completes
/
*
int main( int argc, char argv )
{
*
int back = argc > 1 ? atoi( argv[1] ) : 1, fill = argc > 2 ? atoi( argv[2] ) : 0;
x264_param_t p;
x264_param_default_preset( &p, "medium", NULL );
p.i_threads = 4;
p.rc.i_rc_method = X264_RC_ABR;
p.rc.i_bitrate = 3777;
p.rc.i_vbv_max_bitrate = 3777;
p.rc.i_vbv_buffer_size = 3777;
p.rc.f_rate_tolerance = 0.02f;
p.rc.i_lookahead = 8;
p.i_width = 1920;
p.i_height = 1020;
p.b_vfr_input = 1;
p.i_timebase_num = 1;
p.i_timebase_den = 1000;
p.b_annexb = 0;
p.b_repeat_headers = 0;
p.b_open_gop = 0;
p.i_scenecut_threshold = 0;
p.i_keyint_max = 1073741824;
p.i_keyint_min = 0;
p.i_log_level = X264_LOG_ERROR;
x264_param_apply_profile( &p, "main" );
x264_t h = x264_encoder_open( &p );
if( !h )
{
puts( "open failed" );
return 1;
}
x264_picture_t in, out;
x264_picture_alloc( &in, X264_CSP_I420, 1920, 1020 );
memset( in.img.plane[0], fill, 1920 * 1020 );
memset( in.img.plane[1], 128, 960 * 510 );
memset( in.img.plane[2], 128, 960 * 510 );
int n = 0;
x264_nal_t nals;
int nn;
for( int seg = 0; seg < 2; seg++ )
{
int64_t base = seg == 0 ? 1000 : ( back ? 3000 : 3275 );
for( int i = 0; i <= 90; i++ )
{
in.i_pts = base + i * 25;
in.i_type = i == 0 ? X264_TYPE_IDR : X264_TYPE_AUTO;
if( x264_encoder_encode( h, &nals, &nn, &in, &out ) > 0 )
n++;
}
fprintf( stderr, "seg %d done, %d frames out
*
", seg, n );
*
}
while( x264_encoder_delayed_frames( h ) )
if( x264_encoder_encode( h, &nals, &nn, NULL, &out ) > 0 )
n++;
printf( "ok, %d frames
*
", n );
*
x264_encoder_close( h );
return 0;
*
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.videolan.org/pipermail/x264-devel/attachments/20261109/ed743a31/attachment-0001.htm>
More information about the x264-devel
mailing list