터미널 명령어를 활용하여 동영상을 고품질 움직이는 GIF(움짤)로 변환하고 용량을 압축하는 퀵 레퍼런스.
최신 FFmpeg 팔레트 생성 방식 (권장)
단일 명령 파이프라인에서 최적의 컬러 팔레트를 생성하여 고품질 GIF 제작:
ffmpeg -ss 00:00:02 -to 00:00:08 -i input.mp4 \
-vf "fps=15,scale=480:-1:flags=lanczos,split[s0][s1];[s0]palettegen[p];[s1][p]paletteuse" \
-loop 0 output.gif
전통적인 ImageMagick 및 Gifsicle 파이프라인
mplayer 및 gifsicle을 통한 MP4 변환
mkdir -p gif
mplayer -ao null -vo gif89a:outdir=gif "$INPUT"
mogrify -format gif *.png
gifsicle --colors=256 --delay=4 --loopcount=0 --dither -O3 gif/*.gif > "${INPUT%.*}.gif"
rm -rf gif
mplayer, imagemagick, gifsicle이 필요합니다. 개별 프레임을 추출한 뒤 최적화된 GIF로 결합합니다.
시간 구간 자르기 (트리밍)
타임스탬프를 지정하여 동영상의 특정 구간만 추출:
mplayer -ao null -ss 0:02:06 -endpos 0:00:15 -vo gif89a:outdir=gif videofile.mp4
-ss [time]: 시작 타임스탬프.-endpos [duration]: 추출할 구간의 길이.
Gifsicle 용량 압축 및 최적화
손실 압축과 색상 감축을 통해 GIF 파일 크기를 획기적으로 축소:
# 색상 수를 줄이고 압축 최적화
gifsicle -O3 --colors 128 input.gif -o output.gif
# 손실 압축 적용 (용량 대폭 감소)
gifsicle -O3 --lossy=80 input.gif -o output.gif