[FFmpeg-user] Producing mp4 from gifs for web browser

paweg paweg at op.pl
Wed Oct 17 17:23:14 EEST 2018


I'm making mp4 from gif pictures. I want it to play in web browser in html or some javascript player. When I try to run produced mp4 on VLC player, it shows only first frame, but video time runs. Ubuntu's default Videos player plays almost whole, but freezes at the end and doesn't show few last frames. 
In browser, html5 video also shows only the first frame. Video.js player plays almost whole video, but lost second to last frame.

Command I use:

ffmpeg -y -f lavfi -i anullsrc -f image2 -r 2 -c:v gif -i 'input.gif' \
    -shortest -c:a aac -c:v libx264 -pix_fmt yuv420p -vf "scale=trunc(iw/2)*2:trunc(ih/2)*2" output.mp4

console output:

ffmpeg version 4.0.2 Copyright (c) 2000-2018 the FFmpeg developers
  built with gcc 4.5.1 (GCC) 20100924 (Red Hat 4.5.1-4)
  configuration: --prefix=/home/user/ffmpeg_build --pkg-config-flags=--static --extra-cflags=-I/home/user/ffmpeg_build/include --extra-ldflags=-L/home/user/ffmpeg_build/lib --extra-libs=-lpthread --extra-libs=-lm --bindir=/home/user/bin --enable-libfreetype --enable-libmp3lame --enable-libopus --enable-libvorbis --enable-libx264 --enable-nonfree --enable-gpl
  libavutil      56. 14.100 / 56. 14.100
  libavcodec     58. 18.100 / 58. 18.100
  libavformat    58. 12.100 / 58. 12.100
  libavdevice    58.  3.100 / 58.  3.100
  libavfilter     7. 16.100 /  7. 16.100
  libswscale      5.  1.100 /  5.  1.100
  libswresample   3.  1.100 /  3.  1.100
  libpostproc    55.  1.100 / 55.  1.100
[Parsed_anullsrc_0 @ 0x4320e00] sample_rate:44100 channel_layout:'stereo' nb_samples:1024
Input #0, lavfi, from 'anullsrc':
  Duration: N/A, start: 0.000000, bitrate: 705 kb/s
    Stream #0:0: Audio: pcm_u8, 44100 Hz, stereo, u8, 705 kb/s
[image2 @ 0x43243c0] max_analyze_duration 5000000 reached at 5000000 microseconds st:0
Input #1, image2, from 'input.gif':
  Duration: 00:00:42.00, start: 0.000000, bitrate: N/A
    Stream #1:0: Video: gif, 1 reference frame, bgra, 1101x1094, 2 fps, 2 tbr, 2 tbn, 2 tbc
Stream mapping:
  Stream #1:0 -> #0:0 (gif (native) -> h264 (libx264))
  Stream #0:0 -> #0:1 (pcm_u8 (native) -> aac (native))
Press [q] to stop, [?] for help
[Parsed_scale_0 @ 0x489c4c0] w:trunc(iw/2)*2 h:trunc(ih/2)*2 flags:'bicubic' interl:0
[graph 0 input from stream 1:0 @ 0x489cac0] w:1101 h:1094 pixfmt:bgra tb:1/2 fr:2/1 sar:0/1 sws_param:flags=2
[Parsed_scale_0 @ 0x489c4c0] w:1101 h:1094 fmt:bgra sar:0/1 -> w:1100 h:1094 fmt:yuv420p sar:0/1 flags:0x4
[libx264 @ 0x432df40] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2
[libx264 @ 0x432df40] profile High, level 3.2, 4:2:0, 8-bit
[libx264 @ 0x432df40] 264 - core 157 - H.264/MPEG-4 AVC codec - Copyleft 2003-2018 - 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=-2 threads=34 lookahead_threads=5 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=2 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
[graph_1_in_0_0 @ 0x7dffd80] tb:1/44100 samplefmt:u8 samplerate:44100 chlayout:0x3
[format_out_0_1 @ 0x8ffff00] auto-inserting filter 'auto_resampler_0' between the filter 'Parsed_anull_0' and the filter 'format_out_0_1'
[auto_resampler_0 @ 0x4f1dd80] ch:2 chl:stereo fmt:u8 r:44100Hz -> ch:2 chl:stereo fmt:fltp r:44100Hz
Output #0, mp4, to 'output.mp4':
  Metadata:
    encoder         : Lavf58.12.100
    Stream #0:0: Video: h264 (libx264), 1 reference frame (avc1 / 0x31637661), yuv420p(progressive), 1100x1094, q=-1--1, 2 fps, 16384 tbn, 2 tbc
    Metadata:
      encoder         : Lavc58.18.100 libx264
    Side data:
      cpb: bitrate max/min/avg: 0/0/0 buffer size: 0 vbv_delay: -1
    Stream #0:1: Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, delay 1024, 128 kb/s
    Metadata:
      encoder         : Lavc58.18.100 aac
