History

avcodec/mpegvideo_enc: use 64bit multiplication in dct_quantize_trellis_c and dct_quantize_c

Fixes corruption with: ffmpeg -t 1 -filter_complex "sine=f=21,showwaves=scale=cbrt:mode=line:colors=white:draw=full" -c:v mpeg2video -non_linear_quant 1 -qmin 1 -qmax 1 -cpuflags 0 out.mpg or ffmpeg -t 1 -filter_complex "sine=f=21,showwaves=scale=cbrt:mode=line:colors=white:draw=full" -c:v mpeg2video -non_linear_quant 1 -qmin 1 -qmax 1 -trellis 1 out.mpg

Marton Balint committed 1 year ago

Commit ec4d3dc1 parent ed268121 file · +11 −11Browse files

Unified · Split

libavcodec/mpegvideo_enc.c+11−11
@@ -3998,9 +3998,9 @@ static int dct_quantize_trellis_c(MpegEncContext *s, · 3997 unmodified lines
39983998
39993999 for(i=63; i>=start_i; i--) {
40004000 const int j = scantable[i];
4001− int level = block[j] * qmat[j];
4001+ int64_t level = (int64_t)block[j] * qmat[j];
40024002
4003− if(((unsigned)(level+threshold1))>threshold2){
4003+ if(((uint64_t)(level+threshold1))>threshold2){
40044004 last_non_zero = i;
40054005 break;
40064006 }
@@ -4008,11 +4008,11 @@ static int dct_quantize_trellis_c(MpegEncContext *s, · 1 unmodified line
40084008
40094009 for(i=start_i; i<=last_non_zero; i++) {
40104010 const int j = scantable[i];
4011− int level = block[j] * qmat[j];
4011+ int64_t level = (int64_t)block[j] * qmat[j];
40124012
40134013 // if( bias+level >= (1<<(QMAT_SHIFT - 3))
40144014 // || bias-level >= (1<<(QMAT_SHIFT - 3))){
4015− if(((unsigned)(level+threshold1))>threshold2){
4015+ if(((uint64_t)(level+threshold1))>threshold2){
40164016 if(level>0){
40174017 level= (bias + level)>>QMAT_SHIFT;
40184018 coeff[0][i]= level;
@@ -4601,7 +4601,7 @@ static int dct_quantize_c(MpegEncContext *s, · 582 unmodified lines
46014601 int16_t *block, int n,
46024602 int qscale, int *overflow)
46034603 {
4604− int i, j, level, last_non_zero, q, start_i;
4604+ int i, last_non_zero, q, start_i;
46054605 const int *qmat;
46064606 const uint8_t *scantable;
46074607 int bias;
@@ -4641,10 +4641,10 @@ static int dct_quantize_c(MpegEncContext *s, · 33 unmodified lines
46414641 threshold1= (1<<QMAT_SHIFT) - bias - 1;
46424642 threshold2= (threshold1<<1);
46434643 for(i=63;i>=start_i;i--) {
4644− j = scantable[i];
4645− level = block[j] * qmat[j];
4644+ const int j = scantable[i];
4645+ int64_t level = (int64_t)block[j] * qmat[j];
46464646
4647− if(((unsigned)(level+threshold1))>threshold2){
4647+ if(((uint64_t)(level+threshold1))>threshold2){
46484648 last_non_zero = i;
46494649 break;
46504650 }else{
@@ -4652,12 +4652,12 @@ static int dct_quantize_c(MpegEncContext *s, · 1 unmodified line
46524652 }
46534653 }
46544654 for(i=start_i; i<=last_non_zero; i++) {
4655− j = scantable[i];
4656− level = block[j] * qmat[j];
4655+ const int j = scantable[i];
4656+ int64_t level = (int64_t)block[j] * qmat[j];
46574657
46584658 // if( bias+level >= (1<<QMAT_SHIFT)
46594659 // || bias-level >= (1<<QMAT_SHIFT)){
4660− if(((unsigned)(level+threshold1))>threshold2){
4660+ if(((uint64_t)(level+threshold1))>threshold2){
46614661 if(level>0){
46624662 level= (bias + level)>>QMAT_SHIFT;
46634663 block[j]= level;

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t