Opened 5 years ago

Closed 5 years ago

Last modified 5 years ago

#7890 closed defect (fixed)

garbled output with transparent GIF

Reported by: bjorn Owned by:
Priority: important Component: avcodec
Version: git-master Keywords: gif alpha regression
Cc: bjorn@xowave.com Blocked By:
Blocking: Reproduced by developer: no
Analyzed by developer: no

Description

Summary of the bug:
How to reproduce:

$ ./ffmpeg -i source_sticker.gif -filter_complex '[0:v]scale=100:-1,split[a][b];[a]palettegen[p];[b][p]paletteuse' out.gif
On OS X produces various problems:
- in FFMPeg 4.1.3 it enters an infinite loop.
- in FFMPEG master, it produces garbled output.

Here's the patch:

diff --git a/libavcodec/gif.c b/libavcodec/gif.c
index 94c8b1af49..d7768b4426 100644
--- a/libavcodec/gif.c
+++ b/libavcodec/gif.c
@@ -136,7 +136,7 @@ static void gif_crop_translucent(AVCodecContext *avctx,
         while (*y_start < y_end) {
             int is_trans = 1;
             for (int i = 0; i < w; i++) {
-                if (buf[w * *y_start + i] != trans) {
+                if (buf[linesize * *y_start + i] != trans) {
                     is_trans = 0;
                     break;
                 }
@@ -148,10 +148,10 @@ static void gif_crop_translucent(AVCodecContext *avctx,
         }
 
         // crop bottom
-        while (y_end < h) {
+        while (y_end > *y_start) {
             int is_trans = 1;
             for (int i = 0; i < w; i++) {
-                if (buf[w * y_end + i] != trans) {
+                if (buf[linesize * y_end + i] != trans) {
                     is_trans = 0;
                     break;
                 }
@@ -165,7 +165,7 @@ static void gif_crop_translucent(AVCodecContext *avctx,
         while (*x_start < x_end) {
             int is_trans = 1;
             for (int i = *y_start; i < y_end; i++) {
-                if (buf[w * i + *x_start] != trans) {
+                if (buf[linesize * i + *x_start] != trans) {
                     is_trans = 0;
                     break;
                 }
@@ -176,10 +176,10 @@ static void gif_crop_translucent(AVCodecContext *avctx,
         }
 
         // crop right
-        while (x_end < w) {
+        while (x_end > *x_start) {
             int is_trans = 1;
             for (int i = *y_start; i < y_end; i++) {
-                if (buf[w * i + x_end] != trans) {
+                if (buf[linesize * i + x_end] != trans) {
                     is_trans = 0;
                     break;
                 }

Attachments (1)

source_sticker.gif (16.6 KB ) - added by bjorn 5 years ago.
source file to reproduce issues

Download all attachments as: .zip

Change History (9)

by bjorn, 5 years ago

Attachment: source_sticker.gif added

source file to reproduce issues

comment:1 by Elon Musk, 5 years ago

How can I use this patch?
Better send it to devel list so you could get properly attributed?

comment:2 by bjorn, 5 years ago

Cc: bjorn@xowave.com added

Patch can be applied as

$ patch -p1 < diff #where diff is the patch file

Attribution can go to Collin Burger and Jacob Graff.

comment:3 by Elon Musk, 5 years ago

The author of commit can be only one.

comment:4 by Elon Musk, 5 years ago

also best make patch with git format-patch

comment:5 by bjorn, 5 years ago

Okay, submitted to mailing list.

comment:6 by bjorn, 5 years ago

Okay, submitted to mailing list.

comment:7 by Elon Musk, 5 years ago

Resolution: fixed
Status: newclosed

comment:8 by Carl Eugen Hoyos, 5 years ago

Keywords: alpha regression added; transparent removed
Priority: normalimportant
Version: unspecifiedgit-master
Note: See TracTickets for help on using tickets.