[image2 @ 0x43243c0] Thread message queue blocking; consider raising the thread_queue_size option (current value: 8)
frame=   29 fps=0.0 q=0.0 size=       0kB time=00:00:00.00 bitrate=N/A speed=   0x    
frame=   55 fps= 54 q=0.0 size=       0kB time=00:00:00.00 bitrate=N/A speed=   0x    
frame=   82 fps= 54 q=20.0 size=     256kB time=00:00:00.50 bitrate=4194.6kbits/s speed=0.328x    
No more output streams to write to, finishing.
frame=   84 fps= 39 q=-1.0 Lsize=    2516kB time=00:00:42.00 bitrate= 490.6kbits/s speed=19.4x    
video:2495kB audio:11kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.393834%
Input file #0 (anullsrc):
  Input stream #0:0 (audio): 1810 packets read (3706880 bytes); 1810 frames decoded (1853440 samples); 
  Total: 1810 packets (3706880 bytes) demuxed
Input file #1 (input.gif):
  Input stream #1:0 (video): 84 packets read (14506293 bytes); 84 frames decoded; 
  Total: 84 packets (14506293 bytes) demuxed
Output file #0 (output.mp4):
  Output stream #0:0 (video): 84 frames encoded; 84 packets muxed (2555058 bytes); 
  Output stream #0:1 (audio): 1809 frames encoded (1852416 samples); 1810 packets muxed (10996 bytes); 
  Total: 1894 packets (2566054 bytes) muxed
[libx264 @ 0x432df40] frame I:1     Avg QP:10.32  size:162085
[libx264 @ 0x432df40] frame P:21    Avg QP:15.88  size: 50898
[libx264 @ 0x432df40] frame B:62    Avg QP:18.84  size: 21346
[libx264 @ 0x432df40] consecutive B-frames:  1.2%  0.0%  3.6% 95.2%
[libx264 @ 0x432df40] mb I  I16..4: 40.6% 22.9% 36.5%
[libx264 @ 0x432df40] mb P  I16..4:  1.2%  0.4%  3.5%  P16..4: 13.1%  6.6%  7.1%  0.0%  0.0%    skip:68.0%
[libx264 @ 0x432df40] mb B  I16..4:  0.4%  0.1%  0.7%  B16..8: 11.2%  5.4%  4.2%  direct: 2.6%  skip:75.2%  L0:47.3% L1:42.1% BI:10.6%
[libx264 @ 0x432df40] 8x8 transform intra:14.2% inter:12.5%
[libx264 @ 0x432df40] coded y,uvDC,uvAC intra: 55.1% 55.5% 51.6% inter: 8.7% 10.0% 9.7%
[libx264 @ 0x432df40] i16 v,h,dc,p: 67% 18% 14%  0%
[libx264 @ 0x432df40] i8 v,h,dc,ddl,ddr,vr,hd,vl,hu: 47%  6% 43%  1%  1%  1%  1%  1%  1%
[libx264 @ 0x432df40] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 28% 16% 26%  5%  5%  6%  4%  6%  5%
[libx264 @ 0x432df40] i8c dc,h,v,p: 64% 12% 19%  4%
[libx264 @ 0x432df40] Weighted P-Frames: Y:0.0% UV:0.0%
[libx264 @ 0x432df40] ref P L0: 50.8%  4.4% 28.7% 16.0%
[libx264 @ 0x432df40] ref B L0: 73.9% 20.2%  5.9%
[libx264 @ 0x432df40] ref B L1: 91.5%  8.5%
[libx264 @ 0x432df40] kb/s:486.55
[aac @ 0x4326240] Qavg: 65536.000




More information about the ffmpeg-user mailing list