批处理文件:用gifsicle删除gif文件中的奇数帧
对gif动画的操作有很多开源工具能做,gifscile是小巧的跨操作系统一款,英文手册可以参考这里。
原始的可执行文件功能有限,根据手册可以对其进行一些扩展。这里扩展的主要是批量删除其奇数帧、以缩小体积。——得到了一个近8MB的gif文件,但上传通常要求5MB以内。简单的想法,删除奇数帧,这样体积缩小大概一半(但播放质量大大下降),刚好满足要求,而且在不修改播放速度前提下播放速度自动加倍,两全其美。
下面是名为delodd.bat
的批处理脚本文件(这是DOS年代很常用的;windows操作系统保留cmd.exe中仍然能够使用。)
@echo off
setlocal enabledelayedexpansion
if "%~1"=="" (
echo A .gif file needed, Usage: delodd 2025.gif
exit /b
)
set "input=%~1"
set "output=%~dpn1o.gif"
set "temp=output.gif"
:: 检查 gifsicle 是否安装
gifsicle --version >nul 2>&1
if errorlevel 1 (
echo Please download gifsicle first!
exit /b
)
:: 处理文件
copy /y "%input%" "%temp%" >nul
:: 获取总帧数
for /f "tokens=2" %%a in ('gifsicle --info "%input%" ^| find "images"') do set "total=%%a"
:: 循环删除奇数帧
set "frame=1"
:loop
for /f "tokens=2" %%b in ('gifsicle --info "%temp%" ^| find "images"') do set "current=%%b"
if !frame! gtr !current! goto done
echo Deleting frame No. !frame! of total frames
gifsicle "%temp%" --delete "#!frame!" -o "output_temp.gif"
move /y "output_temp.gif" "%temp%" >nul
set /a "frame+=1"
goto loop
:done
move /y "%temp%" "%output%"
echo Finished!Output gif is: "%output%"
gifsicle --info "%output%"
下面是我用gifsicle处理之后缩小到5MB以内的gif文件:
然而现实往往不以人们的想象为转移。其实还有一个小秘密,正如前面所述,删除奇数帧会导致动画播放图像质量严重下降,后来,我是用下面的方式修改的:
gifsicle 202580.gif --colors 32 -o 20258.gif
把256色改为32色,也成功缩小了原始gif文件体积到合适数值。
人工智能大语言模型聊天非常有想象力。然而,更期望的是,大语言模型能够像设想的那样容易沟通、能力又强。七嘴八舌适合娱乐、务虚。干活人。
另外可以改变每一帧delay
时间:
gifsicle 20250.gif -d3 -o 202508.gif