Opened 9 years ago

Closed 9 years ago

Last modified 9 years ago

#4369 closed defect (worksforme)

FFmpeg uses 100% cpu while processing an invalid gif

Reported by: Martin Samson Owned by:
Priority: normal Component: avformat
Version: git-master Keywords: gif
Cc: Cigaes Blocked By:
Blocking: Reproduced by developer: yes
Analyzed by developer: no

Description

Summary of the bug:
We received a weird gif that keeps ffmpeg transcoding at 100% cpu forever.

The gif data ( from identify gif_timing0_loop_bomb.gif returns the following data:

tmpMh68Z4.gif[0] GIF 600x436 600x436+0+0 8-bit sRGB 256c 859KB 0.000u 0:00.000
tmpMh68Z4.gif[1] GIF 53x42 600x436+547+177 8-bit sRGB 256c 859KB 0.000u 0:00.000
tmpMh68Z4.gif[2] GIF 212x42 600x436+388+177 8-bit sRGB 256c 859KB 0.000u 0:00.000
tmpMh68Z4.gif[3] GIF 307x45 600x436+247+178 8-bit sRGB 256c 859KB 0.000u 0:00.000
tmpMh68Z4.gif[4] GIF 254x42 600x436+159+182 8-bit sRGB 256c 859KB 0.000u 0:00.000
tmpMh68Z4.gif[5] GIF 27x36 600x436+154+190 8-bit sRGB 256c 859KB 0.000u 0:00.000
tmpMh68Z4.gif[6] GIF 62x85 600x436+538+111 8-bit sRGB 256c 859KB 0.000u 0:00.000
tmpMh68Z4.gif[7] GIF 128x125 600x436+472+111 8-bit sRGB 256c 859KB 0.000u 0:00.000
tmpMh68Z4.gif[8] GIF 163x138 600x436+437+115 8-bit sRGB 256c 859KB 0.000u 0:00.000
tmpMh68Z4.gif[9] GIF 138x155 600x436+420+104 8-bit sRGB 256c 859KB 0.000u 0:00.000
tmpMh68Z4.gif[10] GIF 160x155 600x436+343+104 8-bit sRGB 256c 859KB 0.000u 0:00.000
tmpMh68Z4.gif[11] GIF 169x120 600x436+312+116 8-bit sRGB 256c 859KB 0.000u 0:00.000
tmpMh68Z4.gif[12] GIF 175x138 600x436+293+105 8-bit sRGB 256c 859KB 0.000u 0:00.000
tmpMh68Z4.gif[13] GIF 156x156 600x436+259+98 8-bit sRGB 256c 859KB 0.000u 0:00.000
tmpMh68Z4.gif[14] GIF 151x156 600x436+190+98 8-bit sRGB 256c 859KB 0.000u 0:00.000
tmpMh68Z4.gif[15] GIF 168x121 600x436+160+119 8-bit sRGB 256c 859KB 0.000u 0:00.000
tmpMh68Z4.gif[16] GIF 159x159 600x436+160+97 8-bit sRGB 256c 859KB 0.000u 0:00.000
tmpMh68Z4.gif[17] GIF 139x159 600x436+138+97 8-bit sRGB 256c 859KB 0.000u 0:00.000
tmpMh68Z4.gif[18] GIF 157x130 600x436+138+111 8-bit sRGB 256c 859KB 0.000u 0:00.000
tmpMh68Z4.gif[19] GIF 260x247 600x436+65+94 8-bit sRGB 256c 859KB 0.000u 0:00.000
tmpMh68Z4.gif[20] GIF 259x247 600x436+65+94 8-bit sRGB 256c 859KB 0.000u 0:00.000
tmpMh68Z4.gif[21] GIF 256x245 600x436+65+96 8-bit sRGB 256c 859KB 0.000u 0:00.000
tmpMh68Z4.gif[22] GIF 254x243 600x436+65+98 8-bit sRGB 256c 859KB 0.000u 0:00.000
tmpMh68Z4.gif[23] GIF 251x240 600x436+65+101 8-bit sRGB 256c 859KB 0.000u 0:00.000
tmpMh68Z4.gif[24] GIF 249x238 600x436+65+103 8-bit sRGB 256c 859KB 0.000u 0:00.000
tmpMh68Z4.gif[25] GIF 246x236 600x436+65+105 8-bit sRGB 256c 859KB 0.000u 0:00.000
tmpMh68Z4.gif[26] GIF 244x234 600x436+65+107 8-bit sRGB 256c 859KB 0.000u 0:00.000
tmpMh68Z4.gif[27] GIF 242x232 600x436+65+109 8-bit sRGB 256c 859KB 0.000u 0:00.000
tmpMh68Z4.gif[28] GIF 239x230 600x436+65+111 8-bit sRGB 256c 859KB 0.000u 0:00.000
tmpMh68Z4.gif[29] GIF 237x227 600x436+65+113 8-bit sRGB 256c 859KB 0.000u 0:00.000
tmpMh68Z4.gif[30] GIF 234x225 600x436+65+115 8-bit sRGB 256c 859KB 0.000u 0:00.000
tmpMh68Z4.gif[31] GIF 232x223 600x436+65+117 8-bit sRGB 256c 859KB 0.000u 0:00.000
tmpMh68Z4.gif[32] GIF 231x221 600x436+64+119 8-bit sRGB 256c 859KB 0.000u 0:00.000
tmpMh68Z4.gif[33] GIF 228x219 600x436+64+121 8-bit sRGB 256c 859KB 0.000u 0:00.000
tmpMh68Z4.gif[34] GIF 226x216 600x436+64+124 8-bit sRGB 256c 859KB 0.000u 0:00.000
tmpMh68Z4.gif[35] GIF 223x214 600x436+64+126 8-bit sRGB 256c 859KB 0.000u 0:00.000
tmpMh68Z4.gif[36] GIF 221x212 600x436+64+128 8-bit sRGB 256c 859KB 0.000u 0:00.000
tmpMh68Z4.gif[37] GIF 218x210 600x436+64+130 8-bit sRGB 256c 859KB 0.000u 0:00.000
tmpMh68Z4.gif[38] GIF 216x208 600x436+64+132 8-bit sRGB 256c 859KB 0.000u 0:00.000
tmpMh68Z4.gif[39] GIF 214x206 600x436+64+134 8-bit sRGB 256c 859KB 0.000u 0:00.000
tmpMh68Z4.gif[40] GIF 211x204 600x436+64+136 8-bit sRGB 256c 859KB 0.000u 0:00.000
tmpMh68Z4.gif[41] GIF 209x202 600x436+64+138 8-bit sRGB 256c 859KB 0.000u 0:00.000
tmpMh68Z4.gif[42] GIF 206x200 600x436+64+140 8-bit sRGB 256c 859KB 0.000u 0:00.000
tmpMh68Z4.gif[43] GIF 204x198 600x436+64+142 8-bit sRGB 256c 859KB 0.000u 0:00.000
tmpMh68Z4.gif[44] GIF 202x195 600x436+64+145 8-bit sRGB 256c 859KB 0.000u 0:00.000
tmpMh68Z4.gif[45] GIF 199x193 600x436+64+147 8-bit sRGB 256c 859KB 0.000u 0:00.000
tmpMh68Z4.gif[46] GIF 197x191 600x436+64+149 8-bit sRGB 256c 859KB 0.000u 0:00.000
tmpMh68Z4.gif[47] GIF 194x189 600x436+64+151 8-bit sRGB 256c 859KB 0.000u 0:00.000
tmpMh68Z4.gif[48] GIF 192x187 600x436+64+153 8-bit sRGB 256c 859KB 0.000u 0:00.000
tmpMh68Z4.gif[49] GIF 190x185 600x436+64+155 8-bit sRGB 256c 859KB 0.000u 0:00.000
tmpMh68Z4.gif[50] GIF 187x183 600x436+64+157 8-bit sRGB 256c 859KB 0.000u 0:00.000
tmpMh68Z4.gif[51] GIF 185x181 600x436+64+159 8-bit sRGB 256c 859KB 0.000u 0:00.000
tmpMh68Z4.gif[52] GIF 182x179 600x436+64+161 8-bit sRGB 256c 859KB 0.000u 0:00.000
tmpMh68Z4.gif[53] GIF 180x177 600x436+64+163 8-bit sRGB 256c 859KB 0.000u 0:00.000
tmpMh68Z4.gif[54] GIF 177x175 600x436+64+165 8-bit sRGB 256c 859KB 0.000u 0:00.000
tmpMh68Z4.gif[55] GIF 175x173 600x436+64+167 8-bit sRGB 256c 859KB 0.000u 0:00.000
tmpMh68Z4.gif[56] GIF 173x170 600x436+64+170 8-bit sRGB 256c 859KB 0.000u 0:00.000
tmpMh68Z4.gif[57] GIF 171x168 600x436+63+172 8-bit sRGB 256c 859KB 0.000u 0:00.000
tmpMh68Z4.gif[58] GIF 168x166 600x436+64+174 8-bit sRGB 256c 859KB 0.000u 0:00.000
tmpMh68Z4.gif[59] GIF 166x164 600x436+63+176 8-bit sRGB 256c 859KB 0.000u 0:00.000
tmpMh68Z4.gif[60] GIF 164x162 600x436+63+178 8-bit sRGB 256c 859KB 0.000u 0:00.000
tmpMh68Z4.gif[61] GIF 162x160 600x436+63+180 8-bit sRGB 256c 859KB 0.000u 0:00.000
tmpMh68Z4.gif[62] GIF 159x158 600x436+63+182 8-bit sRGB 256c 859KB 0.000u 0:00.000
tmpMh68Z4.gif[63] GIF 157x156 600x436+63+184 8-bit sRGB 256c 859KB 0.000u 0:00.000
tmpMh68Z4.gif[64] GIF 154x154 600x436+63+186 8-bit sRGB 256c 859KB 0.000u 0:00.000
tmpMh68Z4.gif[65] GIF 152x152 600x436+63+188 8-bit sRGB 256c 859KB 0.000u 0:00.000
tmpMh68Z4.gif[66] GIF 149x150 600x436+63+190 8-bit sRGB 256c 859KB 0.000u 0:00.000
tmpMh68Z4.gif[67] GIF 147x147 600x436+63+193 8-bit sRGB 256c 859KB 0.000u 0:00.000
tmpMh68Z4.gif[68] GIF 144x145 600x436+63+195 8-bit sRGB 256c 859KB 0.000u 0:00.000
tmpMh68Z4.gif[69] GIF 142x143 600x436+63+197 8-bit sRGB 256c 859KB 0.000u 0:00.000
tmpMh68Z4.gif[70] GIF 140x141 600x436+63+199 8-bit sRGB 256c 859KB 0.000u 0:00.000
tmpMh68Z4.gif[71] GIF 137x139 600x436+63+201 8-bit sRGB 256c 859KB 0.000u 0:00.000
tmpMh68Z4.gif[72] GIF 135x137 600x436+63+203 8-bit sRGB 256c 859KB 0.000u 0:00.000
tmpMh68Z4.gif[73] GIF 132x135 600x436+63+205 8-bit sRGB 256c 859KB 0.000u 0:00.000
tmpMh68Z4.gif[74] GIF 130x133 600x436+63+207 8-bit sRGB 256c 859KB 0.000u 0:00.000
tmpMh68Z4.gif[75] GIF 127x131 600x436+63+209 8-bit sRGB 256c 859KB 0.000u 0:00.000
tmpMh68Z4.gif[76] GIF 125x129 600x436+63+211 8-bit sRGB 256c 859KB 0.000u 0:00.000
tmpMh68Z4.gif[77] GIF 123x126 600x436+63+214 8-bit sRGB 256c 859KB 0.000u 0:00.000
tmpMh68Z4.gif[78] GIF 120x124 600x436+63+216 8-bit sRGB 256c 859KB 0.000u 0:00.000
tmpMh68Z4.gif[79] GIF 118x122 600x436+63+218 8-bit sRGB 256c 859KB 0.000u 0:00.000
tmpMh68Z4.gif[80] GIF 115x120 600x436+63+220 8-bit sRGB 256c 859KB 0.000u 0:00.000
tmpMh68Z4.gif[81] GIF 113x118 600x436+63+222 8-bit sRGB 256c 859KB 0.000u 0:00.000
tmpMh68Z4.gif[82] GIF 248x340 600x436+63+0 8-bit sRGB 256c 859KB 0.000u 0:00.000
tmpMh68Z4.gif[83] GIF 283x340 600x436+62+0 8-bit sRGB 256c 859KB 0.000u 0:00.000
tmpMh68Z4.gif[84] GIF 283x340 600x436+62+0 8-bit sRGB 256c 859KB 0.000u 0:00.000
tmpMh68Z4.gif[85] GIF 284x344 600x436+64+0 8-bit sRGB 256c 859KB 0.000u 0:00.000
tmpMh68Z4.gif[86] GIF 172x184 600x436+49+173 8-bit sRGB 256c 859KB 0.000u 0:00.000
tmpMh68Z4.gif[87] GIF 214x199 600x436+18+171 8-bit sRGB 256c 859KB 0.000u 0:00.000
tmpMh68Z4.gif[88] GIF 220x165 600x436+18+204 8-bit sRGB 256c 859KB 0.000u 0:00.000
tmpMh68Z4.gif[89] GIF 234x97 600x436+20+201 8-bit sRGB 256c 859KB 0.000u 0:00.000
tmpMh68Z4.gif[90] GIF 263x167 600x436+17+195 8-bit sRGB 256c 859KB 0.000u 0:00.000
tmpMh68Z4.gif[91] GIF 272x170 600x436+17+195 8-bit sRGB 256c 859KB 0.000u 0:00.000
tmpMh68Z4.gif[92] GIF 211x57 600x436+43+318 8-bit sRGB 256c 859KB 0.000u 0:00.000
tmpMh68Z4.gif[93] GIF 573x436 600x436+27+0 8-bit sRGB 256c 859KB 0.000u 0:00.000
tmpMh68Z4.gif[94] GIF 467x365 600x436+133+0 8-bit sRGB 256c 859KB 0.000u 0:00.000
tmpMh68Z4.gif[95] GIF 266x182 600x436+150+80 8-bit sRGB 256c 859KB 0.000u 0:00.000
tmpMh68Z4.gif[96] GIF 445x365 600x436+155+0 8-bit sRGB 256c 859KB 0.000u 0:00.000
tmpMh68Z4.gif[97] GIF 415x365 600x436+185+0 8-bit sRGB 256c 859KB 0.000u 0:00.000
tmpMh68Z4.gif[98] GIF 172x365 600x436+428+0 8-bit sRGB 256c 859KB 0.000u 0:00.000
tmpMh68Z4.gif[99] GIF 172x365 600x436+428+0 8-bit sRGB 256c 859KB 0.000u 0:00.000
tmpMh68Z4.gif[100] GIF 171x365 600x436+429+0 8-bit sRGB 256c 859KB 0.000u 0:00.000
tmpMh68Z4.gif[101] GIF 170x365 600x436+430+0 8-bit sRGB 256c 859KB 0.000u 0:00.000

How to reproduce:

% ffmpeg -y -f gif -i gif_timing0_loop_bomb.gif test.mp4
ffmpeg version 2.5.4 Copyright (c) 2000-2015 the FFmpeg developers
  built on Feb 15 2015 20:17:10 with Apple LLVM version 6.0 (clang-600.0.56) (based on LLVM 3.5svn)
  configuration: --prefix=/usr/local/Cellar/ffmpeg/2.5.4 --enable-shared --enable-pthreads --enable-gpl --enable-version3 --enable-hardcoded-tables --enable-avresample --cc=clang --host-cflags= --host-ldflags= --enable-libx264 --enable-libmp3lame --enable-libvo-aacenc --enable-libxvid --enable-vda
  libavutil      54. 15.100 / 54. 15.100
  libavcodec     56. 13.100 / 56. 13.100
  libavformat    56. 15.102 / 56. 15.102
  libavdevice    56.  3.100 / 56.  3.100
  libavfilter     5.  2.103 /  5.  2.103
  libavresample   2.  1.  0 /  2.  1.  0
  libswscale      3.  1.101 /  3.  1.101
  libswresample   1.  1.100 /  1.  1.100
  libpostproc    53.  3.100 / 53.  3.100
Input #0, gif, from 'tmpMh68Z4.gif':
  Duration: N/A, bitrate: N/A
    Stream #0:0: Video: gif, bgra, 600x436, 0k fps, 6.67 tbr, 100 tbn, 100 tbc
No pixel format specified, yuv444p for H.264 encoding chosen.
Use -pix_fmt yuv420p for compatibility with outdated media players.
[libx264 @ 0x7fe5ca800c00] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX
[libx264 @ 0x7fe5ca800c00] profile High 4:4:4 Predictive, level 2.2, 4:4:4 8-bit
[libx264 @ 0x7fe5ca800c00] 264 - core 142 r2495 6a301b6 - H.264/MPEG-4 AVC codec - Copyleft 2003-2014 - http://www.videolan.org/x264.html - options: cabac=1 ref=3 deblock=1:0:0 analyse=0x3:0x113 me=hex subme=7 psy=1 psy_rd=1.00:0.00 mixed_ref=1 me_range=16 chroma_me=1 trellis=1 8x8dct=1 cqm=0 deadzone=21,11 fast_pskip=1 chroma_qp_offset=4 threads=12 lookahead_threads=2 sliced_threads=0 nr=0 decimate=1 interlaced=0 bluray_compat=0 constrained_intra=0 bframes=3 b_pyramid=2 b_adapt=1 b_bias=0 direct=1 weightb=1 open_gop=0 weightp=2 keyint=250 keyint_min=6 scenecut=40 intra_refresh=0 rc_lookahead=40 rc=crf mbtree=1 crf=23.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 ip_ratio=1.40 aq=1:1.00
Output #0, mp4, to 'test.mp4':
  Metadata:
    encoder         : Lavf56.15.102
    Stream #0:0: Video: h264 (libx264) ([33][0][0][0] / 0x0021), yuv444p, 600x436, q=-1--1, 6.67 fps, 10240 tbn, 6.67 tbc
    Metadata:
      encoder         : Lavc56.13.100 libx264
Stream mapping:
  Stream #0:0 -> #0:0 (gif (native) -> h264 (libx264))
Press [q] to stop, [?] for help
frame= 8738 fps=1810 q=24.0 size=     668kB time=00:21:42.00 bitrate=   4.2kbits/s dup=8736 drop=0
    Last message repeated 1289 times
frame=52428 fps=820 q=-1.0 Lsize=    4450kB time=02:10:55.50 bitrate=   4.6kbits/s dup=52416 drop=0
video:4570kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: unknown
[libx264 @ 0x7fe5ca800c00] frame I:210   Avg QP: 3.46  size: 16470
[libx264 @ 0x7fe5ca800c00] frame P:13216 Avg QP: 4.30  size:    33
[libx264 @ 0x7fe5ca800c00] frame B:39002 Avg QP: 8.67  size:    20
[libx264 @ 0x7fe5ca800c00] consecutive B-frames:  0.8%  0.0%  0.0% 99.2%
[libx264 @ 0x7fe5ca800c00] mb I  I16..4: 84.0%  0.8% 15.2%
[libx264 @ 0x7fe5ca800c00] mb P  I16..4:  0.0%  0.0%  0.0%  P16..4:  0.0%  0.0%  0.0%  0.0%  0.0%    skip:100.0%
[libx264 @ 0x7fe5ca800c00] mb B  I16..4:  0.0%  0.0%  0.0%  B16..8:  0.0%  0.0%  0.0%  direct: 0.0%  skip:100.0%  L0:23.5% L1:76.5% BI: 0.0%
[libx264 @ 0x7fe5ca800c00] 8x8 transform intra:0.9% inter:0.4%
[libx264 @ 0x7fe5ca800c00] coded y,u,v intra: 12.3% 6.3% 7.6% inter: 0.0% 0.0% 0.0%
[libx264 @ 0x7fe5ca800c00] i16 v,h,dc,p: 95%  1%  4%  0%
[libx264 @ 0x7fe5ca800c00] i8 v,h,dc,ddl,ddr,vr,hd,vl,hu: 59% 15% 25%  0%  0%  0%  0%  0%  0%
[libx264 @ 0x7fe5ca800c00] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 18% 20% 14%  4%  8% 24%  4%  4%  3%
[libx264 @ 0x7fe5ca800c00] Weighted P-Frames: Y:0.0% UV:0.0%
[libx264 @ 0x7fe5ca800c00] ref P L0: 90.9%  0.2%  6.0%  2.9%
[libx264 @ 0x7fe5ca800c00] ref B L0: 52.6% 47.4%
[libx264 @ 0x7fe5ca800c00] ref B L1: 100.0%  0.0%
[libx264 @ 0x7fe5ca800c00] kb/s:4.76
Received signal 2: terminating.

Attachments (1)

gif_timing0_loop_bomb.gif (838.5 KB ) - added by Martin Samson 9 years ago.

Download all attachments as: .zip

Change History (11)

by Martin Samson, 9 years ago

Attachment: gif_timing0_loop_bomb.gif added

comment:1 by Clément Bœsch, 9 years ago

Component: undeterminedavformat
Keywords: mp4 added
Priority: normalimportant
Reproduced by developer: set
Status: newopen
Version: 2.5.4git-master

Reproducible with git/master. Only reproduced with mp4 output format (avi OK for instance). Same issue with different codecs (ex: mpeg4).

comment:2 by Cigaes, 9 years ago

The file announces 6.67 frames per second, but ffprobe shows each frame separated by 655.35 seconds. Either this file was badly encoded or theree is a bug in the Gif demuxer.

The long encoding comes from the fact that the MP4 muxer does not support variables FPS, and therefore needs to duplicate each frame 4371 times.

in reply to:  2 comment:3 by Carl Eugen Hoyos, 9 years ago

Cc: Cigaes added
Keywords: mp4 removed
Priority: importantnormal

Replying to Cigaes:

The file announces 6.67 frames per second

Why do you think the file announces 6.67 frames per second?
I don't think gif files contain a fps value, do they?

comment:4 by Cigaes, 9 years ago

The banner announces it:

Video: gif, bgra, 600x436, 0k fps, 6.67 tbr, 100 tbn, 100 tbc

And the encoder chooses it:

Video: h264 (libx264) ([33][0][0][0] / 0x0021), yuv444p, 600x436, q=-1--1, 6.67 fps, 10240 tbn, 6.67 tbc

comment:5 by Carl Eugen Hoyos, 9 years ago

Doesn't the banner announce "0" frames per second for the provided sample?
This is not wrong imo, the actual value is one frame per 11 minutes. (The "k" looks misleading though.)

comment:6 by Martin Samson, 9 years ago

From a end-user perspective, is there a way to tell ffmpeg to normalize the framerate if it exceeds a certain threshold?

ex: -max-fps=5

In our current usage scenario having ffmpeg encode 1 frame per 11 minutes creates a denial of service.

comment:7 by Michael Niedermayer, 9 years ago

You can limit the number of output frames with -vframes X
you can limit the output time with -t X

comment:8 by Carl Eugen Hoyos, 9 years ago

Resolution: worksforme
Status: openclosed

The sample you uploaded plays for eighteen hours, encoding with FFmpeg takes 150 seconds here (which is not forever) with -vsync cfr which is the default for mov. You can ues -vsync vfr, the output file may not completely conform to the relevant specification.

I added an option -max_gif_delay that allows you to play the sample in real-time.

comment:9 by Martin Samson, 9 years ago

Thank you cehoyos and the others who have helped on this issue.

We modified our service to set a max_gif_delay and a maximum output time.

in reply to:  5 comment:10 by Carl Eugen Hoyos, 9 years ago

Replying to cehoyos:

Doesn't the banner announce "0" frames per second for the provided sample?
This is not wrong imo, the actual value is one frame per 11 minutes.

(The "k" looks misleading though.)

This should be fixed in
c4367f950d5bc8a3a2979182d5aef7bd94949f93

Note: See TracTickets for help on using tickets.