For moving images, short MP4/WebM videos are known to come out much smaller than GIFs. Use autoplay loop muted playsinline to make them behave like a GIF, and take care of accessibility and fallbacks.
GIF is a format from 1987 that uses a palette of up to 256 colors per frame and a lossless method (LZW). It compresses very inefficiently for photo-like images that keep moving. Video codecs, on the other hand, remove the redundancy between consecutive frames with the inter-frame prediction we've been covering since Chapter 3 of this course. That's why converting short demos and reaction clips from GIF to short MP4 or WebM is commonly recommended in web performance guides. This site has not measured the size of GIFs versus video, so we don't give a figure like 'X times smaller'. Convert the same animation from your own file and check it directly.
ffmpeg -i demo.gif \
-movflags +faststart -pix_fmt yuv420p \
-vf "scale=trunc(iw/2)*2:trunc(ih/2)*2" \
-c:v libx264 -crf 23 -an demo.mp4scale=trunc(iw/2)*2:trunc(ih/2)*2**: because of chroma subsampling, yuv420p needs even width and height. If the GIF's dimensions are odd, this filter rounds them to even.ffmpeg -i demo.gif -c:v libvpx-vp9 -crf 33 -b:v 0 -an demo.webm<video autoplay loop muted playsinline width="480" height="270"
poster="demo-poster.jpg" aria-label="Demo of using the settings screen">
<source src="demo.webm" type="video/webm">
<source src="demo.mp4" type="video/mp4">
</video>controls so users can stop it.WebP and AVIF can also hold animation (Chapter 4), which has the advantage that you can use a single <img>. However, a video file gets <video> features like seeking and pausing and the benefit of hardware decoding (hardware decoding), while an animated image is simple with just one <img>. Which is smaller and smoother depends on the content, so make GIF, WebP, and MP4 all from the same source and compare file size and playback directly to decide.
ffmpeg -i demo.mp4 -vf "fps=15,scale=480:-2" -c:v libwebp -quality 70 -loop 0 -an demo-anim.webpScreen recordings with lots of text and lines can show noticeable ringing and color bleeding even in a video codec. This site's measured clips include no screen recordings (limits of the encoding recipes chapter), so we can't say which CRF is appropriate; after converting, check by eye that the text isn't smeared.
An image format from 1987. It uses a palette of up to 256 colors and lossless compression, and supports animation.
A video tag attribute. On some mobile browsers, it makes the video play inside the page instead of full screen.
The image shown before a video plays.
Why do you make the width and height even when converting a GIF to MP4 (H.264, yuv420p)?
Which is closest to the combination of attributes a <video> needs to autoplay and loop like a GIF?