From thiele at streamline-x.org Sat Apr 1 16:43:48 2023 From: thiele at streamline-x.org (H. Thiele) Date: Sat, 1 Apr 2023 18:43:48 +0200 Subject: [x264-devel] [bug-report] An accidental trailing space in qpfile encodes as a broken I-frame Message-ID: Hi, I did not find a suitable way to sign-in to your issue tracker (I only can log-in when I have an account with Google, Twitter, etc.?), so I hope it is acceptable to report my issue here on this mailing list. Issue ----- Having a random trailing space in a qpfile can lead to the respective frame encoded as a blank grey I-frame (no image content), following B/P frames warp then in funnily. It's quite a nice looking glitch. e.g. an qpfile could look like this to force some i-frames on specific scene switches (e.g. dark -> dark to aid with debanding efforts): ... 4507I 4578I 5414I 5619I 5764I 5870I 6113I 12744I 12799I 19428I ... Please note the extra accidental space character after the "I" for frame #6113. After removing the space character and re-encoding the whole file the issue went away. What Should Happen? ------------------- Accidental trailing whitespace in lines of a qpfile should be ignored and not trigger encoding errors. My wild guess is it was trying to parse of the optional QP value, failed on it, and then set it to an internal default. Used x264 Command Line (Example) -------------------------------- vspipe --y4m input.vpy - | x264 --crf 17 --profile high422 --preset veryslow --tune film --demuxer y4m - --output output.264 --no-interlaced --level 4.1 --deblock -2:-2 --force-cfr --range tv --colorprim bt709 --transfer bt709 --colormatrix bt709 --sar 1:1 --vbv-maxrate 5120 --vbv-bufsize 12288 --threads 4 --frames 48012 --qpfile qpfile.txt regards, H. Thiele From BugMaster at narod.ru Sun Apr 2 13:24:54 2023 From: BugMaster at narod.ru (BugMaster) Date: Sun, 2 Apr 2023 16:24:54 +0300 Subject: [x264-devel] [bug-report] An accidental trailing space in qpfile encodes as a broken I-frame In-Reply-To: References: Message-ID: <1433626390.20230402162454@narod.ru> On Sat, 1 Apr 2023 18:43:48 +0200, H. Thiele wrote: > Hi, > I did not find a suitable way to sign-in to your issue tracker (I only > can log-in when I have an account with Google, Twitter, etc.?), so I > hope it is acceptable to report my issue here on this mailing list. Hi. I don't know why they removed the link "Register now", but in theory you can try to replace sign_in with sing_up in the url. > Issue > ----- > Having a random trailing space in a qpfile can lead to the respective > frame encoded as a blank grey I-frame (no image content), following B/P > frames warp then in funnily. It's quite a nice looking glitch. > e.g. an qpfile could look like this to force some i-frames on specific > scene switches (e.g. dark -> dark to aid with debanding efforts): > ... > 4507I > 4578I > 5414I > 5619I > 5764I > 5870I > 6113I > 12744I > 12799I > 19428I > ... > Please note the extra accidental space character after the "I" for frame > #6113. > After removing the space character and re-encoding the whole file the > issue went away. https://code.videolan.org/videolan/x264/-/merge_requests/129 should probably fix your issue. > What Should Happen? > ------------------- > Accidental trailing whitespace in lines of a qpfile should be ignored > and not trigger encoding errors. > My wild guess is it was trying to parse of the optional QP value, failed > on it, and then set it to an internal default. It parsed 6113I12744I as frame=6113 type=I qp=12744 (due such high qp value it decimated to grey frame) And later probably failed with error: x264 [error]: can't parse qpfile for frame 6114 From gitlab at videolan.org Sun Apr 23 17:56:21 2023 From: gitlab at videolan.org (Anton Mitrofanov (@BugMaster)) Date: Sun, 23 Apr 2023 19:56:21 +0200 Subject: [x264-devel] [Git][videolan/x264][master] Improve qpfile parsing resiliency Message-ID: <644571451d663_1708881963f95c160765f@gitlab.mail> 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