FFmpeg Recipe

Turn GIFs into MP4 files with better quality and smaller size

Convert GIF files to MP4 for smoother playback, smaller file sizes, and better compatibility across platforms.

Why convert GIF to MP4

GIFs are universal but inefficient. Converting GIF to MP4 gives you:

  • Smaller files: MP4 files are typically 50-90% smaller than equivalent GIFs, saving bandwidth and storage costs
  • Smoother playback: Better compression means less jank on mobile devices and slow connections
  • Better compatibility: MP4 plays natively in video players, works better on social media, and supports audio if needed
  • Less bandwidth: Smaller files load faster and reduce hosting costs, especially for high-traffic sites

Most browsers and platforms now prefer MP4 for animated content. Instagram, Twitter, and TikTok automatically convert GIFs to video on upload.

The raw FFmpeg command

If you were running FFmpeg locally, the command looks like this:

ffmpeg -i input.gif \
  -movflags faststart \
  -pix_fmt yuv420p \
  -vf "scale=trunc(iw/2)*2:trunc(ih/2)*2" \
  output.mp4

What each flag does:

  • -i input.gif — the source GIF file
  • -movflags faststart — enables progressive playback (file starts playing before fully downloaded)
  • -pix_fmt yuv420p — ensures compatibility with most players and browsers
  • -vf "scale=..." — makes dimensions divisible by 2 (required by H.264 encoder)

The API version

Skip the command line. Send the conversion as an API request:

Request
curl -X POST https://api.ffmpeg-micro.com/v1/transcodes \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -d '{
    "inputs": [
      { "url": "gs://YOUR_BUCKET/animation.gif" }
    ],
    "outputFormat": "mp4",
    "options": [
      { "option": "-movflags", "argument": "faststart" },
      { "option": "-pix_fmt", "argument": "yuv420p" },
      { "option": "-vf", "argument": "scale=trunc(iw/2)*2:trunc(ih/2)*2" }
    ]
  }'

💡 Get your API key from the API Keys page

Example request and response

Here's what you'll send and receive:

Response (job created)
{
  "id": "550e8400-e29b-41d4-a716-446655440000",
  "status": "pending",
  "inputs": [
    { "url": "gs://YOUR_BUCKET/animation.gif" }
  ],
  "output_format": "mp4",
  "created_at": "2026-05-08T23:45:00Z"
}
Poll for completion
curl -X GET https://api.ffmpeg-micro.com/v1/transcodes/550e8400-e29b-41d4-a716-446655440000 \
  -H "Authorization: Bearer YOUR_API_KEY"
Response (completed)
{
  "success": true,
  "jobId": "550e8400-e29b-41d4-a716-446655440000",
  "status": "completed",
  "outputUrl": "gs://YOUR_OUTPUT_BUCKET/animation.mp4",
  "createdAt": "2026-05-08T23:45:00Z",
  "completedAt": "2026-05-08T23:45:12Z"
}
Download the result
curl -X GET https://api.ffmpeg-micro.com/v1/transcodes/550e8400-e29b-41d4-a716-446655440000/download \
  -H "Authorization: Bearer YOUR_API_KEY"

# Returns:
{
  "url": "https://storage.googleapis.com/...?X-Goog-Signature=..."
}

Quality and output settings

Tune the output for different use cases

Codec choice

Default is H.264 (libx264) for maximum compatibility. You can specify it explicitly:

{ "option": "-c:v", "argument": "libx264" }
Bitrate vs CRF

For consistent quality with variable file size, use CRF (18 = high quality, 23 = balanced, 28 = smaller file):

{ "option": "-crf", "argument": "23" }

For fixed bitrate (e.g., social media upload limits):

{ "option": "-b:v", "argument": "1M" }
Resize dimensions

Scale down for smaller files (e.g., max width 720px, maintain aspect ratio):

{ "option": "-vf", "argument": "scale='min(720,iw)':'-2'" }
Frame rate

GIFs often have low frame rates. You can cap it or match the source:

{ "option": "-r", "argument": "15" }  // 15 fps

Common product use cases

  • UGC platforms: Users upload GIFs, your app converts them to MP4 for faster loading and mobile playback
  • Social sharing: Convert reaction GIFs to MP4 before posting to Instagram, TikTok, or Twitter for better compression
  • Meme conversion: Turn GIF memes into shareable MP4 clips with optional text overlays or watermarks
  • CMS optimization: Automatically convert uploaded GIFs to MP4 to reduce CDN bandwidth and improve page load times
  • Email marketing: GIF support in email is spotty; MP4 with a fallback image works better in Gmail and Outlook
  • Product demos: Convert screen-recorded GIFs to MP4 for embedding in docs, landing pages, and support articles

Common mistakes

  • Oversized dimensions: GIFs are often small (e.g., 480px wide). Don't upscale — keep original size or scale down.
  • Missing pixel format: Without -pix_fmt yuv420p, some browsers won't play the MP4.
  • Wrong container format: Make sure output extension is .mp4, not .webm or .avi.
  • Not preserving loop behavior: GIFs loop by default. MP4 needs a loop attribute in HTML or player settings.
  • Ignoring aspect ratio: Use scale=trunc(iw/2)*2:trunc(ih/2)*2 or similar to keep dimensions even.
  • Forgetting faststart: Without -movflags faststart, the video won't start playing until fully downloaded.

Related recipes

Ready to convert GIFs to MP4?

Start with 100 free minutes of video processing. No FFmpeg installation required.