Opened 5 years ago

Closed 11 months ago

#7972 closed defect (fixed)

Gif output not preserving source duration for last frame

Reported by: bjorn Owned by:
Priority: normal Component: undetermined
Version: unspecified Keywords: gif
Cc: bjorn@xowave.com, jacob@giphy.com Blocked By:
Blocking: Reproduced by developer: no
Analyzed by developer: no

Description

Summary of the bug:
How to reproduce:

% ffmpeg -i source_lightning.gif out.gif
ffmpeg version
ffmpeg version 4.1.3 Copyright (c) 2000-2019 the FFmpeg developers
built with Apple LLVM version 10.0.1 (clang-1001.0.46.4)
configuration: --prefix=/usr/local/Cellar/ffmpeg/4.1.3_1 --enable-shared --enable-pthreads --enable-version3 --enable-hardcoded-tables --enable-avresample --cc=clang --host-cflags='-I/Library/Java/JavaVirtualMachines/adoptopenjdk-11.0.2.jdk/Contents/Home/include -I/Library/Java/JavaVirtualMachines/adoptopenjdk-11.0.2.jdk/Contents/Home/include/darwin' --host-ldflags= --enable-ffplay --enable-gnutls --enable-gpl --enable-libaom --enable-libbluray --enable-libmp3lame --enable-libopus --enable-librubberband --enable-libsnappy --enable-libtesseract --enable-libtheora --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libx265 --enable-libxvid --enable-lzma --enable-libfontconfig --enable-libfreetype --enable-frei0r --enable-libass --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-librtmp --enable-libspeex --enable-videotoolbox --disable-libjack --disable-indev=jack --enable-libaom --enable-libsoxr
libavutil      56. 22.100 / 56. 22.100
libavcodec     58. 35.100 / 58. 35.100
libavformat    58. 20.100 / 58. 20.100
libavdevice    58.  5.100 / 58.  5.100
libavfilter     7. 40.101 /  7. 40.101
libavresample   4.  0.  0 /  4.  0.  0
libswscale      5.  3.100 /  5.  3.100
libswresample   3.  3.100 /  3.  3.100
libpostproc    55.  3.100 / 55.  3.100

out.gif will have the wrong timing for the last frame. you can see this visually or in a tool such as imagemagick:

$ identify -format "%T\n" source_lightning.gif 
1
1
1
1
1
5
1
1
450
$ identify -format "%T\n" out.gif 
10
10
10
10
10
5
10
10
10

Attachments (1)

source_lightning.gif (16.6 KB ) - added by bjorn 5 years ago.

Download all attachments as: .zip

Change History (6)

by bjorn, 5 years ago

Attachment: source_lightning.gif added

comment:1 by bjorn, 5 years ago

Cc: bjorn@xowave.com added

comment:2 by Jacob Graff, 5 years ago

One fix for this in fftools/ffmpeg.c is to copy the duration from the frame to the packet during do_video_out calls, eg:

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);

And then use the packet duration, rather than the pts, during the gif encode step. However, this fix is probably not general enough, since other which attempts to write out gif packets could still face this issue. Ideally, packet duration should always be copied (and not zeroed out) during filtering, however it appears that at some point between reading packets in and writing them out, the duration gets dropped.

comment:3 by Jacob Graff, 5 years ago

Cc: jacob@giphy.com added

comment:4 by Elon Musk, 3 years ago

Keywords: gif added
Status: newopen

comment:5 by Elon Musk, 11 months ago

Resolution: fixed
Status: openclosed
Note: See TracTickets for help on using tickets.