aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarton Balint <cus@passwd.hu>2025-01-06 23:08:32 +0100
committerMarton Balint <cus@passwd.hu>2025-01-25 20:10:41 +0100
commitec4d3dc5b90f0e5b4e931667fd9c9c6944da40fa (patch)
tree02d164f12d25c060d19a46b8d2b90f621130edc5
parented26812337b397e602e68dae5c39b20b8b599565 (diff)
downloadffmpeg-ec4d3dc5b90f0e5b4e931667fd9c9c6944da40fa.tar.gz
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 Signed-off-by: Marton Balint <cus@passwd.hu>
-rw-r--r--libavcodec/mpegvideo_enc.c22
1 files changed, 11 insertions, 11 deletions
diff --git a/libavcodec/mpegvideo_enc.c b/libavcodec/mpegvideo_enc.c
index d5088fe67f..e6e6648e3c 100644
--- a/libavcodec/mpegvideo_enc.c
+++ b/libavcodec/mpegvideo_enc.c
@@ -3998,9 +3998,9 @@ static int dct_quantize_trellis_c(MpegEncContext *s,
for(i=63; i>=start_i; i--) {
const int j = scantable[i];
- int level = block[j] * qmat[j];
+ int64_t level = (int64_t)block[j] * qmat[j];
- if(((unsigned)(level+threshold1))>threshold2){
+ if(((uint64_t)(level+threshold1))>threshold2){
last_non_zero = i;
break;
}
@@ -4008,11 +4008,11 @@ static int dct_quantize_trellis_c(MpegEncContext *s,
for(i=start_i; i<=last_non_zero; i++) {
const int j = scantable[i];
- int level = block[j] * qmat[j];
+ int64_t level = (int64_t)block[j] * qmat[j];
// if( bias+level >= (1<<(QMAT_SHIFT - 3))
// || bias-level >= (1<<(QMAT_SHIFT - 3))){
- if(((unsigned)(level+threshold1))>threshold2){
+ if(((uint64_t)(level+threshold1))>threshold2){
if(level>0){
level= (bias + level)>>QMAT_SHIFT;
coeff[0][i]= level;
@@ -4601,7 +4601,7 @@ static int dct_quantize_c(MpegEncContext *s,
int16_t *block, int n,
int qscale, int *overflow)
{
- int i, j, level, last_non_zero, q, start_i;
+ int i, last_non_zero, q, start_i;
const int *qmat;
const uint8_t *scantable;
int bias;
@@ -4641,10 +4641,10 @@ static int dct_quantize_c(MpegEncContext *s,
threshold1= (1<<QMAT_SHIFT) - bias - 1;
threshold2= (threshold1<<1);
for(i=63;i>=start_i;i--) {
- j = scantable[i];
- level = block[j] * qmat[j];
+ const int j = scantable[i];
+ int64_t level = (int64_t)block[j] * qmat[j];
- if(((unsigned)(level+threshold1))>threshold2){
+ if(((uint64_t)(level+threshold1))>threshold2){
last_non_zero = i;
break;
}else{
@@ -4652,12 +4652,12 @@ static int dct_quantize_c(MpegEncContext *s,
}
}
for(i=start_i; i<=last_non_zero; i++) {
- j = scantable[i];
- level = block[j] * qmat[j];
+ const int j = scantable[i];
+ int64_t level = (int64_t)block[j] * qmat[j];
// if( bias+level >= (1<<QMAT_SHIFT)
// || bias-level >= (1<<QMAT_SHIFT)){
- if(((unsigned)(level+threshold1))>threshold2){
+ if(((uint64_t)(level+threshold1))>threshold2){
if(level>0){
level= (bias + level)>>QMAT_SHIFT;
block[j]= level;