{"author_link":"\/users\/andrewkennedy","author_name":"andrewkennedy","author_uid":"andrewkennedy","comments":[],"epoch":1743783742,"event":"LD57","format":"md","ldjam_node_id":410358,"likes":16,"metadata":{"p_key":"209769","p_author":"andrewkennedy","p_authorkey":"1236545","p_urlkey":"448860","p_title":"An FFmpeg command for nice GIFs","p_cat":"LDJam ","p_event":"LD57","p_time":"1743783742","p_likes":"16","p_comments":"0","p_status":"WAYBACK","us_key":"1236545","us_name":"LDJam user 236545","us_username":"236545","event_start":"1743811200","event_key":"111","event_name":"Ludum Dare 57"},"node":{"_collation":{"body_sanitizer":"TextUtils::SanitizeHTML via existing importer","event":"LD57","removed_author":false},"_superparent":406845,"_trust":1,"author":236545,"body":"It's fun to take breaks and share what you're working on during the weekend, but I always found it kind of frustrating to make a nice GIF, without downloading some bloated screen recording software. So a few years ago I whipped up an FFmpeg command for converting `.mp4` to `.gif`, specifically for sharing on the LDjam site. The goals were:\n- Keep the file size as small as possible\n- Retain as much quality as possible\n- Resize to a consistent width\n\n\n\nI'm sharing it here in case anyone finds it useful. Since I'm on Windows, I wrote it as a `.bat` script so that I can just drag and drop any video on it, and get a GIF without needing to do anything else. Tweak the `FPS` and `WIDTH` values as you see fit. (This assumes you have [FFmpeg](https:\/\/www.ffmpeg.org\/) downloaded and available on your system PATH).\n\n```\nREM mp4_to_gif.bat\n\nSET FPS=30\nSET WIDTH=320\n\nSET SRC=%1\nSET DST=%SRC%.gif\nSET PALETTE=%SRC%.palette.png\n\nffmpeg -y -i %SRC% -vf \"fps=%FPS%,scale=%WIDTH%:-1:flags=lanczos,palettegen=stats_mode=diff\" %PALETTE%\nffmpeg -y -i %SRC% -i %PALETTE% -lavfi \"fps=%FPS%,scale=%WIDTH%:-1:flags=lanczos,mpdecimate,paletteuse=dither=bayer:bayer_scale=5:diff_mode=rectangle\" %DST%\ndel %PALETTE%\n```\n\nBonus info for the FFmpeg nerds:\n- Even though I record in 60FPS, I chose to retime to 30FPS so that I don't have to worry about file size as much (this site limits you to 4MB uploads)\n- Doing a 2-pass render to generate a palette first gets you way better color accuracy\n- The combination of `mpdecimate` and `palettegen=diff` options will optimize for situations where you have a lot of static backgrounds, with moving foregrounds. I'm mostly doing pixel art with static-ish backgrounds, so this works well for me.","comments":4,"comments-timestamp":"2025-04-04T19:35:13Z","created":"2025-04-04T15:47:04Z","files":[],"files-timestamp":0,"id":410358,"love":16,"love-timestamp":"2025-04-04T21:22:02Z","meta":[],"modified":"2025-04-04T21:22:02Z","name":"An FFmpeg command for nice GIFs","node-timestamp":"2025-04-04T16:22:22Z","parent":410357,"parents":[1,5,9,406845,410357],"path":"\/events\/ludum-dare\/57\/that-underground-level\/an-ffmpeg-command-for-nice-gifs","published":"2025-04-04T16:22:22Z","scope":"public","slug":"an-ffmpeg-command-for-nice-gifs","subsubtype":"","subtype":"","type":"post","version":1285163},"node_metadata":{"n_key":"410358","n_urlkey":"448860","n_parent":"410357","n_path":"\/events\/ludum-dare\/57\/that-underground-level\/an-ffmpeg-command-for-nice-gifs","n_slug":"an-ffmpeg-command-for-nice-gifs","n_type":"post","n_subtype":"","n_subsubtype":"","n_author":"236545","n_created":"1743781624","n_modified":"1743801722","n_version":"1285163","n_status":"WAYBACK"},"source_url":"https:\/\/ldjam.com\/events\/ludum-dare\/57\/that-underground-level\/an-ffmpeg-command-for-nice-gifs","text":"It's fun to take breaks and share what you're working on during the weekend, but I always found it kind of frustrating to make a nice GIF, without downloading some bloated screen recording software. So a few years ago I whipped up an FFmpeg command for converting `.mp4` to `.gif`, specifically for sharing on the LDjam site. The goals were:\n- Keep the file size as small as possible\n- Retain as much quality as possible\n- Resize to a consistent width\n\n\n\nI'm sharing it here in case anyone finds it useful. Since I'm on Windows, I wrote it as a `.bat` script so that I can just drag and drop any video on it, and get a GIF without needing to do anything else. Tweak the `FPS` and `WIDTH` values as you see fit. (This assumes you have [FFmpeg](https:\/\/www.ffmpeg.org\/) downloaded and available on your system PATH).\n\n```\nREM mp4_to_gif.bat\n\nSET FPS=30\nSET WIDTH=320\n\nSET SRC=%1\nSET DST=%SRC%.gif\nSET PALETTE=%SRC%.palette.png\n\nffmpeg -y -i %SRC% -vf \"fps=%FPS%,scale=%WIDTH%:-1:flags=lanczos,palettegen=stats_mode=diff\" %PALETTE%\nffmpeg -y -i %SRC% -i %PALETTE% -lavfi \"fps=%FPS%,scale=%WIDTH%:-1:flags=lanczos,mpdecimate,paletteuse=dither=bayer:bayer_scale=5:diff_mode=rectangle\" %DST%\ndel %PALETTE%\n```\n\nBonus info for the FFmpeg nerds:\n- Even though I record in 60FPS, I chose to retime to 30FPS so that I don't have to worry about file size as much (this site limits you to 4MB uploads)\n- Doing a 2-pass render to generate a palette first gets you way better color accuracy\n- The combination of `mpdecimate` and `palettegen=diff` options will optimize for situations where you have a lot of static backgrounds, with moving foregrounds. I'm mostly doing pixel art with static-ish backgrounds, so this works well for me.","title":"An FFmpeg command for nice GIFs","wayback_source":[]}