[x264-devel] [Git][videolan/x264][master] Improve qpfile parsing resiliency
Anton Mitrofanov (@BugMaster)
gitlab at videolan.org
Sun Apr 23 17:56:21 UTC 2023
Anton Mitrofanov pushed to branch master at VideoLAN / x264
Commits:
a8b68ebf by Anton Mitrofanov at 2023-04-02T15:51:50+03:00
Improve qpfile parsing resiliency
- - - - -
1 changed file:
- x264.c
Changes:
=====================================
x264.c
=====================================
@@ -1802,18 +1802,26 @@ static void parse_qpfile( cli_opt_t *opt, x264_picture_t *pic, int i_frame )
{
int num = -1;
char type;
+ char buf[100];
while( num < i_frame )
{
int64_t file_pos = ftell( opt->qpfile );
int qp = -1;
- int ret = fscanf( opt->qpfile, "%d %c%*[ \t]%d\n", &num, &type, &qp );
+ int ret = fscanf( opt->qpfile, " %99[^\n]\n", buf );
+ if( ret == 1 )
+ {
+ ret = sscanf( buf, "%d %c %d", &num, &type, &qp );
+ if( ret == EOF )
+ ret = 0;
+ }
pic->i_type = X264_TYPE_AUTO;
pic->i_qpplus1 = X264_QP_AUTO;
if( num > i_frame || ret == EOF )
{
- if( file_pos < 0 || fseek( opt->qpfile, file_pos, SEEK_SET ) )
+ if( ret == EOF || file_pos < 0 || fseek( opt->qpfile, file_pos, SEEK_SET ) )
{
- x264_cli_log( "x264", X264_LOG_ERROR, "qpfile seeking failed\n" );
+ if( ret != EOF )
+ x264_cli_log( "x264", X264_LOG_ERROR, "qpfile seeking failed\n" );
fclose( opt->qpfile );
opt->qpfile = NULL;
}
@@ -1821,8 +1829,6 @@ static void parse_qpfile( cli_opt_t *opt, x264_picture_t *pic, int i_frame )
}
if( num < i_frame && ret >= 2 )
continue;
- if( ret == 3 && qp >= 0 )
- pic->i_qpplus1 = qp+1;
if ( type == 'I' ) pic->i_type = X264_TYPE_IDR;
else if( type == 'i' ) pic->i_type = X264_TYPE_I;
else if( type == 'K' ) pic->i_type = X264_TYPE_KEYFRAME;
@@ -1837,6 +1843,8 @@ static void parse_qpfile( cli_opt_t *opt, x264_picture_t *pic, int i_frame )
opt->qpfile = NULL;
break;
}
+ if( ret == 3 && qp >= 0 )
+ pic->i_qpplus1 = qp+1;
}
}
View it on GitLab: https://code.videolan.org/videolan/x264/-/commit/a8b68ebfaa68621b5ac8907610d3335971839d52
--
View it on GitLab: https://code.videolan.org/videolan/x264/-/commit/a8b68ebfaa68621b5ac8907610d3335971839d52
You're receiving this email because of your account on code.videolan.org.
VideoLAN code repository instance
More information about the x264-devel
mailing list