Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gif transparency fix #3

Open
wants to merge 26 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
ada564c
fix for transparencies in animated gifs
bejayoharen Jan 16, 2018
88a7c75
bugfixes for edge and 2nd frame artifacts
bejayoharen Feb 5, 2018
77cd1d0
fixes for corrupt gifs
bejayoharen Mar 16, 2018
e8f1d7d
Merge remote-tracking branch 'upstream/master'
cyburgee Mar 19, 2018
9e5c00c
Merge remote-tracking branch 'upstream/master'
cyburgee Apr 4, 2018
6e06057
actually fix conflict
cyburgee Apr 4, 2018
e6bd543
Merge remote-tracking branch 'upstream/master'
cyburgee Apr 18, 2018
2e5e052
Merge remote-tracking branch 'upstream/master'
cyburgee May 22, 2018
8f5485b
Merge remote-tracking branch 'upstream/master'
cyburgee Oct 18, 2018
5eaaf8e
CR-1266: Fix infinite loop bug on transparent optimization
jagraff Nov 26, 2018
a35311a
Merge pull request #1 from Giphy/CR-1266
jagraff Nov 29, 2018
6e3b807
Merge remote-tracking branch 'upstream/master'
cyburgee Mar 14, 2019
5cfb22c
fix conflict res issue
cyburgee Mar 14, 2019
2fc69e5
Merge pull request #2 from Giphy/upstream-merge-03-14-19-v2
cyburgee Mar 14, 2019
c6180f3
fix transparent crop
cyburgee Apr 19, 2019
d69c4cf
Update gif.c
cyburgee Apr 19, 2019
8376342
Fix bug with transparent gif cropping
jagraff May 6, 2019
561517b
Optimize
jagraff May 6, 2019
d199ea7
Remove extra logging
jagraff May 6, 2019
9f697ed
Fix disposal method issue
jagraff May 10, 2019
9ecadad
Fix for duration bug
jagraff Jun 11, 2019
1647406
Don't need to specify prop
jagraff Jun 11, 2019
f837eeb
Change get delay function
jagraff Jun 11, 2019
b3f31a3
Change get delay function
jagraff Jun 11, 2019
4f1587a
Spacing
jagraff Jun 11, 2019
f2b8cce
Remove incorrect AV_NOPTS_VALUE check
jagraff Jun 19, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion fftools/ffmpeg.c
Original file line number Diff line number Diff line change
Expand Up @@ -847,7 +847,6 @@ static void output_packet(OutputFile *of, AVPacket *pkt,
OutputStream *ost, int eof)
{
int ret = 0;

/* apply the output bitstream filters, if any */
if (ost->nb_bitstream_filters) {
int idx;
Expand Down Expand Up @@ -1291,6 +1290,8 @@ static void do_video_out(OutputFile *of,

while (1) {
ret = avcodec_receive_packet(enc, &pkt);
if (pkt.duration <= 0)
pkt.duration = av_rescale_q(in_picture->pkt_duration, ost->mux_timebase, enc->time_base);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[from IRL discussion] jagraff explained to me that this is probably not the 'right' way to copy the duration between frames (since it's probably better to figure out why the duration isn't copied over and fix that). So this is unlikely to be merged into mainline - but I think it's fine to use this for GIPHY's purposes.

update_benchmark("encode_video %d.%d", ost->file_index, ost->index);
if (ret == AVERROR(EAGAIN))
break;
Expand Down
6 changes: 6 additions & 0 deletions libavcodec/avcodec.h
Original file line number Diff line number Diff line change
Expand Up @@ -1376,6 +1376,12 @@ enum AVPacketSideDataType {
*/
AV_PKT_DATA_A53_CC,

/**
* The disposal method that should be used with the frame. If missing,
* the frame will not be disposed. This contains exactly one byte.
*/
AV_PKT_DATA_GIF_FRAME_DISPOSAL,

/**
* This side data is encryption initialization data.
* The format is not part of ABI, use av_encryption_init_info_* methods to
Expand Down
17 changes: 9 additions & 8 deletions libavcodec/gif.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(ignoring this file as it's already mostly been accepted in mainline)

is_trans = 0;
break;
}
Expand All @@ -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;
}
Expand All @@ -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;
}
Expand All @@ -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;
}
Expand All @@ -191,6 +191,7 @@ static void gif_crop_translucent(AVCodecContext *avctx,

*height = y_end + 1 - *y_start;
*width = x_end + 1 - *x_start;

av_log(avctx, AV_LOG_DEBUG,"%dx%d image at pos (%d;%d) [area:%dx%d]\n",
*width, *height, *x_start, *y_start, avctx->width, avctx->height);
}
Expand Down Expand Up @@ -267,7 +268,7 @@ static int gif_image_write_image(AVCodecContext *avctx,
int bcid = -1, honor_transparency = (s->flags & GF_TRANSDIFF) && s->last_frame && !palette;
const uint8_t *ptr;

if (!s->image && avctx->frame_number && is_image_translucent(avctx, buf, linesize)) {
if (!s->image && is_image_translucent(avctx, buf, linesize)) {
gif_crop_translucent(avctx, buf, linesize, &width, &height, &x_start, &y_start);
honor_transparency = 0;
disposal = GCE_DISPOSAL_BACKGROUND;
Expand Down Expand Up @@ -497,4 +498,4 @@ AVCodec ff_gif_encoder = {
AV_PIX_FMT_GRAY8, AV_PIX_FMT_PAL8, AV_PIX_FMT_NONE
},
.priv_class = &gif_class,
};
};
4 changes: 4 additions & 0 deletions libavdevice/indev_list.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
static const AVInputFormat * const indev_list[] = {
&ff_avfoundation_demuxer,
&ff_lavfi_demuxer,
NULL };
2 changes: 2 additions & 0 deletions libavdevice/outdev_list.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
static const AVOutputFormat * const outdev_list[] = {
NULL };
2 changes: 2 additions & 0 deletions libavformat/gif.c
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ static int gif_get_delay(GIFContext *gif, AVPacket *prev, AVPacket *new)
gif->duration = av_clip_uint16(new->pts - prev->pts);
else if (!new && gif->last_delay >= 0)
gif->duration = gif->last_delay;
else
gif->duration = prev->duration;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

makes sense


return gif->duration;
}
Expand Down