天天看點

gif 縮放算法及相關資料

http://giflib.sourceforge.net/whatsinagif/index.html

http://giflib.sourceforge.net/whatsinagif/bits_and_bytes.html

gif 縮放算法及相關資料

https://gif.ski/ gifski 可以從視訊生成高品質的 gif

濃縮的才是精華:淺析 GIF 格式圖檔的存儲和壓縮 https://cloud.tencent.com/developer/article/1004763

用av1視訊替代 gif https://www.singhkays.com/blog/its-time-replace-gifs-with-av1-video

“Replace animated GIFs with video for faster page loads” : https://web.dev/replace-gifs-with-videos/

https://web.dev/efficient-animated-content/

http://blog.pkh.me/p/21-high-quality-gif-with-ffmpeg.html

每幀一個調色闆,就可以消除噪點。 https://medium.com/@Peter_UXer/small-sized-and-beautiful-gifs-with-ffmpeg-25c5082ed733

if 本身的算法比較古老壓縮率低下,和 h264/h265/vp9 之類的編碼算法是沒法比的,比如用 h264/VP9 mp4/webm 視訊代替 gif,大概可以壓縮到原大小的 1/5 ~ 1/10

“Replace animated GIFs with video for faster page loads” : https://web.dev/replace-gifs-with-videos/

《頁面加載性能之video替換GIF》: https://www.bilibili.com/read/cv6905954

“用av1視訊替代 gif " https://www.singhkays.com/blog/its-time-replace-gifs-with-av1-video

gifsicle https://www.lcdf.org/gifsicle/

檢視 gif 檔案結構:

1 gifsicle -I input.gif
1 gcc -pthread -DHAVE_CONFIG_H quantize.c merge.c optimize.c gifunopt.c gifwrite.c gifsicle.c clp.c support.c giffunc.c xform.c gifread.c fmalloc.c -I ../include/ -I ../ -lm

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

# gcc -pthread -DHAVE_CONFIG_H quantize.c merge.c optimize.c gifunopt.c gifwrite.c gifsicle.c clp.c support.c giffunc.c xform.c gifread.c fmalloc.c -I ../include/ -I ../ -lm

function scale(){

input=$1

time ffmpeg -hide_banner -y -i $input -b 568k -r 20 -vf 'fps=20,scale=w=162:h=-1:flags=lanczos,palettegen ' ${input}.palettegen.png

time ffmpeg -hide_banner -y -i $input -i ${input}.palettegen.png -r 15 -lavfi 'fps=15,scale=w=162:h=-1:flags=lanczos[x];[x][1:v]paletteuse' $2

rm -f ${input}.palettegen.png

}

time ffmpeg -threads 1 -hide_banner -y -i 987.gif -vf 'scale=w=162:h=-1:flags=lanczos ' 987.gif.162.lanczos.gif

scale 987.gif 987.gif.162.palettegen.gif

gifsicle 987.gif --resize 162x_ -o 987.gif.162.gifsicle.gif

#ffmpeg -y -i 987.gif -filter_complex "[0:v] fps=15,scale=w=720:h=-1,split [a][b];[a] palettegen=stats_mode=single [p];[b][p] paletteuse=new=1" avengers3.gif

#ffmpeg -y -i 987.gif -filter_complex "[0:v]scale=w=162:h=-1,split [a][b];[a] palettegen=stats_mode=single [p];[b][p] paletteuse=new=1" 987.gif.162.ffmpeg_single.gif

ffmpeg -y -i 987.gif -filter_complex "[0:v]scale=w=162:h=-1:flags=lanczos,split [a][b];[a] palettegen=stats_mode=single [p];[b][p] paletteuse=new=1" 987.gif.162.ffmpeg_single.gif

time convert 987.gif -resize 162x1620 987.162.gif